I have a very simple SysVinit service in /etc/rc.d:
#!/bin/bash
PIDFILE="/var/run/test.pid"
status() {
if [ -f "$PIDFILE" ]; then
echo 'Service running'
return 1
fi
return 0
}
start() {
if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")"; then
echo 'Service already running'
return 1
fi
echo 'Starting...'
test & echo $! > "$PIDFILE"
return 0
}
stop() {
if [ ! -f "$PIDFILE" ] || ! kill -0 "$(cat "$PIDFILE")"; then
echo 'Service not running'
return 1
fi
echo 'Stopping...'
kill -15 "$(cat "$PIDFILE")" && rm -f "$PIDFILE"
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
When the system starts it starts the service.
But when the system stops, it never calls the stop command. The only reason I can think off is that the system either thinks the service is not running or was not started correctly.
But what are the requirements for that?
- Do you need to return a special exitcode for the start command?
- Do I need to create a file in
/var/lock/subsysto signal that it is active? - Anything else that might cause the system to think the service did not start?