Edit File: beamium
#!/bin/sh ### BEGIN INIT INFO # Provides: beamium # 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/beamium RUNAS=beamium PIDFILE=/var/run/beamium.pid WORKDIR=/opt/beamium LOGFILE=/var/log/beamium.log OUTLOG="/var/log/beamium/beamium.out" ERRLOG="/var/log/beamium/beamium.err" 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 beamium' cd "$WORKDIR" local cmd="$CMD >> "$OUTLOG" 2>> "$ERRLOG" & 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 beamium.." kill -2 `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