linux/scripts/init/inithelpers/fns.sh

47 lines
750 B
Bash
Raw Permalink Normal View History

2014-10-10 16:35:33 +02:00
#!/bin/sh
# Author: Adrian Kousz, 2014
# See:
# https://wiki.debian.org/LSBInitScripts
# https://github.com/jasonblewis/sample-service-script/blob/master/service.sh
is_running() {
if [ -r "$1" ]; then
kill -0 $(cat "$1") 2>&-
return
fi
return 1
}
stop() {
if is_running "$1"; then
kill -INT $(cat "$1") && rm -f "$1"
echo 'Service stopped'
else
echo 'Service not running'
return 7
2014-10-10 16:35:33 +02:00
fi
}
status() {
if [ -r "$1" ]; then
PID=$(cat "$1")
2014-10-10 18:23:53 +02:00
$KILL=$(kill -0 $PID 2>&1 >&-)
if [ $? ]; then
2014-10-10 16:35:33 +02:00
echo "Service running, PID = $PID"
return 0
2014-10-10 16:35:33 +02:00
else
2014-10-10 18:23:53 +02:00
if [ -z "$KILL" ]; then
echo "Process is dead, PID file = $1"
return 1
else
echo "$KILL"
return 4
fi
2014-10-10 16:35:33 +02:00
fi
else
echo 'Service not running'
return 3
2014-10-10 16:35:33 +02:00
fi
}