OpenBCM start file and Systemd

FYI, In the top menu you can choose OpenBCM. This page contains all references to items about openBCM.

I have found a file to start OpenBCM. We will inplant this script and start using it.

We are going to create a user who does not have shell and no home directory. This makes it impossible to log in as this user. This gives a bit of security.

sudo useradd -r -s /bin/false bcm

The above command creates a user “bcm” as a system user.

Copy the directory of bcm to /usr/local

sudo cp -r bcm /usr/local/

Now we have to make the user “bcm” owner of the directory and files /usr/local/bcm

sudo chown -R bcm:bcm /usr/local/bcm

See if everything is in okay.

pd9q@pd9q:/usr/local/bcm $ ls -l
total 1620
-rwxr-xr-x 1 bcm bcm 890996 Nov 15 15:16 bcm
-rwxr-xr-x 1 bcm bcm  15673 Nov 16 06:57 bct.rpi
-rw-r--r-- 1 bcm bcm 262144 Nov 15 16:12 bidh2.bcm
-rw-r--r-- 1 bcm bcm     36 Nov 15 21:08 bids3.bcm
-rw-r--r-- 1 bcm bcm    178 Nov 17 08:34 boardinf.bcm
-rw-r--r-- 1 bcm bcm     48 Nov 17 06:51 bulletin.bak
-rw-r--r-- 1 bcm bcm    182 Nov 17 08:34 bulletin.bcm
-rw-r--r-- 1 bcm bcm      0 Nov 15 21:02 check.bcm
-rw-r--r-- 1 bcm bcm      0 Nov 15 21:02 checknum.bcm
-rw-r--r-- 1 bcm bcm    612 Nov 15 16:12 crontab.bcm
drwxr-xr-x 6 bcm bcm   4096 Nov 15 16:12 fwd
-rw-r--r-- 1 bcm bcm     66 Nov 15 16:12 fwd.bcm
-rw-r--r-- 1 bcm bcm   2048 Nov 17 13:36 hadr4.bcm
-rw-r--r-- 1 bcm bcm 131072 Nov 15 20:20 hadrhash.bcm
drwxr-xr-x 2 bcm bcm   4096 Nov 17 10:34 http
drwxr-xr-x 2 bcm bcm   4096 Nov 15 20:20 info
-rw-r--r-- 1 bcm bcm   1519 Nov 17 13:36 init.bak
-rw-r--r-- 1 bcm bcm   1517 Nov 17 13:42 init.bcm
-rw-r--r-- 1 bcm bcm    382 Nov 15 16:12 init.l2
drwxr-xr-x 2 bcm bcm   4096 Nov 17 10:47 log
drwxr-xr-x 2 bcm bcm   4096 Nov 16 10:04 msg
-rw-r--r-- 1 bcm bcm     66 Nov 15 20:28 rhosts.bcm
-rw-r--r-- 1 bcm bcm    403 Nov 15 16:12 speech.bcm
drwxr-xr-x 2 bcm bcm   4096 Nov 17 10:37 srv
drwxr-xr-x 2 bcm bcm   4096 Nov 15 16:12 temp
drwxr-xr-x 2 bcm bcm   4096 Nov 17 10:47 trace
drwxr-xr-x 2 bcm bcm   4096 Nov 15 20:20 user
-rw-r--r-- 1 bcm bcm 262144 Nov 15 20:47 userh2.bcm
-rw-r--r-- 1 bcm bcm      0 Nov 15 16:12 users4.bak
-rw-r--r-- 1 bcm bcm   1920 Nov 17 12:22 users4.bcm
pd9q@pd9q:/usr/local/bcm $

Now create the startfile.

sudo touch startbcm

Edit the startbcm file

sudo nano startbcm

Here is the start file.

#!/bin/sh
#
# Startup script for BayCom-Mailbox
#
sleep 1
BCMHOME=/usr/local/bcm
export BCMHOME
export TZ=GMT+1GMT
cd $BCMHOME
PATH=/bin:/usr/bin:/usr/local/bin:/usr/local/bcm:/usr/local/bcm/runutils
export PATH
#
# remove comment if necessary!
# source .bash_profile
#
# check if somebody wants to install a new version
if [ -f bcm_new ]
then
  mv -f bcm bcm_old
  mv -f bcm_new bcm
  chmod 777 bcm
fi
#
# start bcm as user "bcm"
# redirect tracer outputs to system console
#
if [ -f nobcm ]
then
  echo "BCM execution stopped. Remove nobcm for continue."
  sleep 5
