Naposledy aktivní 1 month ago

Revize d8993228cd56f0562768e14fa5deed344491ea41

debian-init.sh Raw
1#!/bin/bash -e
2### BEGIN INIT INFO
3# Provides: generic-prog
4# Required-Start: $local_fs $remote_fs $network
5# Required-Stop: $local_fs $remote_fs $network
6# Default-Start: 2 3 4 5
7# Default-Stop: 0 1 6
8# Short-Description: Generic Prog
9# Description: Generic Prog is a generic program to do generic things with
10### END INIT INFO
11
12
13# Documentation available at
14# http://refspecs.linuxfoundation.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptfunc.html
15# Debian provides some extra function though
16source /lib/lsb/init-functions
17
18
19DAEMON_NAME="generic-prog"
20DAEMON_USER="${DAEMON_NAME}"
21DAEMON_PATH="/usr/local/bin/generic-prog"
22DAEMON_OPTS="-c /etc/generic-prog.conf"
23DAEMON_PWD="${PWD}"
24
25STARTUP_MSG="Starting generic-prog daemon"
26SHUTDOWN_MSG="Stopping generic-prog daemon"
27
28DAEMON_PID="/var/run/${DAEMON_NAME}.pid"
29DAEMON_LOG="/var/log/${DAEMON_NAME}.log"
30DAEMON_NICE=0
31
32[ -r "/etc/default/${DAEMON_NAME}" ] && source "/etc/default/${DAEMON_NAME}"
33
34
35do_start() {
36 local result
37 log_daemon_msg "${STARTUP_MSG}" "${DAEMON_NAME}"
38 if [ -z "${DAEMON_USER}" ]; then
39 start_daemon -n $DAEMON_NICE -p "${DAEMON_PID}" "${DAEMON_PATH}" $DAEMON_OPTS
40 result=$?
41 log_end_msg $result
42 else
43 start-stop-daemon --start --quiet --oknodo --background \
44 --nicelevel $DAEMON_NICE \
45 --chdir "${DAEMON_PWD}" \
46 --pidfile "${DAEMON_PID}" --make-pidfile \
47 --exec "${DAEMON_PATH}" -- $DAEMON_OPTS
48 result=$?
49 log_end_msg $result
50 fi
51 return $result
52}
53
54do_stop() {
55 local result
56 log_daemon_msg "${SHUTDOWN_MSG}" "${DAEMON_NAME}"
57 killproc -p "${DAEMON_PID}" "${DAEMON_PATH}"
58 result=$?
59 log_end_msg $result
60 return $result
61}
62
63do_restart() {
64 local result
65 do_stop
66 result=$?
67 if [ $result = 0]; then
68 do_start
69 result=$?
70 fi
71 return $result
72}
73
74do_status() {
75 local result
76 status_of_proc -p "${DAEMON_PID}" "${DAEMON_PATH}" "${DAEMON_NAME}"
77 result=$?
78 return $result
79}
80
81do_usage() {
82 echo $"Usage: $0 {start | stop | restart | status}"
83 exit 1
84}
85
86case "$1" in
87start) do_start; exit $? ;;
88stop) do_stop; exit $? ;;
89restart) do_restart; exit $? ;;
90status) do_status; exit $? ;;
91*) do_usage; exit 1 ;;
92esac
93