Skip to content

How To: Init.d script

Bruno P. Kinoshita edited this page Mar 6, 2021 · 1 revision

Here's an example for an init.d script for Linux-based systems. It also works with systemd.

Create an executable file /etc/init.d/smashing with following content and adapt the pathes :

#!/bin/bash
### BEGIN INIT INFO
# Provides: dashboard
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO

# Must be a valid filename
NAME=smashing
DASHING_DIR=/opt/smashing-dashboards/tvs_dashboard
DAEMON=/usr/local/bin/smashing
PIDFILE="/var/run/smashing.pid"
DAEMON_OPTS="start -d -P $PIDFILE"
GEM_HOME=/var/lib/gems/2.1.0

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

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

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

exit 0

Then follow instructions of your Linux distribution to enable it

Clone this wiki locally