28 lines
582 B
Bash
28 lines
582 B
Bash
|
#!/bin/bash
|
||
|
|
||
|
# Find service name from argument
|
||
|
monitorService=$1
|
||
|
|
||
|
# Check if $monitorService is empty
|
||
|
if [ -z "$monitorService" ]; then
|
||
|
read -p "Please pass me the service name: " monitorService
|
||
|
fi
|
||
|
|
||
|
|
||
|
# Define the check_service function
|
||
|
function check_service {
|
||
|
|
||
|
# Check if the service is active and report so
|
||
|
if systemctl is-active --quiet $monitorService; then
|
||
|
echo "$monitorService is running"
|
||
|
|
||
|
# If the service is not running, exit with an error.
|
||
|
else
|
||
|
echo "$monitorService is not running"
|
||
|
exit 1
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
# Excecute the check_service function
|
||
|
check_service
|