I have a simple crontab entry that is supposed to stop a service, yet it does not work.
* * * * * systemctl stop nginx
I even tried:
* * * * * /bin/systemctl stop nginx
Since that't the location of systemctl that which command shows.
That line works with root user, yet not working with root's crontab.
And by not working, I mean the service is not shut down. I can confirm the server is still running and systemctl status nginx show it's active.
What am I doing wrong?
Best Answer
Probably because you haven't told cron to use root.
That will execute the command every minute, regardless of the nginx status (started or not)
So that being said, if the goal is to make sure nginx is never started, why not just disable it?
==Edit==
Good point made by Aaron Copley in the comments, in order to make sure nginx wont be started even after boot the command should be;