Created
October 29, 2015 06:41
-
-
Save Chunlin-Li/91fe129dabc1ee8391f5 to your computer and use it in GitHub Desktop.
Linux 下创建一个 service. create a Linux daemon / service
This file contains hidden or 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=XXXXXXXXXX | |
DESC="XXXXXXXXXXXXXXXX" | |
PIDFILE="/var/run/${NAME}.pid" | |
LOGFILE="/var/log/${NAME}.log" | |
# path to the target executable file | |
DAEMON="/PATH/TO/EXECUTABLE/FILE" | |
# options of the target executable file | |
DAEMON_OPTS="-XX xxx -XXX XXX --XXXX-XX=XXX" | |
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 | |
## | |
## depends on http://www.nginxtips.com/create-linux-daemon-service/ | |
## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment