Can I run this cron for 1 minute?

Hello guys, I have an problem where some of my services stop working until I restart them. Services like ngix, mariadb, php7.4, so I have added the following codes to restart them automatically when not active so I won’t have to do them manually anymore.

if ! systemctl is-active --quiet mariadb; then
    systemctl restart mariadb
fi

if ! systemctl is-active --quiet apache2; then
    systemctl restart apache2
fi

if ! systemctl is-active --quiet bind9; then
    systemctl restart bind9
fi

if ! systemctl is-active --quiet nginx; then
    systemctl restart nginx
fi

if ! systemctl is-active --quiet  php7.4-fpm; then
    systemctl restart  php7.4-fpm
fi

I added them to /usr/local/hestia/bin/v-update-sys-queue which is set to run every 2 minutes via cron job.

So I want to know if I can set it to run every minute, will it be ok?

Sure you can set your own time. I suggest you to copy one of those scripts from /usr/local/hestia/bin give it a new name add your code in there and last add your own cron job.

PS: if you create your own script from copying one of the other files, do not forget to make it executable!

PS2: you can modify your script like this:

services=(“mariadb” “apache2” “bind9” “nginx” “php7.4-fpm”)

for service in “${services[@]}”; do
if ! systemctl is-active --quiet “$service”; then
systemctl restart “$service”
fi
done

so if you need to add more services you can do it in the array without adding a new if statement!

Create the file in /root/ folder give it execution right

crontab -e

* * * * * /root/filename.sh

1 Like

@eris why in root and not in bin? will overide the files after update?

Why in hestia bin folder if is not used for Hestia it self?

I had never an issue with with any service randomly stopping is that the case you probally need to check what happens en restarting it will only hide the issue

2 Likes