Start Jnos with Systemd

# Starting Jnos at boot, and restart when fail
# Jnos is running in the background

cd /lib/systemd/system
sudo nano jnos.service

Add to the file

[Unit]
Description=Jnos Daemon
After=network.target
After=sound.target
After=syslog.target

[Service]
Type=simple
Restart=always
RestartSec=5
ExecStart=/bin/bash /home/pd9q/jnos/startnos
WorkingDirectory=/home/pd9q/jnos

[Install]
WantedBy=multi-user.target
Alias=jnos.service

save

sudo systemctl enable jnos.service

startnos

# Jnos start file
cd /home/pd9q/jnos
sleep 2
rm -f /home/pd9q/jnos/spool/mqueue/*.lck 2> /dev/null
rm -f /home/pd9q/jnos/jnos/spool/mail/*.lck 2> /dev/null
sleep 1
TZ='Europe/Amsterdam'; export TZ
export TERM=linux
exec ./jnos2.0m.1rc -C -wf+b -u3 -fnos.cfg -i  </dev/tty2>/dev/tty2 2>&1

sudo apt-get install conspy
sudo conspy 2

And there is jnos….. Hit a couple off times [esc] to exit conspy

sudo systemctl status jnos

pd9q@packet-jnos:~/jnos/logs $ sudo systemctl status jnos
● jnos.service - Jnos Daemon
Loaded: loaded (/lib/systemd/system/jnos.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2020-02-08 07:36:44 CET; 6h ago
Main PID: 525 (jnos2.0m.1rc)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/jnos.service
└─525 ./jnos2.0m.1rc -C -wf b -u3 -fnos.cfg -i

Feb 08 07:36:44 packet-jnos systemd[1]: Started Jnos Daemon.
pd9q@packet-jnos:~/jnos/logs $

 

Watchdog

I use watchdog to monitor my RPI. Do services go offline or the RPI is not responding, watchdog kicks in and restart the system. Now I also want watchdog to watch my Linbpq. This is possible with watchdog, watchdog looks at a PID file. As far as I know, no PID file is created when starting Linbpq.

Now there is a possibility that when starting Linbpq with systemd a command can be given so that a PID file is created.

This is my linbpq.service file from systemd

pd9q@packet:~ $ sudo cat /etc/systemd/system/linbpq.service
[Unit]
Description=Linbpq Daemon
After=network.target
After=direwolf.target
StartLimitInterval=0

[Service]
Type=simple
Restart=always
RestartSec=5
ExecStartPost=/bin/sh -c "echo $MAINPID > /home/pd9q/linbpq/run/linbpq.pid"
ExecStart=/bin/bash /home/pd9q/linbpq/linbpq.start
WorkingDirectory=/home/pd9q/linbpq

[Install]
WantedBy=multi-user.target
Alias=linbpq.service

This command creates a linbpq.pid file, now it is possible that watchdog monitors linbpq.

ExecStartPost=/bin/sh -c "echo $MAINPID > /home/pd9q/linbpq/run/linbpq.pid"
pd9q@packet:~ $ sudo ls -l /home/pd9q/linbpq/run
-rw-r--r-- 1 root root 4 Oct 14 18:36 linbpq.pid
pd9q@packet:~ $

At the end of my watchdog configuration file (/etc/watchdog.conf) I have added the following line.

# Check if Linbpq is running
pidfile         = /home/pd9q/linbpq/run/linbpq.pid

Take a look at what happens when you stop Linbpq.

sudo systemctl stop linbpq.service

Yes the system is ReBoOtInG (I hoop)

Systemd RestartSec/StartLimitInterval/StartLimitIntervalSec

Systemd

The default delay between executions is 100ms (RestartSec) which causes the rate limit to be reached very fast.

Just using Restart and RestartSec is not enough: systemd services have start rate limiting enabled by default. If service is started more than StartLimitBurst times in StartLimitInterval/StartLimitIntervalSec seconds is it not permitted to start any more.

Add RestartSec=5 in the service section
Add StartLimitInterval=0 in the unit section

[Unit]
Description=Linbpq
After=network.target
StartLimitInterval=0

[Service]
Type=simple
Restart=always
RestartSec=5
ExecStart=/bin/bash /home/pd9q/linbpq/runbpq
WorkingDirectory=/home/pd9q/linbpq

[Install]
WantedBy=multi-user.target
Alias=linbpq.service

Run

systemctl daemon-reload

 

 

DireWolf/Linpq with Systemd.

I have a bad time behind me, I have had a lot of arguments with Systemd to start DireWolf and Linpq when booting πŸ™‚
If you like Systemd, you can read some about it here https://en.wikipedia.org/wiki/Systemd

I want Linbpq to run under /dev/tty2 and DireWolf under /dev/tty3. This is because if I login remotely I can view the monitor from DireWolf with “conspy”. “conspy 3” Hit esc a few times to leave conspy.

Systemd does not want to accept the start line with >/dev/tty3 &

ExecStart=/usr/local/bin/direwolf -c /home/pd9q/direwolf.conf -l /home/pd9q/direwolf.log >/dev/tty3

This upper start line does not work.

So I had to come up with something else for that. So i wrote a start file. “direwolf.start”

cd /usr/local/bin
./direwolf -c /home/pd9q/direwolf.conf -l /home/pd9q/direwolf.log >/dev/tty3

Now i wrote a unit file to start DireWolf on boot.
/etc/systemd/system/direwolf.service

[Unit]
Description=DireWolf Deamon
After=network.target
After=sound.target
After=syslog.target

[Service]
Type=simple
ExecStart=/bin/bash /home/pd9q/linbpq/direwolf.start

[Install]
WantedBy=multi-user.target
Alias=direwolf.service

Now DireWolf is starting very nice on /dev/tty3

pd9q@packet:~ $ systemctl status direwolf.service
● direwolf.service - DireWolf Deamon
   Loaded: loaded (/lib/systemd/system/direwolf.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2018-09-12 10:58:51 UTC; 1h 18min ago
 Main PID: 463 (bash)
   CGroup: /system.slice/direwolf.service
           β”œβ”€463 /bin/bash /home/pd9q/linbpq/direwolf.start
           └─474 ./direwolf -c /home/pd9q/direwolf.conf -l /home/pd9q/direwolf.log

Sep 12 10:58:51 packet systemd[1]: Started DireWolf Deamon.
pd9q@packet:~ $

I had the same problem with Linbpq, which I solved in the same way.

Linbpq start file “runbpq”

cd /home/pd9q/linbpq
sudo ./linbpq  >/dev/tty2

The unit file “linbpq.service”

[Unit]
Description=Linbpq Daemon
After=network.target
After=direwolf.target
StartLimitInterval=0

[Service]
Type=simple
Restart=always
RestartSec=5
ExecStart=/bin/bash /home/pd9q/linbpq/runbpq
WorkingDirectory=/home/pd9q/linbpq

[Install]
WantedBy=multi-user.target
Alias=linbpq.service

Ok, let’s see if it is running

pd9q@packet:~ $ systemctl status linbpq.service
● linbpq.service - Linbpq Daemon
   Loaded: loaded (/lib/systemd/system/linbpq.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2018-09-12 10:58:51 UTC; 1h 23min ago
 Main PID: 464 (bash)
   CGroup: /system.slice/linbpq.service
           β”œβ”€464 /bin/bash /home/pd9q/linbpq/runbpq
           β”œβ”€473 sudo ./linbpq
           └─501 ./linbpq

Sep 12 12:13:36 packet LINBPQ[501]: BPQ32 Heartbeat Buffers 102
Sep 12 12:14:31 packet LINBPQ[501]: BPQ32 Heartbeat Buffers 99
Sep 12 12:15:27 packet LINBPQ[501]: BPQ32 Heartbeat Buffers 102
Sep 12 12:16:22 packet LINBPQ[501]: BPQ32 Heartbeat Buffers 102
Sep 12 12:17:17 packet LINBPQ[501]: BPQ32 Heartbeat Buffers 102
Sep 12 12:18:12 packet LINBPQ[501]: BPQ32 Heartbeat Buffers 100
Sep 12 12:19:07 packet LINBPQ[501]: BPQ32 Heartbeat Buffers 102
Sep 12 12:20:03 packet LINBPQ[501]: BPQ32 Heartbeat Buffers 102
Sep 12 12:20:58 packet LINBPQ[501]: BPQ32 Heartbeat Buffers 102
Sep 12 12:21:53 packet LINBPQ[501]: BPQ32 Heartbeat Buffers 102
pd9q@packet:~ $

Now have a look at /dev/tty2 “conspy 2”

G8BPQ AX25 Packet Switch System Version 6.0.16.30 July 2018
Copyright β–’ 2001-2018 John Wiseman G8BPQ
Current Directory is /home/pd9q/linbpq

Configuration file Preprocessor.
Using Configuration file /home/pd9q/linbpq/bpq32.cfg
Conversion (probably) successful

PORTS 1d9784 LINKS 1dce14 DESTS 1dfc58 ROUTES 1f9c58 L4 1fd058 BUFFERS 22f170

Initialising Port 01     TCPKISS IP 127.0.0.1 Port 8001 Chan A
Initialising Port 02     AXIP
Initialising Port 03     Telnet Server
Initialising Port 04     Loopback

 

Systemd / Systemctl and Linbpq

Update : Okay, i relay dont like systemctl….
apt-get install sysvinitΒ  / apt-get install openbsd-inetd / apt-get purge systemd / reboot

Debian Jessie uses the “new” systemd. No more inittab and inetd.conf. So a unit file must come up for this.

nano /etc/systemd/system/linbpq.service
[Unit]
Description=Linbpq start
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/linbpq/linbpq
WorkingDirectory=/usr/local/linbpq
Restart=always

[Install]
WantedBy=multi-user.target
Alias=linbpq.service
systemctl enable linbpq.service
systemctl daemon-reload
systemctl start linbpq.service

Now let`s check all startup nicely.

systemctl status linbpq.service
root@gw:/etc/systemd/system# systemctl status linbpq.service
● linbpq.service - Linbpq daemon
   Loaded: loaded (/etc/systemd/system/linbpq.service; enabled)
   Active: active (running) since Wed 2017-12-13 07:14:07 CET; 1h 19min ago
 Main PID: 19267 (linbpq)
   CGroup: /system.slice/linbpq.service
           └─19267 /usr/local/linbpq/linbpq

Up and running