Searched extensively, many questions related but none that I found actually worked.
So I have a shell script which I want to automate via a systemd service. The script:
#!/usr/bin/env bash
SESSION="daemon"
DAEMON_WINDOW="daemon"
CLIENT_WINDOW="client"
tmux new-session -d -s $SESSION
tmux rename-window -t 0 $DAEMON_WINDOW
tmux send-keys -t $DAEMON_WINDOW 'cd $HOME/work/gastd' C-m './gastd' C-m
sleep 30
tmux new-window -t $SESSION:1 -n $CLIENT_WINDOW
tmux send-keys -t $CLIENT_WINDOW 'gast-client' C-m
tmux attach-session -t $SESSION:1
OK this works when run from the shell. Basically it starts the daemon in one window. The daemon inits some stuff, so I have to wait, and after sleeping, I start the second window with the client.
Now when I run as systemd, it actually seems to startup fine, then exits with a failure.
I assume the reason is simple: everything runs through, then the script terminates, so systemd assumes it terminated and exists the service as well - killing the tmux session and windows, which is the real problem.
The goal is to keep the session and windows running forever, unless I run systemctl stop service.
I could just add an endless loop at the end of the script, but that doesn't seem very nice.
Is there a better way?
I tried Type=forking
but that didn't help either, it also crashed in the end for some reason.
Here is my current systemd script:
[Unit]
Description=gast daemon
[Service]
ExecStart=/home/gastuser/start-tmux-session.sh
WorkingDirectory=/home/gastuser/work/gastd
User=gastuser
StandardOutput=file:/home/gastuser/.gast/gast.log
StandardError=file:/home/gastuser/.gast/gast.log
Restart=on-failure
[Install]
WantedBy=multi-user.target
I really searched far and wide, if the question/answer already exists, apologies.