TECH

175 Moonlight Home

Connected Packet



HowTO: Auto-start LinBPQ using Systemd and a Non-root User


This methodology should work in current versions of Debian and Ubuntu, e.g. Stretch, Buster, 18.04 and 20.04, and it should work in a Linux computer or a Raspberry Pi. Yours Truly is using this configuration to auto-start pilinbpq in Ubuntu 20.04 on an Odroid XU4.

This setup uses screen, so first install screen if not already installed:

sudo apt install screen

Systemd generally works well for auto-starting applications upon boot, but it starts them using the root user by default.  The objective here is to autostart linbpq or pilinbpq using a non-root user.

Create a new text file in the /etc/systemd/system directory named "bpq.service" using your favorite editor. For example, to create it using the nano editor, issue this command:


sudo nano bpq.service

Below is an example of the contents of the text file, bpq.service.

[Unit]
Description=BPQ
After=network.target

[Service]
Type=forking
User=odroid
Group=odroid
WorkingDirectory=/home/odroid/BPQ
ExecStart=/usr/bin/screen -S bpq -d -m /home/odroid/BPQ/pilinbpq
SyslogIdentifier=BPQ

[Install]
WantedBy=multi-user.target


Unless you're using an odroid, you will need to edit the User and Group names to match the applicable username for your installation.  Also if linbpq or pilinbpq is not located in /home/odroid/BPQ, change the WorkingDirectory above to the actual location. Then on the next line, change the path from /home/odroid/BPQ to the correct path. Also if the executable file you are running is named "linbpq" not "pilinbpq", change that in the ExecStart line as well.

Once your bpq.service file is created and edited to match your configuration, issue the following command: (If you make any tweaks to the service file later, re-issue this command.)


sudo systemctl daemon-reload

Now it's time to test your new systemd service. Make sure BPQ is not running, then issue the following command:

sudo systemctl start bpq

BPQ will be started in a screen session.  To view the BPQ window, issue this command:

screen -r bpq

To "detach" the screen session, issue "Ctrl-a" then "d".  You can also just close the terminal window.  Because BPQ is running in screen it will keep right on running if you close the window.  Screen works fine in headless operation using SSH for remote access.

To have BPQ autostart upon boot, issue the following command:

sudo systemctl enable bpq

Another consideration - when running linbpq or pilinbpq as a non-root user, don't forget to issue the setcap command - see the link below:

https://www.cantab.net/users/john.wiseman/Documents/InstallingLINBPQ.htm





TECH

175 Moonlight Home

Connected Packet