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