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

Description=Sensors service

ExecStart=/bin/bash /home/username/start_script.sh


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.

  • it appears to me like you need systemd to allocate a terminal to your service; presumably byobu is the one complaining about the lack of a terminal.
    – Jeff Schaller
    Jun 21, 2019 at 18:41

2 Answers 2


Here is what finally worked for me (on Ubuntu 18.04).

The /home/username/start_script.sh (don't forget the chmod +x for that file):

set -x
set -e

byobu list-sessions | grep my-app || byobu new-session -d -s my-app

byobu list-windows -t my-app | grep start-script || byobu new-window -t my-app -n 'start-script'

byobu send-keys -t my-app:start-script "cd /home/username/scripts/ && python userscript1.py" C-m

And the /etc/systemd/system/my-app.start_script.service:

Description=My app start script

ExecStart=/bin/bash -l -c '/home/username/start_script.sh'


Then install it thanks to sudo systemctl enable my-app.start_script.service.

To see the logs of the service: sudo journalctl -u my-app.start_script.service.

Thanks to this answer, this one and this one for the hints.

  • 2
    It didn't work for me out of the box (I could start the service and all would be fine, but it wouldn't work after reboot). However, changing Type=oneshot to Type=forking did the trick for me ! Thanks
    – Julian S.
    Aug 30, 2019 at 19:01
  • I confirm add 'Type=forking' work Dec 18, 2021 at 3:18

Do you have #/bin/bash as the first line in your script? Not sure if that would solve it or not, but that way you can just call your script on the ExecStart entry.

  • note that the script is being called, but is complaining about the lack of a terminal...
    – Jeff Schaller
    Jun 21, 2019 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.