Created
February 12, 2025 13:39
-
-
Save zanshin/8ea4b110b0be3061e34a2be2e593ec3a to your computer and use it in GitHub Desktop.
Check to see if a service is running, if not, start the service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if a service name was provided | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <service_name>" | |
exit 1 | |
fi | |
SERVICE_NAME="$1" | |
# Check if the service is running | |
if systemctl is-active --quiet "$SERVICE_NAME"; then | |
echo "$SERVICE_NAME is already running." | |
else | |
echo "$SERVICE_NAME is not running. Starting it now..." | |
sudo systemctl start "$SERVICE_NAME" | |
# Verify if it started successfully | |
if systemctl is-active --quiet "$SERVICE_NAME"; then | |
echo "$SERVICE_NAME started successfully." | |
else | |
echo "Failed to start $SERVICE_NAME." | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Created using ChatGPT