1

I'm using Plesk 12 + CentOS 6.

I ssh into root account and use crontab -e to create the following entry:

* * * * * service httpd restart

I expect it to restart apache every minute (just to test/debug it's working)

I checked the apache status using service httpd status and the PID is always the same, and apache is not restarting.

I verified /var/log/cron that the command is being executed.

Feb 7 16:11:01 srv104 CROND[15620]: (root) CMD (service httpd restart)

However, all other entries in the crontab are correctly executing.

If I execute the command service httpd restart manually in shell terminal, apache is restarting correctly with a new updated PID.

Is there any preventive measure in place such that service can't be executed in root cronjob?


Why is my crontab not working, and how can I troubleshoot it? has some useful tips, but does not address my specific situation mentioned in the original question above.

Working Solution:

If I specify the full path to the /sbin/service, eg. /sbin/service httpd restart in the cronjob, as mentioned in the accepted answer, it does work.

Not sure if it's operating system version related, but simply with the PATH in place in /etc/crontab/ does not help in my situation.

KDX
  • 213
  • 1
  • 11
  • 1
    Try to set PATH variable in your crontab properly. By default, it may look for executables into /bin or /usr/bin directories only. As 'service' script/tool is in /sbin directory it may be not working. – dsmsk80 Feb 07 '17 at 17:22

1 Answers1

2

Replace your command with /sbin/service httpd restart.

Or as pointed out in the comments: setting a PATH in /etc/crontab, including /sbin and /usr/sbin should do.

SYN
  • 1,751
  • 8
  • 14
  • My current `/etc/crontab` already has this entry: `PATH=/sbin:/bin:/usr/sbin:/usr/bin` and it failed to restart apache with just `service httpd restart` in cronjob entry. However, if I specify the full path as you mentioned, `/sbin/service httpd restart`, it does work. – KDX Feb 08 '17 at 07:31