SW_AutoStart - fablab-wue/piTelex GitHub Wiki

Set up automatic start of telex service at boot:

When your piTelex is finally configured to your needs and everything is working fine, you might want to start pitelex.service automagically at boot time.

via systemd and byobu

(recommended; tested on Debian buster, bullseye and bookworm):

This method installs piTelex as a system service that can be managed with systemctl like any other system service like e.g. cups or samba. Furthermore it provides the possibility to hook up to a running piTelex session using byobu for debugging purposes or just to use piTelex' console screen. The installation part is somewhat more complex than with the other methods (see below), but the usability is more convenient with systemd. Here we go:

  • Make sure byobu and screen are installed:

    $ sudo apt install screen byobu
  • Change to the piTelex subdirectory utils/systemd.

    $ pwd
    /home/pi/piTelex
    $ cd utils/systemd
  • Check the contents of the service file pitelex.service. This is a text file which contains some definitions for the service. For a standard Raspberry Pi OS installation with pi as normal user, the defaults should be OK. If necessary use a text editor of your choice (e.g. nano) to edit pitelex.service

    $ nano pitelex.service

    and ONLY configure in section [Service] the defintions:

    User=pi
    Group=pi
    WorkingDirectory=/home/pi/piTelex/
    

    [!IMPORTANT] Values for paths and usernames are correct for standard installations under RaspBerry Pi OS and user pi and must be adapted for non-standard installations.

  • Install the service file:

    $ sudo cp pitelex.service /lib/systemd/system/
  • Enable the piTelex service to be started on boot:

    $ sudo systemctl enable pitelex.service

    Start piTelex service now (or reboot the system to start the service at boot time):

    $ sudo systemctl daemon-reload && sudo systemctl start pitelex.service

    Test if the service is running:

    $ systemctl status pitelex.service

    should list piTelex as active (running).

    $ byobu-screen -list 

    should show the piTelex session as detached.

Note

The suspicious can furthermore check if piTelex is running as follows:

$ ps x | grep telex

should give you something like

400 ?        Ss    16:01 SCREEN -T screen -c   /usr/share/byobu/profiles/byoburc -d -m -S piTelex   /home/pi/piTelex/telex.py
401 pts/0    Ssl+ 3658:15 /usr/bin/python3 /home/pi/piTelex/telex.py
Finally...

If everything is fine, piTelex is now running transparently in the background. You can start, restart and stop piTelex using systemd service commands:

$ sudo systemctl [start|stop|restart|status] pitelex.service

To connect to your running piTelex service, call byobu from the command line:

$ byobu-screen

This will connect you to the screen of piTelex just as if you had started it from command line. You can detach from the session using F6. This returns you to the shell, but piTelex will continue to run.

Tip

Inside byobu, piTelex can also be terminated using CTRL-C, CTRL-C or <ESC>exit<Enter>. The byobu session will also quit. systemd will restart everything after 10 s.

Alternative Methods:

Important

Remember to adapt the values for user and directory if user <> 'pi' and piTelex directory <> '/home/pi/piTelex'

  1. rc.local:

    • Edit telex.json: disable module screen to avoid I/O problems
    • Edit /etc/rc.local as superuser with e.g. sudo nano /etc/rc.local

    • Before exit 0 at end insert the line cd /home/pi/piTelex && sudo -u pi ./telex.py 2>&1 &

    • reboot the system: sudo shutdown -r now

    • Check if piTelex is running: ps ax | grep telex should give you something like

         24189 pts/1    S      0:00 sudo -u pi ./telex.py
         24190 pts/1    Sl     0:10 /usr/bin/python3 ./telex.py
      
  2. crontab:

    • Edit telex.json: disable module screen to avoid I/O problems

    • Edit the system crontab file as superuser with sudo crontab -e and at the bottom of the file add the line

      @reboot (cd /home/pi/piTelex && sudo -u pi ./telex.py  2>&1 &)
      

      Note: Depending on your cron version, the exact syntax may vary; see the corresponding man page

    • Reboot the system: sudo shutdown -r now

    • Check if piTelex is running: (see above)

Important

Values for paths and usernames are correct for standard installations under RaspBerry Pi OS and user pi and must be adapted for non-standard installations.


⚠️ **GitHub.com Fallback** ⚠️