Última atividade 1 month ago

Revisão 2aed7e6f2b854ac1736aa0e8b1364455cb738239

debian-init.sh Bruto
1#!/bin/sh
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 Program
9# Description: Generic Program 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 functions 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}"
24DAEMON_DESC=$(get_lsb_header_val $0 "Short-Description")
25DAEMON_PID="/var/run/${DAEMON_NAME}.pid"
26DAEMON_NICE=0
27
28[ -r "/etc/default/${DAEMON_NAME}" ] && source "/etc/default/${DAEMON_NAME}"
29
30do_start() {
31 local result
32
33 pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null
34 if [ $? -eq 0 ]; then
35 log_warning_msg "${DAEMON_NAME} is already started"
36 result=0
37 else
38 log_daemon_msg "Starting ${DAEMON_DESC}" "${DAEMON_NAME}"
39 if [ -z "${DAEMON_USER}" ]; then
40 start-stop-daemon --start --quiet --oknodo --background \
41 --nicelevel $DAEMON_NICE \
42 --chdir "${DAEMON_PWD}" \
43 --pidfile "${DAEMON_PID}" --make-pidfile \
44 --exec "${DAEMON_PATH}" -- $DAEMON_OPTS
45 result=$?
46 else
47 start-stop-daemon --start --quiet --oknodo --background \
48 --nicelevel $DAEMON_NICE \
49 --chdir "${DAEMON_PWD}" \
50 --pidfile "${DAEMON_PID}" --make-pidfile \
51 --chuid "${DAEMON_USER}" \
52 --exec "${DAEMON_PATH}" -- $DAEMON_OPTS
53 result=$?
54 fi
55 log_end_msg $result
56 fi
57 return $result
58}
59
60do_stop() {
61 local result
62
63 pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null
64 if [ $? -ne 0 ]; then
65 log_warning_msg "${DAEMON_NAME} is not started"
66 result=0
67 else
68 log_daemon_msg "Stopping ${DAEMON_DESC}" "${DAEMON_NAME}"
69 killproc -p "${DAEMON_PID}" "${DAEMON_PATH}"
70 result=$?
71 log_end_msg $result
72 rm "${DAEMON_PID}"
73 fi
74 return $result
75}
76
77do_restart() {
78 local result
79 do_stop
80 result=$?
81 if [ $result = 0 ]; then
82 do_start
83 result=$?
84 fi
85 return $result
86}
87
88do_status() {
89 local result
90 status_of_proc -p "${DAEMON_PID}" "${DAEMON_PATH}" "${DAEMON_NAME}"
91 result=$?
92 return $result
93}
94
95do_usage() {
96 echo $"Usage: $0 {start | stop | restart | status}"
97 exit 1
98}
99
100case "$1" in
101start) do_start; exit $? ;;
102stop) do_stop; exit $? ;;
103restart) do_restart; exit $? ;;
104status) do_status; exit $? ;;
105*) do_usage; exit 1 ;;
106esac
107