Edit File: S50noderig
#!/bin/sh ### BEGIN INIT INFO # Provides: noderig # Required-Start: $local_fs $network $named $time $syslog # Required-Stop: $local_fs $network $named $time $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Description: Prometheus to Warp10 metrics forwarder ### END INIT INFO CMD=/usr/bin/noderig RUNAS=root PIDFILE=/var/run/noderig.pid WORKDIR=/tmp LOGFILE=/var/log/noderig/noderig.log get_pid() { cat "$PIDFILE" } is_running() { [ -f "$PIDFILE" ] && ps `get_pid` > /dev/null 2>&1 } start() { if is_running; then echo "Already started" else echo 'Starting noderig' cd "$WORKDIR" local cmd="$CMD >> "$LOGFILE" 2>&1 & echo \$!" su -c "$cmd" $RUNAS > "$PIDFILE" if ! is_running; then echo "Unable to start, see $OUTLOG and $ERRLOG" exit 1 fi fi echo "Started" } stop() { if is_running; then echo -n "Stopping noderig.." kill `get_pid` for i in {1..10} do if ! is_running; then break fi echo -n "." sleep 1 done echo if is_running; then echo "Not stopped; may still be shutting down or shutdown may have failed" exit 1 else echo "Stopped" if [ -f "$PIDFILE" ]; then rm "$PIDFILE" fi fi else echo "Not running" fi } status() { if is_running; then echo "Running" else echo "Stopped" exit 1 fi } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) status ;; *) echo "Usage: $0 {start|stop|restart|status}" esac exit 0