0

This question already has an answer here:

I am trying to run a java program inside a screen session at boot, I am using the following cron, but after reboot screen -ls shows no active screen sessions.

@reboot /usr/bin/screen -dmS myservice "java -jar /home/david/myservice/MyService-0.0.1-SNAPSHOT.jar"

Any idea what I am doing wrong?

EDIT:

I did change it to the following and the screen does start at boot now.

@reboot /usr/bin/screen -dmS myservice && "java -jar /home/david/myservice/MyService-0.0.1-SNAPSHOT.jar"

I added && before starting the java command and not the screen does start at boot. But the program is still not running.

but the program is not running when I attach to the screen. after attaching to the screen all I see is a dollar sign.

marked as duplicate by HBruijn linux Oct 30 '18 at 16:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 5
    Don't run services in screen. It is not reliable for production use, and it is not a service manager anyway. Start them properly, e.g. from a systemd unit. – Michael Hampton Oct 30 '18 at 15:57
  • @MichaelHampton the reason I want to run it on screen is because I want to be able to see the output on screen without having to use log files – Arya Oct 30 '18 at 19:36
  • Don't do that. You need to learn how to use logs to see the output. Using screen means you actually can't see logs because they aren't saved anywhere. – Michael Hampton Oct 30 '18 at 20:00
0

It's possible your distro, or your implementation of cron, doesn't support @reboot at all, or fully, or for all users. It's a tricky one.

screen might not be a good way to launch a service either, but either way, I'd recommend an alternative to cron for this. This tutorial covers initialising services at boot across a few different system configurations, and might be what you need.

  • Can you please check the edited section of my question please – Arya Oct 30 '18 at 16:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.