I have a game server that I want to automatically run whenever I start up the physical server. For a while I just used systemd to start the server directly, but this game server has a console that I want to be able to access at runtime. Ideally, I would like to have some sort of setup where a detached screen is created, the program is run, and I can attach the screen when I want to use it. Is that possible and if so, how do I do it?
open crontab edit mode:
crontab works on everything, systemd or not, it's easy to add, and runs your scripts with user privileges automatically.
Add a new line for a screen session:
Code:
@reboot screen -dmS name_of_your_session /home/user/path/to/your/game
Save and exit. You can list your crontab jobs by typing:
Parameters used in startup entry:
-d -m Start screen in detached mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts.
-S adds session name for easier management
After reboot, use
screenie tool (install it) to easily manage screen sessions running in the background:
Once you are in screenie, just type screen number you want to enter, in your case it's 1.
Background screen session allows you to see full output, you can also scroll the terminal by key press combination:
- CTRL+ALT+A Enter Copy mode
- scroll terminal output by using arrow and PgUp PgDown keys
- Esc - exit Copy mode
To detach from screen and go back to screenie menu, press
CTRL + A + D