Last active
April 26, 2019 14:01
-
-
Save peycho/6c7432d61ab82cab3e828378bae06f25 to your computer and use it in GitHub Desktop.
Monitoring linux process with bash script.
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 | |
process="your-process-here" | |
run_command="command to start the process" | |
time_check="5" # time to check in sec. | |
while true ; do | |
proc_count=$(ps xa | grep -v grep | grep "$process" | wc -l) | |
if [ "$proc_count" == 0 ]; then | |
$run_command | |
echo "$(date) process $process was restarted." | |
fi | |
sleep $time_check | |
done | |
exit 0 |
Systemd config
Create example config in /etc/systemd/system/procx.service
[Unit]
Description=procx
Requires=network-online.target
After=network-online.target
[Service]
User=youruser
Group=yourgroup
Restart=on-failure
LimitAS=infinity
LimitRSS=infinity
LimitCORE=infinity
LimitNOFILE=999999
Environment=LANG=en_US.UTF-8
Environment=LC_ALL=en_US.UTF-8
SyslogIdentifier=procx
ExecStart=/path/to/procx.sh
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
[Install]
WantedBy=multi-user.target
Enable the service
sudo systemctl enable procx.service
sudo systemclt start procx.service
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To start it in screen