1#!/bin/sh 2 3DAEMON="netdata" 4PIDFILE="/var/run/$DAEMON.pid" 5 6NETDATA_ARGS="-u root -P $PIDFILE" 7 8# Create needed directories. 9mkdir -p /var/cache/$DAEMON /var/lib/$DAEMON /var/log/$DAEMON 10 11# shellcheck source=/dev/null 12[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON" 13 14start() { 15 printf 'Starting %s: ' "$DAEMON" 16 # shellcheck disable=SC2086 # we need the word splitting 17 start-stop-daemon -S -q -p "$PIDFILE" -x "/usr/sbin/$DAEMON" \ 18 -- $NETDATA_ARGS 19 status=$? 20 if [ "$status" -eq 0 ]; then 21 echo "OK" 22 else 23 echo "FAIL" 24 fi 25 return "$status" 26} 27 28stop() { 29 printf 'Stopping %s: ' "$DAEMON" 30 start-stop-daemon -K -q -p "$PIDFILE" 31 status=$? 32 if [ "$status" -eq 0 ]; then 33 echo "OK" 34 else 35 echo "FAIL" 36 fi 37 return "$status" 38} 39 40restart() { 41 stop 42 sleep 1 43 start 44} 45 46case "$1" in 47 start|stop|restart) 48 "$1";; 49 reload) 50 # Restart, since there is no true "reload" feature. 51 restart;; 52 *) 53 echo "Usage: $0 {start|stop|restart|reload}" 54 exit 1 55esac 56