I tried looking up some good example init scripts, but all that I found were excessively complicated. So I wrote my own simple init script targeting CentOS 6. I tried to follow LSB where I understood what it says. CentOS uses chkconfig instead of the LSB comment block.
This is my first serious shell script ever. What do you guys think?
#!/bin/sh
# chkconfig: 2345 80 20
# description: Perforce server
. /etc/profile.d/p4d.sh
command_line='p4d -d'
running() {
pgrep -fx "$command_line" > /dev/null
}
start() {
if ! running; then
$command_line > /dev/null
fi
}
stop() {
if running; then
p4 admin stop > /dev/null
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|force-reload)
stop
start
;;
status)
if running; then
echo "Running"
else
echo "Stopped"
exit 3
fi
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload|status}"
exit 1
;;
esac
exit 0