Os serviços geralmente usam scripts de wrapper como, por exemplo;
#!/bin/bash
# Provides: example
# Required-Start:
# Should-Start:
# Required-Stop:
# Default-Start: 2 3 5
# Default-Stop: 0 1 2 6
# Short-Description: example
# Description: example
#
# /etc/init.d/example
#
set -e
trap 'echo "ERROR: $BASH_SOURCE:$LINENO $BASH_COMMAND" >&2' ERR
NPID=$(pgrep -f example2.sh || true);
function start {
if [ "$NPID" = "" ] ; then
screen -S example -d -m bash -c '/root/example2.sh'
else
echo "example service is already running as $NPID";
fi
}
function stop {
if [ "$NPID" != "" ] ; then
kill "$NPID";
else
echo "example service was not running" >&2;
fi
}
function status {
if [ "$NPID" = "" ]; then
echo "example is not running";
else
echo "example is running with pid $NPID";
fi
}
if [ "$1" = "start" ]; then
start
elif [ "$1" = "stop" ]; then
stop
elif [ "$1" = "restart" ]; then
stop;
start;
elif [ "$1" = "status" ]; then
status
else
echo " * Usage: /etc/init.d/example {start|status|stop|restart}";
fi