Skip to content

Commit e9de51f

Browse files
authored
Add stop command
1 parent 05b452e commit e9de51f

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

autostart/crew-sudo.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ script
1111
# - It dropped a controlling tty (std{in,err,out} are /dev/null).
1212
# - It calls setsid() for every job.
1313
# - It forked for us.
14-
exec /usr/local/bin/crew-sudo --daemon --foreground
14+
exec /usr/local/bin/crew-sudo daemon --foreground
1515
end script

autostart/crew-sudo.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
if grep -q '^/sbin/frecon' < "/proc/$(ps -p $PPID -o ppid= | tr -d ' ')/cmdline"; then
22
# start crew-sudo daemon if running in VT-2
3-
[ -f /tmp/crew-sudo.socket ] || crew-sudo --daemon --bashrc
3+
[ -f /tmp/crew-sudo.socket ] || crew-sudo daemon --bashrc
44
fi

component/daemon.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ def runas_daemon(argv)
1010
if File.exist?(SOCKET_PATH) && File.exist?(PID_FILE_PATH)
1111
if ARGV.include?('--replace')
1212
Process.kill('TERM', File.read(PID_FILE_PATH).to_i)
13+
sleep 0.1 while File.exist?(SOCKET_PATH)
1314
else
1415
if IS_BASHRC
1516
warn "crew-sudo: Daemon started with PID #{File.read(PID_FILE_PATH)}"
1617
else
1718
message <<~EOT, loglevel: :error
1819
crew-sudo daemon (process #{File.read(PID_FILE_PATH)}) is already running.
1920
20-
Use `#{PROGNAME} --daemon --replace` to replace the running daemon
21+
Use `#{PROGNAME} --daemon --replace` to replace the running daemon.
2122
EOT
2223
end
2324
exit 1

crew-sudo

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@ $verbose = ENV['CREW_SUDO_VERBOSE'].eql?('1')
99
case PROGNAME
1010
when 'crew-sudo'
1111
case ARGV[0]
12-
when '-d', '--daemon'
12+
when 'daemon'
1313
runas_daemon(ARGV[1..-1])
14-
when '-c', '--client'
14+
when 'client'
1515
runas_client(ARGV[1..-1])
16+
when 'stop-daemon'
17+
exit(0) unless File.exist?(PID_FILE_PATH)
18+
pid = File.read(PID_FILE_PATH)
19+
20+
begin
21+
Process.kill('TERM', pid)
22+
warn "crew-sudo: Daemon with PID #{pid} stopped"
23+
rescue Errno::ESRCH
24+
end
1625
when '-h', '--help'
1726
warn <<~EOT
1827
#{File.basename($0)} multi-purpose launcher
@@ -21,9 +30,10 @@ when 'crew-sudo'
2130
#{PROGNAME} -h|--help
2231
#{PROGNAME} -V|--version
2332
24-
Available modes:
25-
--daemon: Run as daemon mode, listen incoming requests at #{SOCKET_PATH}
26-
--client: Run as client mode, pass all given command arguments to daemon
33+
Available commands:
34+
daemon Run as daemon mode, listen incoming requests at #{SOCKET_PATH}
35+
client Run as client mode, pass all given command arguments to daemon
36+
stop-daemon Stop currently running crew-sudo daemon
2737
2838
EOT
2939
when '-V', '--version'

0 commit comments

Comments
 (0)