2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
6 # Init script for keepproxy
8 # Generated by pleaserun.
9 # Implemented based on LSB Core 3.1:
10 # * Sections: 20.2, 20.3
14 # Required-Start: $remote_fs $syslog
15 # Required-Stop: $remote_fs $syslog
16 # Default-Start: 2 3 4 5
19 # Description: no description given
22 PATH=/sbin:/usr/sbin:/bin:/usr/bin
26 program=/usr/bin/keepproxy
28 pidfile="/var/run/$name.pid"
30 [ -r /etc/default/$name ] && . /etc/default/$name
31 [ -r /etc/sysconfig/$name ] && . /etc/sysconfig/$name
34 logger -t "/etc/init.d/keepproxy" "$@"
44 # Ensure the log directory is setup correctly.
45 [ ! -d "/var/log/" ] && mkdir "/var/log/"
46 chown "$user":"$group" "/var/log/"
50 # Setup any environmental stuff beforehand
55 chroot --userspec "$user":"$group" "$chroot" sh -c "
58 exec \"$program\" $args
59 " >> /var/log/keepproxy.stdout 2>> /var/log/keepproxy.stderr &
61 # Generate the pidfile from here. If we instead made the forked process
62 # generate it there will be a race condition between the pidfile writing
63 # and a process possibly asking for status.
71 # Try a few times to kill TERM the program
74 trace "Killing $name (pid $pid) with SIGTERM"
76 # Wait for it to exit.
77 for i in 1 2 3 4 5 ; do
78 trace "Waiting $name (pid $pid) to die..."
83 emit "$name stop failed; still running."
91 if [ -f "$pidfile" ] ; then
93 if ps -p $pid > /dev/null 2> /dev/null ; then
94 # process by this pid is running.
95 # It may not be our pid, but that's what you get with just pidfiles.
96 # TODO(sissel): Check if this process seems to be the same as the one we
97 # expect. It'd be nice to use flock here, but flock uses fork, not exec,
98 # so it makes it quite awkward to use in this case.
101 return 2 # program is dead but pid file exists
104 return 3 # program is not running
111 status && kill -KILL $(cat "$pidfile")
117 force-start|start|stop|force-stop|restart)
118 trace "Attempting '$1' on keepproxy"
130 if [ $code -eq 0 ]; then
131 emit "$name is already running"
139 force-stop) force_stop ;;
143 if [ $code -eq 0 ] ; then
144 emit "$name is running"
146 emit "$name is not running"
155 echo "Usage: $SCRIPTNAME {start|force-start|stop|force-start|force-stop|status|restart}" >&2