Skip to content

Instantly share code, notes, and snippets.

@Chunlin-Li
Created October 29, 2015 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chunlin-Li/91fe129dabc1ee8391f5 to your computer and use it in GitHub Desktop.
Save Chunlin-Li/91fe129dabc1ee8391f5 to your computer and use it in GitHub Desktop.
Linux 下创建一个 service. create a Linux daemon / service
#! /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