Naposledy aktivní 1 month ago

Revize ea01328c5aca215d3d348cdda869bbb5ddfc4079

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_NICE=0
30
31[ -r "/etc/default/${DAEMON_NAME}" ] && source "/etc/default/${DAEMON_NAME}"
32
33
34do_start() {
35 local result
36 log_daemon_msg "${STARTUP_MSG}" "${DAEMON_NAME}"
37 if [ -z "${DAEMON_USER}" ]; then
38 start_daemon -n $DAEMON_NICE -p "${DAEMON_PID}" "${DAEMON_PATH}" $DAEMON_OPTS
39 result=$?
40 else
41 start-stop-daemon --start --quiet --oknodo --background \
42 --nicelevel $DAEMON_NICE \
43 --chdir "${DAEMON_PWD}" \
44 --pidfile "${DAEMON_PID}" --make-pidfile \
45 --chuid "${DAEMON_USER}" \
46 --exec "${DAEMON_PATH}" -- $DAEMON_OPTS
47 result=$?
48 fi
49 log_end_msg $result
50 return $result
51}
52
53do_stop() {
54 local result
55 log_daemon_msg "${SHUTDOWN_MSG}" "${DAEMON_NAME}"
56 killproc -p "${DAEMON_PID}" "${DAEMON_PATH}"
57 result=$?
58 log_end_msg $result
59 return $result
60}
61
62do_restart() {
63 local result
64 do_stop
65 result=$?
66 if [ $result = 0]; then
67 do_start
68 result=$?
69 fi
70 return $result
71}
72
73do_status() {
74 local result
75 status_of_proc -p "${DAEMON_PID}" "${DAEMON_PATH}" "${DAEMON_NAME}"
76 result=$?
77 return $result
78}
79
80do_usage() {
81 echo $"Usage: $0 {start | stop | restart | status}"
82 exit 1
83}
84
85case "$1" in
86start) do_start; exit $? ;;
87stop) do_stop; exit $? ;;
88restart) do_restart; exit $? ;;
89status) do_status; exit $? ;;
90*) do_usage; exit 1 ;;
91esac
92