0

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.

Arya
  • 121
  • 11
  • 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

1 Answers1

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.

Johnny
  • 170
  • 7