Bmavinga300
Posts: 2
Joined: Mon Apr 05, 2021 10:15 pm

Problems with systemd

Thu Apr 15, 2021 1:13 pm

So I was trying to create a .service file in my systemd to auto start a dual channel packet forwarder file.
I rebooted the system and nothing seemed to have happened, After trying for some time i decided to delete the file altogether and
continue on with the project without doing a auto-start.

I tried to run my gateway manually as you can see below but it wouldnt fully run. Its supposed to connect to the TTN servers but it doesnt anymore :( and i didn't know what to make of it.

pi@raspberrypi-B:~ $ cd dual_chan_pkt_fwd
pi@raspberrypi-B:~/dual_chan_pkt_fwd $ sudo ./dual_chan_pkt_fwd
server: .address = router.eu.staging.thethings.network; .port = 1700; .enable = 1
server: .address = router.eu.thethings.network; .port = 1700; .enable = 0
Gateway Configuration
your name (a@b.c)
Dual channel pkt forwarder
Latitude=0.00000000
Longitude=0.00000000
Altitude=10
Interface: eth0
Trying to detect module CE0 with NSS=6 DIO0=7 Reset=0 Led1=unused
Transceiver version 0x00
Unrecognized transceiver: Success

I did a systemctl status dual_chan_pkt_fwd.service and i got the output below.

pi@raspberrypi-B:~ $ systemctl status dual_chan_pkt_fwd
● dual_chan_pkt_fwd.service - Lora Packet Forwarder
Loaded: loaded (/lib/systemd/system/dual_chan_pkt_fwd.service; enabled; vendo
Active: activating (auto-restart) (Result: exit-code) since Thu 2021-04-15 13
Process: 1033 ExecStart=/home/pi/dual_chan_pkt_fwd/dual_chan_pkt_fwd (code=exi
Main PID: 1033 (code=exited, status=1/FAILURE)

Apr 15 13:59:18 raspberrypi-B systemd[1]: dual_chan_pkt_fwd.service: Main proc
Apr 15 13:59:18 raspberrypi-B systemd[1]: dual_chan_pkt_fwd.service: Failed wi
lines 1-8/8 (END)...skipping...
● dual_chan_pkt_fwd.service - Lora Packet Forwarder
Loaded: loaded (/lib/systemd/system/dual_chan_pkt_fwd.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Thu 2021-04-15 13:59:18 IST; 1s ago
Process: 1033 ExecStart=/home/pi/dual_chan_pkt_fwd/dual_chan_pkt_fwd (code=exited, status=1/FAILURE)
Main PID: 1033 (code=exited, status=1/FAILURE)

Apr 15 13:59:18 raspberrypi-B systemd[1]: dual_chan_pkt_fwd.service: Main process exited, code=exite
Apr 15 13:59:18 raspberrypi-B systemd[1]: dual_chan_pkt_fwd.service: Failed with result 'exit-code'.
~
I then deleted the .service file with the command sudo rm /lib/systemd/system/dual_chan_pkt_fwd.service
sudo systemctl daemon-reload

The service file was gone and I uninstalled the gateway file then reinstalled it again but it hasn't worked ever since and I don't know why! Maybe I messed around too much with systemd and ruined the whole thing? I don't know I'm very new to this.

If you know why my gateway isn't working please let me know :) and I also want to know if systemd resides in the pi device or is it in the SD card because i have ordered a new SD card to install OS onto it to try fix this issue. Please let me know your thoughts on this also.

deepo
Posts: 771
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: Problems with systemd

Thu Apr 15, 2021 1:30 pm

A service file needs to be enabled and started before your service works again.

What happens when you do this again, after putting the service file back in place?

Code: Select all

pi@raspberrypi-B:~ $ systemctl status dual_chan_pkt_fwd
If the service is disabled then:

Code: Select all

pi@raspberrypi-B:~ $ sudo systemctl enable dual_chan_pkt_fwd
pi@raspberrypi-B:~ $ sudo systemctl start dual_chan_pkt_fwd
Then your service should run - check again with:

Code: Select all

pi@raspberrypi-B:~ $ systemctl status dual_chan_pkt_fwd

bls
Posts: 1346
Joined: Mon Oct 22, 2018 11:25 pm
Location: Seattle, WA

Re: Problems with systemd

Thu Apr 15, 2021 1:46 pm

In general, you should put .service files that you create into /etc/systemd/system, rather than /lib/systemd/system, which is typically used for packages that are installed by the system.

systemd searches for .service files first in /etc/systemd/system, then in /lib/systemd/system. One nice feature of this is that you can copy the system-provided .service file into /etc/systemd/system, modify it, and it will be used instead of the one in /lib/systemd/system, should you need to do so.

systemd comes with RasPiOS (and virtually all Linux distros). It's not part of the hardware.

I've found that the best way to get a program running with systemd is to
  • build a script in /usr/local/bin that starts whatever it is you want to run
  • Get that script working on the command line with 'sudo /usr/local/bin/myscript'
  • Start the script in your .service file in /etc/systemd/system
Depending on what your program does, you may need to futz around with the .service file to properly stop the service when you issue a 'sudo systemctl stop myservice' command. Once start and stop are working, you can enable the service to start automatically with 'sudo systemctl enable myservice'
Pi tools:
Quickly and easily build customized-just-for-you SD Cards: https://github.com/gitbls/sdm
Easily run your network's DHCP/DNS on a Pi: https://github.com/gitbls/ndm
Easy strongSwan VPN installer/manager: https://github.com/gitbls/pistrong
Lightweight Virtual VNC Config: https://github.com/gitbls/RPiVNCHowTo

cbad536
Posts: 3
Joined: Fri Mar 12, 2021 4:31 pm

Re: Problems with systemd

Mon Apr 19, 2021 5:43 pm

Hi Team, I'm having a slightly similar problem,

I'm trying to use systemd and systemctl to automatically open a webpage, my Grafana dashboard.

Code: Select all

  GNU nano 3.2                               /etc/systemd/system/showgrafana.service                                         

[Unit]
showgrafana

[Sevice]
ExecStart=chromium-browser -display 192.168.1.43:3000

When I try to run with systemctl, I get:

Code: Select all

pi@Pimonitor:~ $ systemctl enable --now showgrafana.service
Failed to enable unit: File showgrafana.service: Invalid argument
I feel like I'm superclose...
CB

User avatar
DougieLawson
Posts: 41180
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Problems with systemd

Mon Apr 19, 2021 5:58 pm

Try using

Code: Select all

--display 192.168.1.43:3000
with two dashes not one.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

bls
Posts: 1346
Joined: Mon Oct 22, 2018 11:25 pm
Location: Seattle, WA

Re: Problems with systemd

Mon Apr 19, 2021 6:32 pm

Also, your [Unit] section is wrong. "showgrafana" is not a valid systemd option. Have a look at some of the other *.service files in /lib/systemd/system for examples. Google/Bing/whatever for systemd.service for the details.
Pi tools:
Quickly and easily build customized-just-for-you SD Cards: https://github.com/gitbls/sdm
Easily run your network's DHCP/DNS on a Pi: https://github.com/gitbls/ndm
Easy strongSwan VPN installer/manager: https://github.com/gitbls/pistrong
Lightweight Virtual VNC Config: https://github.com/gitbls/RPiVNCHowTo

cbad536
Posts: 3
Joined: Fri Mar 12, 2021 4:31 pm

Re: Problems with systemd

Mon Apr 19, 2021 6:53 pm

bls wrote:
Mon Apr 19, 2021 6:32 pm
Also, your [Unit] section is wrong. "showgrafana" is not a valid systemd option. Have a look at some of the other *.service files in /lib/systemd/system for examples. Google/Bing/whatever for systemd.service for the details.
Ahh, that did something. I added 'description=' before show grafana. Now systemctl has a whole bunch more complaints about missing parameters. I'll look around the other .service files, see if I can cut and paste my way into success.

Return to “Raspberry Pi OS”