Skip to content

Instantly share code, notes, and snippets.

@dragonbk91
Forked from alobato/start-stop-example.sh
Created September 27, 2018 09:14
Show Gist options
  • Save dragonbk91/dfb3120fd7e97da1b4edb8fd1f47da7f to your computer and use it in GitHub Desktop.
Save dragonbk91/dfb3120fd7e97da1b4edb8fd1f47da7f to your computer and use it in GitHub Desktop.

Revisions

  1. @alobato alobato created this gist Mar 3, 2012.
    38 changes: 38 additions & 0 deletions start-stop-example.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    #!/bin/sh

    # Quick start-stop-daemon example, derived from Debian /etc/init.d/ssh
    set -e

    # Must be a valid filename
    NAME=foo
    PIDFILE=/var/run/$NAME.pid
    #This is the command to be run, give the full pathname
    DAEMON=/usr/local/bin/bar
    DAEMON_OPTS="--baz=quux"

    export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"

    case "$1" in
    start)
    echo -n "Starting daemon: "$NAME
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS
    echo "."
    ;;
    stop)
    echo -n "Stopping daemon: "$NAME
    start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
    echo "."
    ;;
    restart)
    echo -n "Restarting daemon: "$NAME
    start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $PIDFILE
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS
    echo "."
    ;;

    *)
    echo "Usage: "$1" {start|stop|restart}"
    exit 1
    esac

    exit 0