File tree Expand file tree Collapse file tree 1 file changed +19
-15
lines changed Expand file tree Collapse file tree 1 file changed +19
-15
lines changed Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
2
3
- # NOTE: THIS NTP SERVICE CHECK SCRIPT ASSUME THAT NTP SERVICE IS RUNNING UNDER SYSTEMD .
4
- # THIS IS JUST AN EXAMPLE. YOU CAN WRITE YOUR OWN NODE PROBLEM PLUGIN ON DEMAND .
3
+ # This plugin checks if the ntp service is running under systemd .
4
+ # NOTE: This is only an example for systemd services .
5
5
6
- OK=0
7
- NONOK=1
8
- UNKNOWN=2
6
+ readonly OK=0
7
+ readonly NONOK=1
8
+ readonly UNKNOWN=2
9
9
10
- which systemctl > /dev/null
11
- if [ $? -ne 0 ]; then
12
- echo " Systemd is not supported"
13
- exit $UNKNOWN
10
+ readonly SERVICE=' ntp.service'
11
+
12
+ # Check systemd cmd present
13
+ if ! command -v systemctl > /dev/null; then
14
+ echo " Could not find 'systemctl' - require systemd"
15
+ exit $UNKNOWN
14
16
fi
15
17
16
- systemctl status ntp.service | grep ' Active:' | grep -q running
17
- if [ $? -ne 0 ]; then
18
- echo " NTP service is not running"
19
- exit $NONOK
18
+ # Return success if service active (i.e. running)
19
+ if systemctl -q is-active " $SERVICE " ; then
20
+ echo " $SERVICE is running"
21
+ exit $OK
22
+ else
23
+ # Does not differenciate stopped/failed service from non-existent
24
+ echo " $SERVICE is not running"
25
+ exit $NONOK
20
26
fi
21
27
22
- echo " NTP service is running"
23
- exit $OK
You can’t perform that action at this time.
0 commit comments