Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- # 2013 Daniel Hilst Selli <daniel.hilst@csi.ind.br>
- #
- # Change this to start your service
- # also, set ARGS on /etc/default/<SERVICE>
- # as arguments to $PROG. Where SERVICE is the
- # name of this script at /etc/init.d
- PATH=/usr/bin:/bin:/sbin:/usr/sbin
- PROG=foo
- # Guessing the service script name. It is /etc/rcN.d/S20service
- # while booting, and /etc/init.d/service if is interactively invocated
- # On both cases I want service. sed, perl, awk are slow :-)
- _nopath=${0##*/} # now we have S20service or service on $_nopath
- SERVICE=${_nopath#[SK][0-9][0-9]} # and now service
- PIDFILE=${PIDFILE:-/var/run/$SERVICE.pid} # Overwrite this on /etc/default/$SERVICE
- if test -r /etc/default/$SERVICE; then
- . /etc/default/$SERVICE
- fi
- start()
- {
- start-stop-daemon --background --make-pidfile --pidfile $PIDFILE --exec $PROG -S -- $ARGS
- }
- stop()
- {
- start-stop-daemon --pidfile $PIDFILE --exec $PROG -K
- }
- status()
- {
- if kill -0 $(cat $PIDFILE) > /dev/null 2>&1; then
- return 0
- else
- return 1
- fi
- }
- usage()
- {
- echo "$0 {start|stop|status|restart}"
- }
- if test -z "$1"; then
- start
- exit 1
- fi
- case $1 in
- start)
- echo -n "Starting $SERVICE ... "
- start
- sleep 1
- if status; then
- echo "DONE"
- else
- echo "FAIL"
- fi
- ;;
- stop)
- echo -n "Stopping $SERVICE ... "
- stop > /dev/null 2>&1
- sleep 1
- if status; then
- echo "FAIL"
- else
- echo "DONE"
- fi
- ;;
- restart)
- stop
- sleep 2
- start
- status
- ;;
- status)
- echo -n "$SERVICE is ... "
- if status; then
- echo "STARTED"
- else
- echo "STOPPED"
- fi
- ;;
- *)
- usage
- exit 1
- ;;
- esac
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement