简易init.d脚本
2016-11-22 本文已影响153人
bluexiii
#!/bin/sh
### BEGIN INIT INFO
# Provides: redsocks
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start redsocks daemon.
### END INIT INFO
SERVICE_NAME=redsocks
SERVICE_PATH=/usr/local/bin/redsocks
SERVICE_PARAM="-c /etc/redsocks.conf"
SERVICE_HOME=/home/pi
SERVICE_USER=pi
SERVICE_PID_FILE=/var/run/${SERVICE_NAME}.pid
start() {
start-stop-daemon --start \
--chdir "${SERVICE_HOME}" \
--chuid "${SERVICE_USER}" \
--user "${SERVICE_USER}" \
-b -m -p "${SERVICE_PID_FILE}" \
--exec ${SERVICE_PATH} -- ${SERVICE_PARAM}
}
stop() {
start-stop-daemon --stop \
--chdir "${SERVICE_HOME}" \
--chuid "${SERVICE_USER}" \
--user "${SERVICE_USER}" \
-p "${SERVICE_PID_FILE}"
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
# code to check status of app comes here
# example: status program_name
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
esac
exit 0