I have a cronjob running on AWS EC2, that I usually launch via crontab:
0 */6 * * * sudo python3 /opt/homeDirectoryForMyApp/manage.py myCronJob --settings=server.settings.production
This works correctly as expected. Now I'm trying to launch the same job via SystemD.
myCronJob.service:
[Unit]
Description=myCronJob Service
Wants=myCronJob.timer
[Service]
ExecStart='/usr/bin/python3.7' manage.py myCronJob --settings=server.settings.production
WorkingDirectory=/opt/homeDirectoryForMyApps/
[Install]
WantedBy=multi-user.target
myCronJob.timer:
[Unit]
Description=launch myCronJob
Requires=myCronJob.service
[Timer]
Unit=myCronJob.service
OnCalendar=00/2:10
[Install]
WantedBy=rss.target
I'm getting this in journalctl (via journalctl -u myCronJob
):
Jan 02 22:45:03 ip-###-##-#-### systemd[3760]: myCronJob.service: Failed at step CHDIR spawning /usr/bin/python3.7: No such file or directory
But /usr/bin/python3.7
does exist at that path:
ubuntu@ip-###-##-#-###:/etc/systemd/system$ cd /usr/bin
ubuntu@ip-###-##-#-###:/usr/bin$ ls python3.7
python3.7
What am I missing?
The error you are seeing is:
Failed at step CHDIR spawning /usr/bin/python3.7: No such file or directory
This suggests that the problem actually lies with your WorkingDirectory
setting in your unit file (step CHDIR
means "the error occurred when trying to change directory").
There is probably a typo in your WorkingDirectory
path in your unit file.