ubuntu 18.04 hw2018 systemd screen
Here is how to start a systemd service running attached to a console (inside screen).
User services MUST be enabled before (see this post : custom services).
A simple script
#!/bin/bash
while true
do
echo "$0 pid:$$ ppid:$PPID user:$(id -un) group:$(id -g) parameters:'$@'"
sleep 10
done
Saved in ~/bin/testservice-stdout
, and executable.
The user service
[Unit]
Description=myscript
After=network.target
[Service]
Type=forking
Restart=always
RestartSec=3
ExecStart=/usr/bin/screen -L -dmS testservice-screen %h/bin/testservice-stdout hello inside screen
[Install]
WantedBy=default.target
Saved in ~/.config/systemd/user/testservice-screen.service
Then
systemctl --user daemon-reload && systemctl --user start testservice-screen.service
And connect to screen
:
screen -R testservice-screen
...
/home/pim/bin/testservice-stdout pid:13329 ppid:13328 user:pim group:1000 parameters:'hello inside screen'
/home/pim/bin/testservice-stdout pid:13329 ppid:13328 user:pim group:1000 parameters:'hello inside screen'
...
~~~
Question, remark, bug? Don't hesitate to contact me or report a bug.