Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
icinga-checks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
icinga-checks
Commits
3ab9de15
Commit
3ab9de15
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
add check script for a systemd unit
parent
b46130be
No related branches found
No related tags found
1 merge request
!161
Add systemdunit
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_systemdunit
+77
-0
77 additions, 0 deletions
check_systemdunit
with
77 additions
and
0 deletions
check_systemdunit
0 → 100755
+
77
−
0
View file @
3ab9de15
#!/bin/bash
# ================================================================================
#
# CHECK A SINGLE SYSTEMD SERVICE
#
# (1)
# shows overview of important services - edit check_systemdservices.cfg to define
# them
#
# (2)
# resturns
# - OK if all systemd servises are running
# - UNKNOWN if systemctl command is not available
# - ERROR if any systemd service is not running
#
# -------------------------------------------------------------------------------
# 2023-09-05 v01.0 <axel.hahn@unibe.ch>
# ================================================================================
.
$(
dirname
$0
)
/inc_pluginfunctions
export
self_APPVERSION
=
1.0
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
# show help text
function
showHelp
(){
local
_self
;
_self
=
$(
basename
$0
)
cat
<<
EOF
$(
ph.showImlHelpHeader
)
Check a unit using systemctl status.
The status is unknown if the command systemctl is not found.
The status is critical if the service does not exist or is not running.
SYNTAX:
$_self
[-h] UNIT
OPTIONS:
-h this help
UNIT Name of a unit - see output of 'systemctl'
EXAMPLES:
$_self
mysql.service
show status of service mysql
EOF
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
ph.hasParamoption
"h"
"
$@
"
;
bOptHelp
=
$?
if
[
$bOptHelp
-eq
0
-o
$#
-eq
0
]
;
then
showHelp
exit
0
fi
ph.require
"systemctl"
_service
=
"
${
1
}
"
_status
=
$(
systemctl
--no-pager
-l
status
"
${
_service
}
"
2>&1
)
if
!
grep
"Active: active (running) "
<<<
"
${
_status
}
"
>
/dev/null
;
then
ph.setStatus critical
fi
ph.status
"
${
_status
}
"
ph.exit
# ----------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment