]> TLD Linux GIT Repositories - rc-scripts.git/blob - doc/template.init
- disable lock checks (happens on LUKS2 and fails during system boot)
[rc-scripts.git] / doc / template.init
1 #!/bin/sh
2 #
3 # <service>     <service> short service description
4 #
5 # chkconfig:    345 <start_level> <stop_level>
6 #
7 # description:  <service> long service description
8 #
9 # processname:  <procname>
10 # config:
11 # pidfile:
12 #
13
14 # Source function library
15 . /etc/rc.d/init.d/functions
16
17 # Get network config
18 . /etc/sysconfig/network
19
20 # Check that networking is up.
21 if is_yes "${NETWORKING}"; then
22         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
23                 msg_network_down "<service_name>"
24                 exit 1
25         fi
26 else
27         exit 0
28 fi
29
30 # Set defaults
31 OPTION1=""      # Strings
32 OPTION2="-q"    #
33 OPTION3=        # Values
34 OPTION4=5       #
35
36 # Get service config - may override defaults
37 [ -f /etc/sysconfig/<service> ] && . /etc/sysconfig/<service>
38
39 pidfile="/var/run/<service>.pid"
40
41 # configtest itself
42 # must return non-zero if check failed
43 # output is discarded if checkconfig is ran without details
44 configtest() {
45         /usr/sbin/<service> -t
46         return $?
47 }
48
49 # wrapper for configtest
50 checkconfig() {
51         local details=${1:-0}
52
53         if [ $details = 1 ]; then
54                 # run config test and display report (status action)
55                 show "Checking %s configuration" "<service_name>"; busy
56                 local out
57                 out=$(configtest 2>&1)
58                 RETVAL=$?
59                 if [ $RETVAL = 0 ]; then
60                         ok
61                 else
62                         fail
63                 fi
64                 [ "$out" ] && echo >&2 "$out"
65         else
66                 # run config test and abort with nice message if failed
67                 # (for actions checking status before action).
68                 configtest >/dev/null 2>&1
69                 RETVAL=$?
70                 if [ $RETVAL != 0 ]; then
71                         show "Checking %s configuration" "<service_name>"; fail
72                         nls 'Configuration test failed. See details with %s "checkconfig"' $0
73                         exit $RETVAL
74                 fi
75         fi
76 }
77
78 start() {
79         # Check if the service is already running?
80         if [ -f /var/lock/subsys/<service> ]; then
81                 msg_already_running "<service_name>"
82                 return
83         fi
84
85         checkconfig
86         msg_starting "<service_name>"
87         daemon /usr/sbin/<service>
88         RETVAL=$?
89         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/<service>
90 }
91
92 stop() {
93         if [ ! -f /var/lock/subsys/<service> ]; then
94                 msg_not_running "<service_name>"
95                 return
96         fi
97
98         # Stop daemons.
99         msg_stopping "<service_name>"
100         killproc <procname>
101         killproc --pidfile $pidfile <procname> -TERM
102         rm -f /var/lock/subsys/<service>
103 }
104
105 reload() {
106         if [ ! -f /var/lock/subsys/<service> ]; then
107                 msg_not_running "<service_name>"
108                 RETVAL=7
109                 return
110         fi
111
112         checkconfig
113         msg_reloading "<service_name>"
114         killproc <procname> -HUP
115         killproc --pidfile $pidfile <procname> -HUP
116         RETVAL=$?
117 }
118
119 condrestart() {
120         if [ ! -f /var/lock/subsys/<service> ]; then
121                 msg_not_running "<service_name>"
122                 RETVAL=$1
123                 return
124         fi
125
126         checkconfig
127         stop
128         start
129 }
130
131 RETVAL=0
132 # See how we were called.
133 case "$1" in
134   start)
135         start
136         ;;
137   stop)
138         stop
139         ;;
140   restart)
141         checkconfig
142         stop
143         start
144         ;;
145   try-restart)
146         condrestart 0
147         ;;
148 # include force-reload here if program allows reloading without restart
149 # otherwise remove reload action and support force-reload as restart if running
150   reload|force-reload)
151         reload
152         ;;
153 # use this one if program doesn't support reloading without restart
154   force-reload)
155         condrestart 7
156         ;;
157   checkconfig|configtest)
158         checkconfig 1
159         ;;
160   status)
161         status <service>
162         status --pidfile $pidfile <service>
163         status --pidfile $pidfile <service> <procname>
164         RETVAL=$?
165         ;;
166   *)
167         msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}"
168         exit 3
169 esac
170
171 exit $RETVAL