Answers for "start a service in bash if stopped"

0

start a service in bash if stopped

#!/bin/bash
SERVICE="nginx"
if pgrep -x "$SERVICE" >/dev/null
then
    echo "$SERVICE is running"
else
    echo "$SERVICE stopped"
    # uncomment to start nginx if stopped
    # systemctl start nginx
    # mail  
fi
Posted by: Guest on July-21-2021

Browse Popular Code Answers by Language