2 # Init script for keepproxy
4 # Generated by pleaserun.
5 # Implemented based on LSB Core 3.1:
6 # * Sections: 20.2, 20.3
10 # Required-Start: $remote_fs $syslog
11 # Required-Stop: $remote_fs $syslog
12 # Default-Start: 2 3 4 5
15 # Description: no description given
18 PATH=/sbin:/usr/sbin:/bin:/usr/bin
22 program=/usr/bin/keepproxy
24 pidfile="/var/run/$name.pid"
26 [ -r /etc/default/$name ] && . /etc/default/$name
27 [ -r /etc/sysconfig/$name ] && . /etc/sysconfig/$name
30 logger -t "/etc/init.d/keepproxy" "$@"
40 # Ensure the log directory is setup correctly.
41 [ ! -d "/var/log/" ] && mkdir "/var/log/"
42 chown "$user":"$group" "/var/log/"
46 # Setup any environmental stuff beforehand
51 chroot --userspec "$user":"$group" "$chroot" sh -c "
54 exec \"$program\" $args
55 " >> /var/log/keepproxy.stdout 2>> /var/log/keepproxy.stderr &
57 # Generate the pidfile from here. If we instead made the forked process
58 # generate it there will be a race condition between the pidfile writing
59 # and a process possibly asking for status.
67 # Try a few times to kill TERM the program
70 trace "Killing $name (pid $pid) with SIGTERM"
72 # Wait for it to exit.
73 for i in 1 2 3 4 5 ; do
74 trace "Waiting $name (pid $pid) to die..."
79 emit "$name stop failed; still running."
87 if [ -f "$pidfile" ] ; then
89 if ps -p $pid > /dev/null 2> /dev/null ; then
90 # process by this pid is running.
91 # It may not be our pid, but that's what you get with just pidfiles.
92 # TODO(sissel): Check if this process seems to be the same as the one we
93 # expect. It'd be nice to use flock here, but flock uses fork, not exec,
94 # so it makes it quite awkward to use in this case.
97 return 2 # program is dead but pid file exists
100 return 3 # program is not running
107 status && kill -KILL $(cat "$pidfile")
113 force-start|start|stop|force-stop|restart)
114 trace "Attempting '$1' on keepproxy"
126 if [ $code -eq 0 ]; then
127 emit "$name is already running"
135 force-stop) force_stop ;;
139 if [ $code -eq 0 ] ; then
140 emit "$name is running"
142 emit "$name is not running"
151 echo "Usage: $SCRIPTNAME {start|force-start|stop|force-start|force-stop|status|restart}" >&2