N
N
NeoLight22020-05-29 13:57:31
linux
NeoLight2, 2020-05-29 13:57:31

Bash script for Linux that restarts a program/service automatically after a given time?

There is Ubuntu Server 16.04 LTS 64 bit.
There is a program (server) .x86_64 that has the problem of "hanging" after a while, and therefore a bash script is needed that will automatically restart the program after a specified time.

If there are any solutions, I would be happy to hear.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Armenian Radio, 2020-05-29
@gbg

Either fix the bydlocode,
Or put it in systemd and put the systemctl restart call in cron [name of the bydlocode piece]

T
Talyan, 2020-05-29
@flapflapjack

nano /usr/local/bin/killproc.sh
there

#!/bin/bash
PROCFOLDER="/bin/" #папка процесса
PROCNAME="Thunar"; #имя процесса
kill `ps aux | grep $PROCNAME| tail -n2 | head -n1 |awk {'print $2'}`
$PROCFOLDER$PROCNAME

Further
chmod +x /usr/local/bin/killproc.sh
nano /etc/crontab

and there To twitch every 10 minutes. But it seems to me that you do not have a process, but a daemon, so you can stupidly write service httpd restart in the crontab, for example
*/10 * * * * root /usr/local/bin/killproc.sh

V
Victor Taran, 2020-05-29
@shambler81

as a rule, the construction is used
/etc/init.d/.... status || /etc/init.d... restart(there are many options)
where || the exit code of the program is false
, that is, they check the status of the daemon.
it would not be bad to say what kind of software.

V
Vladimir Kuts, 2020-05-29
@fox_12

monit
In the settings, specify the criterion for the process to hang, and the action to take when it occurs

D
Dobryelectrik, 2020-05-31
@Dobryelectrik

There is such a heartbeat event for servers, you can read it here
https://www.opennet.ru/docs/RUS/ha_cluster/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question