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 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
    
  • Look for a subdirectory systemdin the piTelex tree. Change to this directory and check the contents of the service file pitelex.service. Ths is a text file which contains some definitions for the service. For a standard Raspberry Pi OS installation, the defaults should be OK. If necessary use a text editor of your choice to edit pitelex.service to ONLY configure in section [Service] the defintions:

    User=pi
    Group=pi
    WorkingDirectory=/home/pi/piTelex/
    
  • 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
      

If everything is fine, piTelex is now running transparently in the background.

You can now 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 commandline:

     $ byobu-screen

This will connect you to the screen of piTelex just as if you had started it from commandline.

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:

  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
    • At the bottom add the line @reboot (cd /home/pi/piTelex && sudo -u pi ./telex.py 2>&1 &)

      Note: Depending on your crontab 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** ⚠️