Configure monit for pppd and lora-packet-forwarder

NOTE: With regards to ppp connections and lora-packet-forwarder, carriers can log off PPP at any time. Monit reconnects PPP and restarts lora-packet-forwarder for you automatically.

Install monit

If you have an internet connection:

# opkg install monit
Package monit (5.12.2-r1.0) installed in root is up to date.

Otherwise download monit, and install it on your system:

# opkg install monit_5.12.2-r1.0_arm926ejste.ipk

General configuration of monit

Set up monit to start on boot:

# sed -i 's/="no"/="yes"/' /etc/default/monit
# grep ENA monit 
ENABLED="yes"

Configure status monitor

You do not need to set up the addresses for monit, if you do not wish to monitor anything manually. This may be helpful in testing and setting up monit. Operating a web browser on Conduit® is not supported. Using localhost is not helpful without some kind of IP forwarding (not covered here). In file /etc/monitrc, you  configure a userid and password for monit:

# cd /etc
# sed -i 's/admin:monit/admin:mtech2205/' monitrc
# grep mtech monitrc
    allow admin:mtech2205      # require user 'admin' with password 'monit'

Now listen on all local addresses (or it could be the address range of the PC’s running a web browser):

# sed -i 's?allow localhost?allow 0.0.0.0/0.0.0.0?' monitrc
# grep -B4  admin monitrc
#
set httpd port 2812 and
    use address localhost  # only accept connection from localhost
    allow 0.0.0.0/0.0.0.0        # allow localhost to connect to the server and
    allow admin:mtech2205      # require user 'admin' with password 'monit'

Now set the local address for the bind. This could be a fixed address used by the device:

# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:08:00:4a:1a:30 brd ff:ff:ff:ff:ff:ff
    inet 172.16.1.130/16 brd 172.16.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::208:ff:fe4a:1a30/64 scope link 
       valid_lft forever preferred_lft forever
#

Use the 172.16.1.130 above or the address 0.0.0.0 if there are multiple home addresses (for instance ethernet and ppp).

# sed -i 's/use address localhost/use address 0.0.0.0/' monitrc 
# grep -B4  admin monitrc
#
set httpd port 2812 and
    use address 0.0.0.0  # only accept connection from localhost
    0.0.0.0/0.0.0.0        # allow localhost to connect to the server and
    allow admin:mtech2205      # require user 'admin' with password 'monit'

This may be tested with monit -t:

# monit -t
Cannot translate 'jaktest1' to FQDN name -- Name or service not known
Control file syntax OK

The error occurs because the hostname is not in the /etc/hosts file. Add the hostname as follows (substituting your own IP address):

# echo 172.16.1.130  $(uname -n) >>/etc/hosts

Now create the configuration for the services. To make it easier, start a service to be monitored.

Stop and Start Monit

# /etc/init.d/monit stop
Stopping monit
No daemon process found
# /etc/init.d/monit start
Starting monit
Starting Monit 5.12.2 daemon with http interface at [0.0.0.0]:2812

Verify Monit is Running

Connect to the device by using a browser. Use the following:

http://[Conduit IP address]:2812

In this example:

http://172.16.1.130:2812/

At the login screen, enter the userid and password that was configured earlier in file monitrc.

Note that you are logged in until you exit the browser. There is no logout. This is what you see after you log in.

Configure the status monitor

Normally you will configure the status monitor based on a PID file found in the /run directory. For ppp there are two identical pid files. You may create the configuration file with an editor of your choice.

# cd /run
# ls *ppp*.pid
ppp-ppp0.pid  ppp0.pid

Configure ppp as follows:

# cd /etc/monit.d
# cat >ppp
check process ppp0 with pidfile /run/ppp0.pid
program start = "/etc/init.d/ppp start"
program stop = "/etc/init.d/ppp stop"
<ctrl-d>
# monit -t
Control file syntax OK

To set up lora-packet-forwarder:

# cd /run/lora
# ls
1                       lora-network-server.db  lora-pkt-fwd-1.pid

We must now use the packet forwarder PID in the monit configuration file:

# cd /etc/monit.d
# cat >lora-packet-forwarder
check process lora-pkt-fwd-1 with pidfile /run/lora/lora-pkt-fwd-1.pid
program start = "/etc/init.d/lora-packet-forwarder start"
program stop = "/etc/init.d/lora-packet-forwarder stop"
<ctrl-d>
# monit -t                                                                                                                                                                    
Control file syntax OK
Now restart monit
# /etc/init.d/monit stop
Stopping monit
Monit daemon with pid [730] killed
# /etc/init.d/monit start
Starting monit
Starting Monit 5.12.2 daemon with http interface at [0.0.0.0]:2812

Check status from a web browser

Use the following:

http://[Conduit IP addreess]:2812

Here is an example monitor screen:

Example /var/log/messages after PPP failure and Restart

Sep 12 08:05:01 jaktest1 authpriv.info CROND[1636]: pam_unix(crond:session): session closed for user root                                                            
Sep 12 08:09:56 jaktest1 daemon.info pppd[1590]: Hangup (SIGHUP)                                                                                                     
Sep 12 08:09:56 jaktest1 daemon.notice pppd[1590]: Modem hangup                                                                                                      
Sep 12 08:09:56 jaktest1 daemon.info pppd[1590]: Connect time 60.7 minutes.                                                                                          
Sep 12 08:09:56 jaktest1 daemon.info pppd[1590]: Sent 0 bytes, received 0 bytes.                                                                                     
Sep 12 08:09:56 jaktest1 daemon.notice pppd[1590]: restoring old default route to eth0 [172.16.0.1]                                                                  
Sep 12 08:09:56 jaktest1 daemon.notice pppd[1590]: Connection terminated.                                                                                            
Sep 12 08:09:56 jaktest1 daemon.info pppd[1590]: Exit.                                                                                                               
Sep 12 08:09:58 jaktest1 daemon.info ntpd[787]: Deleting interface #18 ppp0, 100.179.160.4#123, interface stats: received=0, sent=0, dropped=0, active_time=3638 secs
Sep 12 08:09:58 jaktest1 daemon.info ntpd[787]: peers refreshed                                                     
Sep 12 08:10:00 jaktest1 daemon.err monit[743]: 'ppp0' process is not running                                       
Sep 12 08:10:00 jaktest1 daemon.info monit[743]: 'ppp0' trying to restart                                           
Sep 12 08:10:00 jaktest1 daemon.info monit[743]: 'ppp0' start: /etc/init.d/ppp                                      
Sep 12 08:10:00 jaktest1 user.notice root: timeout is 60                                                            
Sep 12 08:10:00 jaktest1 user.notice root: Starting up PPP link: pppd                                               
Sep 12 08:10:00 jaktest1 user.notice root: ppp_on_boot                                                              
Sep 12 08:10:00 jaktest1 daemon.notice pppd[1657]: pppd 2.4.7 started by root, uid 0