2

I want to start a blocking server in a screen on reboot, so that I may access it later.

The command screen -d -m /home/dataserv/www/start_production_server.sh works on its own just fine regardless from where its called, but does not if used as a crontab entry.

dataserv@dataserv-dev:~$ crontab -l
# m h  dom mon dow   command
@reboot echo "test" > /home/dataserv/reboot.txt 2>&1
@reboot screen -d -m /home/dataserv/www/start_production_server.sh

The test entry works fine so I'm quite puzzled as to why its failing.

5
  • 1
    Did you try to type the absolute path of screen (I guess /usr/bin/screen instead of just screen)?
    – Mathieu
    Dec 26, 2015 at 19:31
  • Have you checked permissions? Dec 26, 2015 at 21:56
  • I also tried with the absolute path, which did not help. The permissions are right as the reboot.txt file was created by the dataserv user. Dec 27, 2015 at 13:54
  • 1
    Have you checked any logs to give some indication as to why it's failing? I'm not sure if screen has a -v option or a log. Dec 28, 2015 at 10:00
  • If you add the -L option (before -d, for instance), screen will log output into the cron user's home directory (perhaps yours), naming the file screenlog.0. If you need more debugging help, turning on the script trace (e.g., #!/bin/sh -x at the top) might help. Since you haven't posted the server script, there's really not enough information to do more than suggest ways for you to solve your problem. Dec 29, 2015 at 22:10

1 Answer 1

3
+25

Running the screen command from cron and capturing its stderr reports this message:

Must run suid root for multiuser support.

A quick search around results in the discovery that this message is printed when screen has no tty device from which it can build its session name. (Normally the session name is something like 11597.pts-0.myhostname.) Further reading of the man page shows that the -S flag can be used to specify a session name:

screen -md -S "atboot.$(hostname)" ...

There's nothing special about the "atboot" label; I used it to remind me that the process was started at boot time and didn't have a tty.

Combining this with your crontab specification leads to this:

# m h  dom mon dow   command
@reboot echo "test" > /home/dataserv/reboot.txt 2>&1
@reboot screen -d -m -S "atboot.$(hostname)" /home/dataserv/www/start_production_server.sh

Running screen -ls will give an output similar to this:

11732.atboot.myhostname      (03/01/16 00:25:01)     (Detached)
2
  • This did not work for me. Jan 4, 2016 at 22:42
  • @fabe it worked for me. Can you please try replacing "atboot.$(hostname)" with just "atboot" in case it's a shell or $PATH issue
    – roaima
    Jan 4, 2016 at 23:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .