I want to create a crontab entry so that it starts screen, starts a gameserver and detaches. This is for in case the server is rebooted and I want it to automatically start this for me.
0 0 0 0 0 (command)
should run upon startup.
It runs a shell file located at ~/cube/server.sh
Something like this should work. This example spawns a screen and runs "top":
In your crontab, as indicated, you'd want to do something like this:
Of course, if the game server requires a "normal" environment set, you can get closer by:
This should be sufficient...run
Then enter:
Just for completeness' sake, it's also possible to use tmux for the purpose instead of
screen
(see this link for a comparison):It needs to be noted that simply using screen -dmS SessionNameHere someCommand is NOT enough. In many envs (IE: Ubuntu 18.x) you also have to give the tmp dir or you cant re-attach to the running screen, you wont even be able to list them. The CORRECT way to run screen in crontab is like this:
So if you cant connect to a session started by cron (I had this issue with Ubuntu 18), find out what screen is using for a tmp dir, and put that in the crontab entry. You can do that with "echo $SCREENDIR"
I had a similar situation, but due to other unreasonable restrictions, I could not use crontab. I actually had inittab call screen. ( replaced some names to obscure information):
In 'file.screenrc' is where I setup a few options:
This way it started on boot, and if the program died or screen closed it would re spawn. It may not have been considered conventional, but I had to work a round a few odd environment requirements. If we needed to take it down though, we would have to comment that line out, and kill session. Then when ready to bring it back up, uncomment, and init q.