Last active
March 29, 2018 22:27
-
-
Save adamsiwiec/525aacdb7ae6fda414a87b824474f1d3 to your computer and use it in GitHub Desktop.
service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
NAME=daemon_name | |
DESC="My first linux daemon" | |
PIDFILE="/var/run/${NAME}.pid" | |
LOGFILE="/var/log/${NAME}.log" | |
# PHP binary path | |
DAEMON="/usr/bin/php" | |
# Path of your php script | |
DAEMON_OPTS="/var/www/site.com/myscript.php" | |
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 | |
Remember to edit NAME, DESC and DAEMON_OPTS variables to fit your needs. | |
Give exec permissions to the new linux service: | |
chmod +x /etc/init.d/name -v | |
That’s all, now start your linux daemon for the first time: | |
service name start | |
Popular search terms: | |
linux create service | |
https://www scalescale com/tips/nginx/create-linux-daemon-service/ | |
https://www scalescale com/tips/nginx/create-linux-daemon-service/# | |
how to create a service in linux | |
Get a new article on scaling every Sunday morning and start the week out right. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment