Line 22: |
Line 22: |
| SCRIPT=<COMMAND> | | SCRIPT=<COMMAND> |
| RUNAS=<USERNAME> | | RUNAS=<USERNAME> |
− | NAME=<YOUR_SERVICE_NAME> | + | NAME=<SERVICE_NAME> |
| | | |
| PIDFILE=/var/run/$NAME.pid | | PIDFILE=/var/run/$NAME.pid |
Line 46: |
Line 46: |
| kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE" | | kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE" |
| echo 'Service stopped' >&2 | | echo 'Service stopped' >&2 |
| + | } |
| + | |
| + | uninstall() { |
| + | echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] " |
| + | local SURE |
| + | read SURE |
| + | if [ "$SURE" = "yes" ]; then |
| + | stop |
| + | rm -f "$PIDFILE" |
| + | echo "Notice: log file is not be removed: '$LOGFILE'" >&2 |
| + | update-rc.d -f <NAME> remove |
| + | rm -fv "$0" |
| + | fi |
| } | | } |
| | | |
Line 51: |
Line 64: |
| printf "%-50s" "Checking $NAME..." | | printf "%-50s" "Checking $NAME..." |
| if [ -f $PIDFILE ]; then | | if [ -f $PIDFILE ]; then |
− | PID=`cat $PIDFILE`
| + | PID=$(cat $PIDFILE) |
− | if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
| + | if [ -z "$(ps axf | grep ${PID} | grep -v grep)" ]; then |
− | printf "%s\n" "Process dead but pidfile exists"
| + | printf "%s\n" "The process appears to be dead but pidfile still exists" |
− | else
| + | else |
− | echo "Running, the PID is $PID"
| + | echo "Running, the PID is $PID" |
− | fi
| + | fi |
− | else
| + | else |
− | printf "%s\n" "Service not running"
| + | printf "%s\n" "Service not running" |
| fi | | fi |
| } | | } |
Line 72: |
Line 85: |
| status) | | status) |
| status | | status |
| + | ;; |
| + | uninstall) |
| + | uninstall |
| ;; | | ;; |
| restart) | | restart) |
Line 78: |
Line 94: |
| ;; | | ;; |
| *) | | *) |
− | echo "Usage: $0 {start|stop|status|restart}" | + | echo "Usage: $0 {start|stop|status|restart|uninstall}" |
| esac | | esac |
| | | |