0

What I'm doing

I've been migrating one setup to another, copying configuration and installing dependencies, I was about to be done until screen didn't work as intended.

I have a script that I keep runing on a detached screen that I initialize on boot, the setup is practically identical to the one on the old machine, still no luck

What I have:

  • an Ubuntu 20.04 machine
  • a bar.screenrc with:
screen sh /path/to/file/foo.sh
  • a foo.sh with:
#!/usr/bin/env python3.8
cd /path/to/file/
gunicorn --bind 0.0.0.0:5002 wsgi:app --log-level debug --error-logfile gunicorn.log
  • a cronjob with:
@reboot /usr/bin/screen -c /path/to/file/bar.screenrc >> /path/to/file/cron.log 2>&1 -dmS API

The scenario

On reboot no new session appears, however, if I copy and paste the line (without the @reboot), it'll work as intended.

I tried changing the .screenrc to /usr/bin/screen /usr/bin/sh /path/to/file/foo.sh and this change does initiate a detached screen, but its not running the gunicorn instance

This exact same scenario works on the old setup and has worked on other projects of my own in the past

Disclaimer

I know things can be done with services instead of screen, this is out of the current scope of the project and this question.

Tronikart
  • 101
  • 1
    Duplicate https://unix.stackexchange.com/questions/78017/running-screen-through-a-reboot-cron-job https://superuser.com/questions/918677/starting-script-in-screen-with-cron https://stackoverflow.com/questions/30266676/run-screen-and-command-crontab probably others. – user10489 Jul 12 '22 at 22:57
  • As much as a duplicate, not sure, the 2nd and 3rd don't offer much help, but it wasn't until the 4th answer on the 1st one that I found a workaround, not exactly a fix or explanation why this is not happening on my other server, but oh well. I changed the crontab to be: `@reboot /usr/bin/screen -dmS API sh -c '/path/to/file/bar.screenrc;exec sh'` And that was it, it spins a screen with two windows, one running gunicorn, the other one empty, no idea why this works but after 3 days of trying to figure it out, I'll let it slide – Tronikart Jul 13 '22 at 22:26

0 Answers0