Research
Perhaps I'm using the incorrect vocabulary, but I can't seem to find a duplicate of my issue. I am trying to execute two programs within my shell script and cron is clearly executing the first script, but not the second.
Goal
I have two python scripts, views.py
that runs as a web server and housekeeping.py
that takes care of some cleanup and update checks that the web interface need not worry about. Currently, these can be manually started using sudo /home/ubuntu/start_server.sh
and all works perfectly. I am using port 80, so I need to run as root.
Bash Script
The full bash script:
#!/bin/bash
/home/ubuntu/py3env/bin/python /home/ubuntu/flask_portal/views.py &
/home/ubuntu/py3env/bin/python /home/ubuntu/flask_portal/housekeeping.py &
My understanding is that the &
will cause applications to run in the background.
When I execute manually, the shell script works perfectly.
Crontab
To open crontab, I am using
sudo crontab -u root -e
As I said above, I am using port 80 so I need to run my script as root.
Within the crontab file, I have a single entry:
@reboot /home/ubuntu/start_server.sh
Results
When I execute by hand, both scripts start perfectly. When I allow the server to restart and run the start_server.sh
script itself, the web server views.py
works just fine, but housekeeping.py
never starts (I'm doing logging within that file, so it isn't generating the proper files). In addition, when I execute python aux | grep python
, I see that both views.py
and housekeeping.py
are executing.
sudo env -i /home/ubuntu/py3env/bin/python /home/ubuntu/flask_portal/housekeeping.py
sudo
in that line, but I can verify that the command is executing properly when I type insudo ./start_server.sh
. Is there something there that I should put in the crontab or in the shell script?housekeeping.py
file with no issues.