127 |
|
|
128 |
telinit q |
telinit q |
129 |
|
|
130 |
|
If monit is used to monitor services that are also started at |
131 |
|
boot time (e.g. services started via SYSV init rc scripts or via |
132 |
|
inittab) then in some situations a special race condition can |
133 |
|
occur. That is; if a service is slow to start, monit can assume |
134 |
|
that the service is not running and possibly try to start it and |
135 |
|
raise an alert, while, in fact the service is already about to |
136 |
|
start or already in its startup sequence. If you experience this |
137 |
|
problem, here are a couple of strategies you can use to prevent |
138 |
|
this type of race condition: |
139 |
|
|
140 |
|
|
141 |
|
A) Start critical services directly from monit: |
142 |
|
|
143 |
|
This is the recommended solution - let monit takeover the |
144 |
|
responsibility for starting services. To use this strategy you |
145 |
|
must turn off the systems automatic start and stop for all |
146 |
|
services handled by monit. |
147 |
|
|
148 |
|
On RedHat, you can for example use: |
149 |
|
|
150 |
|
chkconfig myprocess off |
151 |
|
|
152 |
|
on Debian: |
153 |
|
|
154 |
|
update-rc.d -f myprocess remove |
155 |
|
|
156 |
|
a general example: |
157 |
|
|
158 |
|
mv /etc/rc2.d/S99myprocess /etc/rc2.d/s99myprocess |
159 |
|
|
160 |
|
If monit is started from a rc script, then to stop the service |
161 |
|
at systems shutdown, you should add the following line to |
162 |
|
monit's rc script: |
163 |
|
|
164 |
|
/usr/local/bin/monit -c /etc/monitrc stop myprocess |
165 |
|
|
166 |
|
or if monit handles more than one service, simply stop all |
167 |
|
services by using: |
168 |
|
|
169 |
|
/usr/local/bin/monit -c /etc/monitrc stop all |
170 |
|
|
171 |
|
If monit instead is started from init then, add a second line |
172 |
|
to inittab to stop the service: |
173 |
|
|
174 |
|
mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc |
175 |
|
m0:06:wait:/usr/local/bin/monit -Ic /etc/monitrc stop myprocess |
176 |
|
|
177 |
|
or to stop all services handled by monit: |
178 |
|
|
179 |
|
mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc |
180 |
|
m0:06:wait:/usr/local/bin/monit -Ic /etc/monitrc stop all |
181 |
|
|
182 |
|
Services handled by monit I<must> have start and stop methods |
183 |
|
defined so monit can start and stop a service. For instance: |
184 |
|
|
185 |
|
check process myprocess with pidfile /var/run/myprocess.pid |
186 |
|
start program = "/etc/init.d/myprocess start" |
187 |
|
stop program = "/etc/init.d/myprocess stop" |
188 |
|
alert foo@bar.baz |
189 |
|
|
190 |
|
|
191 |
|
B) Make init wait for a service to start: |
192 |
|
|
193 |
|
This solution will make the init process wait for the service |
194 |
|
to start before it will continue to start other services. If |
195 |
|
you are running monit from init, you must enter monit's line |
196 |
|
at the end of /etc/inittab (A short example): |
197 |
|
|
198 |
|
si::sysinit:/etc/init.d/rcS |
199 |
|
... |
200 |
|
l2:2:wait:/etc/init.d/rc 2 |
201 |
|
... |
202 |
|
mo:2345:respawn:/usr/local/bin/monit -Ic /etc/monitrc |
203 |
|
|
204 |
|
The rc script for the monitored service must be I<modified> |
205 |
|
so, that it will not return unless the service was started or |
206 |
|
start of the service timed out. Creative use of sleep(1) may |
207 |
|
be sufficient. |
208 |
|
|
209 |
|
As in the above example, services handled by monit must have |
210 |
|
start and stop methods defined. |
211 |
|
|
212 |
|
|
213 |
|
C) Enable the service monitoring manually from monit: |
214 |
|
|
215 |
|
check file myprocess.pid with path /var/run/myprocess.pid |
216 |
|
if timestamp > 5 minutes then |
217 |
|
exec "/bin/bash -c ' |
218 |
|
/usr/bin/monit -c /etc/monitrc monitor myprocess; |
219 |
|
/usr/bin/monit -c /etc/monitrc unmonitor myprocess.pid |
220 |
|
'" |
221 |
|
check process myprocess with pidfile /var/run/myprocess.pid |
222 |
|
start program = "/etc/init.d/myprocess start" |
223 |
|
stop program = "/etc/init.d/myprocess stop" |
224 |
|
alert foo@bar.baz |
225 |
|
mode manual |
226 |
|
|
227 |
|
This will cause monit to wait for 5 minutes before it will |
228 |
|
enable monitoring of the service myprocess. |
229 |
|
|
230 |
|
|
231 |
|
|
232 |
8. Q: Why is monit not able to gather process data of 64bit applications |
8. Q: Why is monit not able to gather process data of 64bit applications |
233 |
on Solaris? |
on Solaris? |
234 |
|
|
250 |
to other unices, too. |
to other unices, too. |
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
HOW-TO debug: |
HOW-TO debug: |
256 |
|
|
257 |
a) Start monit |
a) Start monit |