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