else
  su bcm -s $BCMHOME/bcm >/dev/tty3
fi
#
# wait some time to release network bindings before respawning
#
sleep 4

Save the file, become owner, and set execute rights

sudo chown bcm:bcm startbcm
sudo chmod 755 startbcm

Now it`s time for Systemd.

Go to the directory /etc/systemd/system and “sudo nano bcm.service”

sudo nano bcm.service

Copy past

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

[Service]
Type=simple
Restart=always
RestartSec=5
ExecStart=/bin/bash /usr/local/bcm/startbcm
WorkingDirectory=/usr/local/bcm

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

Save the file

sudo systemctl enable bcm.service
sudo systemctl daemon-reload
sudo systemctl start bcm.service

Let ‘s check if the service is running.

sudo systemctl status bcm.service
pd9q@pd9q:/etc/systemd/system $ sudo systemctl status bcm.service
● bcm.service - OpenBCM Daemon
   Loaded: loaded (/etc/systemd/system/bcm.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2018-11-18 07:58:49 UTC; 45min ago
 Main PID: 25944 (bash)
   CGroup: /system.slice/bcm.service
           └─25944 /bin/bash /usr/local/bcm/startbcm

Nov 18 07:58:49 pd9q.packet-radio.net systemd[1]: Started OpenBCM Daemon.
Nov 18 07:58:50 pd9q.packet-radio.net su[25949]: Successful su for bcm by root
Nov 18 07:58:50 pd9q.packet-radio.net su[25949]: + ??? root:bcm
Nov 18 07:58:50 pd9q.packet-radio.net su[25949]: pam_unix(su:session): session opened for user bcm by (uid=0)
pd9q@pd9q:/etc/systemd/system $
pd9q@pd9q:/etc/systemd/system $ ps ax
<snip>
25944 ?        Ss     0:00 /bin/bash /usr/local/bcm/startbcm
25949 ?        S      0:00 su bcm -s /usr/local/bcm/bcm
25953 ?        Ss     0:00 /lib/systemd/systemd --user
25956 ?        S      0:00 (sd-pam)
25971 ?        S      0:09 bcm
<snip>
pd9q@pd9q:/etc/systemd/system $ telnet localhost 4719
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.


OpenBCM-Mailbox V1.08-3-g9b42 (Linux)

PI8LAP login:

I think we’re ready to rumble.

One last note.

In the start file you see the line.

su bcm -s $BCMHOME/bcm >/dev/tty3

Here, reference is made to /dev/tty3. I use the program “conspy” to watch on /dev/tty3 how the program runs.

sudo apt-get install conspy
sudo conspy 3
OpenBCM V1.08-3-g9b42 (Linux)(c) GNU GPL 1992-2013 F. Radlherr, DL8MBT et al.
OpenBCM is maintained by Markus Baumann, DH8YMB
18.11.18 07:58:50z SYSTEM: #R working dir: '/usr/local/bcm'
18.11.18 07:58:50z SYSTEM: #R l1axip: 127.0.0.1 rxport=4866 txport=4867
18.11.18 07:58:50z SYSTEM: #R l1axip: initialised to channel 0
18.11.18 07:58:50z SYSTEM: #L Start: V1.08-3-g9b42 Linux mem 880768kB hd 11912MB
18.11.18 07:58:50z SYSTEM: #R init_tnc: 200 ports
18.11.18 07:58:50z SYSTEM: #R ax25k_init: Kernel AX25 disabled
18.11.18 07:58:50z SYSTEM: #R initfwdlist: 0 partners, 0 destinations
18.11.18 07:58:50z SYSTEM: #R readtree: 12 bulletins
18.11.18 07:58:50z SYSTEM: #R telnetd: initialised to port 4719
18.11.18 07:58:50z SYSTEM: #R httpd: initialised to port 8080
18.11.18 07:58:50z SYSTEM: #R ftpd: initialised to port 8021
18.11.18 07:58:50z SYSTEM: #R sendmail: initialised to port 8025
18.11.18 07:58:50z SYSTEM: #R popper: initialised to port 8110
18.11.18 07:58:50z SYSTEM: #R nntpd: initialised to port 8119
18.11.18 07:58:50z SYSTEM: #R radiod: radio connectivity disabled
18.11.18 07:58:50z SYSTEM: #R serv: initialised to port 8123
18.11.18 07:58:51z SYSTEM: #R mbcron: started

To escape conspy hit “esc” a couple of times.