user38931
user38931

Reputation: 491

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!

Upvotes: 6

Views: 7195

Answers (1)

armnotstrong
armnotstrong

Reputation: 9065

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

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

Upvotes: 4

Related Questions