47 lines
750 B
Bash
47 lines
750 B
Bash
#!/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
|
|
fi
|
|
}
|
|
|
|
status() {
|
|
if [ -r "$1" ]; then
|
|
PID=$(cat "$1")
|
|
$KILL=$(kill -0 $PID 2>&1 >&-)
|
|
if [ $? ]; then
|
|
echo "Service running, PID = $PID"
|
|
return 0
|
|
else
|
|
if [ -z "$KILL" ]; then
|
|
echo "Process is dead, PID file = $1"
|
|
return 1
|
|
else
|
|
echo "$KILL"
|
|
return 4
|
|
fi
|
|
fi
|
|
else
|
|
echo 'Service not running'
|
|
return 3
|
|
fi
|
|
}
|