Score:0

Custom systemd unit fails to start gnu screen and fork to background

na flag

I am trying to make systemd unit that starts a script inside GNU screen headlessly. I did base my work here on a couple of questions some had that were related. I also tested the ExecStart line in a shell as the user it should start for, and it works.

Here is the redacted systemd unit file I created and placed in /usr/lib/systemd/system/devredacted.service...

[Unit]
Description=redacted development site inside screen
After=network-online.target

[Service]
Type=forking
Restart=on-failure
RestartSec=3
User=dev
Group=dev
ExecStart=/usr/bin/screen -L -dmS redacted-dev /home/dev/run.sh

When this is started the process does not appear when I look for it using ps aux | grep screen and when I check the status, I see this...

Oct 16 05:45:30 funbox systemd[1]: Starting devredacted.service - redacted development site inside screen...
Oct 16 05:45:30 funbox systemd[1]: Started devredacted.service - redacted development site inside screen.
Oct 16 05:45:30 funbox systemd[1]: devredacted.service: Deactivated successfully.

I tested this as the user this systemd unit user, which has an interactive shell, and the command executed by the unit file clearly works...

$ /usr/bin/screen -L -dmS redacted-dev /home/dev/run.sh
$ screen -ls
There is a screen on:
        31790.redacted-dev        (Detached)
1 Socket in /run/screen/S-dev.
iBug avatar
um flag
`Type=oneshot` might be a better option for these "session manager"-like programs (screen, tmux etc.)
Score:0
na flag

I almost wanted to delete this but I thought leaving it here would help people looking for help in a similar situation.

The problem was actually in my script run.sh which uses a path to an executable inside the home directory for the user dev, which it runs as. When testing this I was already in /home/dev but when using systemd it was not. This meant my script would exit and GNU screen would close.

The solution was as simple as setting the working directory...

[Service]
WorkingDirectory=/home/dev

This has fixed the problem and everything is fine now.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.