File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed
Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 11if 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
3+ [ -f /tmp/crew-sudo.socket ] || crew-sudo --daemon --bashrc
44fi
Original file line number Diff line number Diff line change 55require_relative '../lib/pty_helper'
66
77def runas_daemon ( argv )
8- $mode = :daemon
8+ $mode = :daemon
9+
10+ if File . exist? ( SOCKET_PATH ) && File . exist? ( PID_FILE_PATH )
11+ if ARGV . include? ( '--replace' )
12+ Process . kill ( 'TERM' , File . read ( PID_FILE_PATH ) . to_i )
13+ else
14+ if IS_BASHRC
15+ warn "crew-sudo: Daemon started with PID #{ File . read ( PID_FILE_PATH ) } "
16+ else
17+ message <<~EOT , loglevel : error
18+ crew-sudo daemon (process #{ File . read ( PID_FILE_PATH ) } ) is already running.
19+
20+ Use `#{ PROGNAME } --daemon --replace` to replace the running daemon
21+ EOT
22+ end
23+ exit 1
24+ end
25+ end
26+
927 @server = UNIXServer . new ( SOCKET_PATH ) # create unix socket
1028
1129 # fix permission if we are running as root
@@ -27,6 +45,7 @@ def runas_daemon(argv)
2745 end
2846
2947 Process . setproctitle ( 'crew-sudo daemon process' )
48+ File . write ( PID_FILE_PATH , Process . pid )
3049
3150 warn "crew-sudo: Daemon started with PID #{ Process . pid } "
3251
@@ -113,4 +132,5 @@ def runas_daemon(argv)
113132ensure
114133 @server . close
115134 File . delete ( SOCKET_PATH ) if File . exist? ( SOCKET_PATH )
135+ File . delete ( PID_FILE_PATH ) if File . exist? ( PID_FILE_PATH )
116136end
Original file line number Diff line number Diff line change 11PROGNAME = File . basename ( $0, '.rb' )
2+ IS_BASHRC = ARGV . include? ( '--bashrc' )
23SOCKET_PATH = '/tmp/crew-sudo.socket'
4+ PID_FILE_PATH = '/tmp/crew-sudo.pid'
35DAEMON_LOG_PATH = '/tmp/crew-sudo.log'
You can’t perform that action at this time.
0 commit comments