Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start/stop a systemd service in cronjob

  1. I have a service name bots in /etc/systemd/system/bots.service
  2. I have a shell script name runcron.sh like this
service bots stop

service bots start
  1. If I run ./runcron.sh the service will be stop then start successfully but if I put it in a crontab like this, it won't run successfully

*/5 * * * * /home/vps171-107/runcron.sh

How can I make runcron.sh stop then start the bots service in crontab ?

UPDATE

After the help from @armnotstrong , I've change the script to

/usr/sbin/service bots stop
/usr/sbin/service bots start

And it works!

like image 995
user38931 Avatar asked Feb 07 '17 03:02

user38931


1 Answers

It may be an env issue, crontab may execute the command with sh not bash try:

*/5 * * * * bash /home/vps171-107/runcron.sh
like image 117
armnotstrong Avatar answered Oct 17 '22 11:10

armnotstrong