SW_AutoStart - fablab-wue/piTelex GitHub Wiki
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.
(recommended; tested on Debian buster, bullseye, bookworm andt trixie):
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 withpias normal user, the defaults should be OK. If necessary use a text editor of your choice (e.g.nano) to editpitelex.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
piand 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.serviceStart piTelex service now (or reboot the system to start the service at boot time):
$ sudo systemctl daemon-reload && sudo systemctl start pitelex.serviceTest 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 telexshould 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.pyIf 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.serviceTo connect to your running piTelex service, call byobu from the command line:
$ byobu-screenThis 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.
Important
Remember to adapt the values for user and directory if user <> 'pi' and piTelex directory <> '/home/pi/piTelex'
-
rc.local:
- Edit
telex.json: disable modulescreento avoid I/O problems
-
Edit
/etc/rc.localas superuser with e.g.sudo nano /etc/rc.local -
Before
exit 0at end insert the linecd /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 telexshould give you something like24189 pts/1 S 0:00 sudo -u pi ./telex.py 24190 pts/1 Sl 0:10 /usr/bin/python3 ./telex.py
- Edit
-
crontab:
-
Edit
telex.json: disable modulescreento avoid I/O problems -
Edit the system crontab file as superuser with
sudo crontab -eand 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.