So I want to run screen inside a systemd service so that I can give the process (inside the daemon) commands while it is running. See at the end of the question for examples of what I want be be able to do.
What I currently have:
A java application that is started with
ExecStart=/usr/bin/java -someArguments -jar server.jar
-running as a daemon with user:group set to "server":"server", along with "ProtectSystem=full" and similar hardening arguments. This runs fine, no problems.
However, I want:
The same as above but with it running inside a screen instance. Something like this:
ExecStart=/usr/bin/screen -DmS aServer /usr/bin/java -someArguments -jar server.jar
This latter refuses to start, output from journalctl -xe
tells me: "Failed to execute command: Permission denied". I can however start screen sessions from the same user (server:server) if I do it myself in the terminal (same command as in ExecStart).
I found a solution on the internet that said:
# Uncomment this to fix screen on RHEL 8
ExecStartPre=+/bin/sh -c 'chmod 777 /run/screen'
But I instinctively do not like the 777 part, also I do not understand why it needs to run every time the daemon starts.
What I am basically asking: How do you get screen working inside a systemd daemon? Is the above solution a good idea, or is there a better way?
Examples of what I want to be able to do:
- have a systemd timer that has a
ExecStartPre=/screen -p 0 -S -X eval 'stuff "save-all"\\015'
(or similar) in its sequence. - A sequence of commands during ExecStop like the one above.
- Ability to interact with the process when I manually connect to the Linux server (connecting to the screen instance).