Crontab execution of multiple commands but last command is omitted
The /usr/sbin
directory (where the upstart service
command lives) isn't in the default crontab path, so you will either need to add an explicit PATH
assignment in the top of your crontab file e.g.:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
or use the full path in your command
/usr/sbin/service nginx restart
You will need to do this whether you keep it as an in-line command or break it out into a shell script (although you'd then have the choice of setting the PATH
in the script versus in the crontab file).
FWIW since variants of this question are frequently asked, here's the default cron environment on my 16.04 system, obtained by running /usr/bin/printenv > /tmp/cronenv
from root's crontab:
LANGUAGE=en_CA:en
HOME=/root
LOGNAME=root
PATH=/usr/bin:/bin
LANG=en_CA.UTF-8
SHELL=/bin/sh
PWD=/root
Note how minimal it is - this is often why commands or scripts that run fine in an interactive shell fail when run from cron.