Simple Linux Service

Buat file misalkan namanya coba. Buat di /etc/init.d/coba. Isinya:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          coba
# Required-Start:
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: daemon to balance interrupts for SMP systems
### END INIT INFO
# coba script
# January 2017
# Yudha Rachmat Hidayat

NAME=Coba
DESC="Python Bottle Daemon"
PIDFILE="/var/run/${NAME}.pid"
LOGFILE="/var/log/${NAME}.log"

# PHP binary path
DAEMON="/usr/bin/python"

# Path of your python script
DAEMON_OPTS="/usr/share/bottle/http.py"

START_OPTS="--start --background --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON} ${DAEMON_OPTS}"
STOP_OPTS="--stop --pidfile ${PIDFILE}"

test -x $DAEMON || exit 0

set -e

case "$1" in
start)
echo -n "Starting ${DESC}: "
start-stop-daemon $START_OPTS >> $LOGFILE
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon $STOP_OPTS
echo "$NAME."
rm -f $PIDFILE
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon $STOP_OPTS
sleep 1
start-stop-daemon $START_OPTS >> $LOGFILE
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac

exit 0


Langkah berikutnya ketik di terminal:
systemctl daemon-reload
systemctl enable coba
systemctl start coba

Komentar

Postingan populer dari blog ini

Tidak bisa delete ke Trash di Ubuntu