I would like to start a python script at startup inside a byobu/tmux session (and create the session if it doesn't exist), so I can attach to it later.
I created a start_script.sh containing the following command:
byobu-tmux new-session -A -s userscript \; rename-window userscript1 \; send-keys "cd /home/username/scripts/ && python userscript1.py" C-m
It works fine when executed manually. I then created a systemd service file
[Unit]
Description=Sensors service
After=multi-user.target
StartLimitIntervalSec=0
[Service]
Type=forking
User=username
ExecStart=/bin/bash /home/username/start_script.sh
RemainAfterExit=yes
[Install]
WantedBy=default.target
However, the service fails with
Jun 21 17:11:39 hostname bash[15061]: open terminal failed: not a terminal
I also tried to put the start_script command after ExecStart=, but starting the service fails with the same error message (just byobu-tmux as command name instead of bash).
Ideally, I'd love to have the python process handled by systemd as a service, so it automatically restart on-failure, but that's not a requirement.