Skip to content

Commit 04829a4

Browse files
committed
Add support for upstart init and an installation script
1 parent c0d1c92 commit 04829a4

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

autostart/crew-sudo.conf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# crew-sudo.conf: Upstart init configuration file for crew-sudo
2+
description "The crew-sudo daemon"
3+
author "The Chromebrew authors"
4+
5+
# autostart crew-sudo on early boot
6+
start on started boot-services
7+
8+
script
9+
# We pass --foreground to keep crew-sudo in the foreground. Upstart already provides
10+
# the same features for us:
11+
# - It dropped a controlling tty (std{in,err,out} are /dev/null).
12+
# - It calls setsid() for every job.
13+
# - It forked for us.
14+
exec /usr/local/bin/crew-sudo --daemon --foreground
15+
end script

component/daemon.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ def runas_daemon(argv)
88
$mode = :daemon
99

1010
# daemonize
11-
Process.daemon(false, true)
11+
Process.daemon(false, true) unless ARGV.include?('--foreground')
12+
1213
Process.setproctitle('sudo-server daemon process')
1314

1415
warn "crew-sudo: Daemon started with PID #{Process.pid}"

crew-sudo

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ when 'crew-sudo'
3535
Run '#{PROGNAME} --help' for usage.
3636
EOT
3737
end
38-
when 'sudod'
39-
runas_daemon(ARGV)
4038
when 'sudo'
4139
runas_client(ARGV)
4240
end

install.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash -eu
2+
3+
if [ ${EUID} != 0 ] && [ ! -w ${INSTALL_PREFIX} ]; then
4+
echo "Please run this script as root." 2>&1
5+
exit 1
6+
fi
7+
8+
INSTALL_PREFIX="${CREW_PREFIX:-/usr/local}"
9+
10+
cp -r . ${INSTALL_PREFIX}/lib/crew-sudo
11+
12+
ln -s ../lib/crew-sudo/crew-sudo ${INSTALL_PREFIX}/bin/crew-sudo
13+
ln -s ../lib/crew-sudo/crew-sudo ${INSTALL_PREFIX}/bin/sudo
14+
15+
if [ -d ${INSTALL_PREFIX}/etc/env.d ]; then
16+
# installing under chromebrew
17+
ln -s ../lib/crew-sudo/autostart/crew-sudo.sh ${INSTALL_PREFIX}/etc/env.d/crew_sudo
18+
else
19+
# installing without chromebrew, append the autostart script to bashrc
20+
echo "source ${INSTALL_PREFIX}/lib/crew-sudo/autostart/crew-sudo.sh" > ~/.bashrc
21+
fi

0 commit comments

Comments
 (0)