I have an Upstart init script that manages a python script on the server. The pre-start and pre-stop scripts append a timestamped entry into a log file. There is a cronjob to stop and start the service once an hour. When I start or stop the service as root these entries get added to the log file, but when my cronjob runs the entries are not added.
description "Manages some_script" author "me" start on runlevel  stop on shutdown respawn respawn limit 10 10 script exec /usr/bin/python3.4 /usr/bin/some_script.py end script pre-start script echo "[`date +%Y-%m-%d%l:%M:%S%p`] Some Script Starting" >> /var/log/some_scriptd.log end script pre-stop script echo "[`date +%Y-%m-%d%l:%M:%S%p`] Some Script Stopping" >> /var/log/some_scriptd.log end script
crontab -l -u root
# Stop and start the some_scriptd service once an hour 30 * * * * initctl stop some_scriptd && initctl start some_scriptd
I've checked /var/log/cron and I can see the cronjob being run as scheduled.
Feb 15 09:30:01 my_server CROND: (root) CMD (initctl stop some_scriptd && initctl start some_scriptd)
The log file does not show entries from the cronjob, only from when I manually stop and start the service as root.
[2019-02-15 8:58:43AM] Some Script Stopping [2019-02-15 8:58:43AM] Some Script Starting
Update: I checked the pid of the running python script before and after the cronjob ran and it remained the same. This indicates to me that the initctl command was not successful at all. It wasn't a matter of just the pre-start and pre-stop scripts failing.