Check of the services are online

I have written a script that checks whether the services are still running, if not, I will receive an email and can take action. The script writes the data in a file. This file is in /var/www/up and is called up.htm. Now I can view the file via the browser. http://ip-adres/up/up.htm

http://gw.pd2lt.ampr.org/up/up.htm  # Only amprnet

I have add a cronjob for it. The cronjob runs the script every 5 minutes

*/5  *    * * *   root    /usr/local/etc/ax25/ax-up

The output look like this

Here is the script

#!/bin/sh
mail=pd2lt( @ )packet-radio.net;
S1=netromd;
S2=ax25d;
S3=ax25rtd;
S4=flexd;
S5=mheardd;
S6=beacon;
S7=xfbbd;
S8=jnos;
S9=linuxnet;
S10=ax25ipd;
S11=ax25udp;
S12=rstatrxd;
S13=slattach;
S14=socat;
S15=kissnetd;
S16=kissattach;
S17=apache2;

# Remove the old one
rm -f /var/www/up/up.htm
    echo "<h2> Check services on pi1lap/pi8lap</h2>" >> /var/www/up/up.htm
    echo "#########################################<br/>" >> /var/www/up/up.htm
    echo "Services check script v2.0.32<br/>" >> /var/www/up/up.htm
    echo "E-mail : pd2lt@packet-radio.net<br/>" >> /var/www/up/up.htm
    echo "https://packet-radio.net<br/>" >> /var/www/up/up.htm
    echo "#########################################<br/><br/>" >> /var/www/up/up.htm
    echo "Uptime Pi1lap -" `uptime` "<br/>" >> /var/www/up/up.htm
    echo `uname -a` "<br/><br/>" >> /var/www/up/up.htm
# netromd
if P1=$(pgrep $S1)
then
    echo "1. $S1 is up and running, PID is $P1 - Uptime" `ps -o etime= -p "$P1"` "<br/>" >> /var/www/up/up.htm
else
    echo "1. $S1 is not running" | mail -s "$S1 down" $mail
fi
# ax25d
if P2=$(pgrep $S2)
then
    echo "2. $S2 is up and running, PID is $P2 - Uptime" `ps -o etime= -p "$P2"` "<br/>" >> /var/www/up/up.htm
else
    echo "2. $S2 is not running" | mail -s "$S2 down" $mail
fi
# ax25rtd
if P3=$(pgrep $S3)
then
    echo "3. $S3 is up and running, PID is $P3 - Uptime" `ps -o etime= -p "$P3"` "<br/>" >> /var/www/up/up.htm
else
    echo "3. $S3 is not running" | mail -s "$S3 down" $mail
fi
# flexd
if P4=$(pgrep $S4)
then
    echo "4. $S4 is up and running, PID is $P4 - Uptime" `ps -o etime= -p "$P4"` "<br/>" >> /var/www/up/up.htm
else
    echo "4. $S4 is not running" | mail -s "$S4 down" $mail
fi
#mheardd
if P5=$(pgrep $S5)
then
    echo "5. $S5 is up and running, PID is $P5 - Uptime" `ps -o etime= -p "$P5"` "<br/>" >> /var/www/up/up.htm
else
    echo "5. $S5 is not running" | mail -s "$S5 down" $mail
fi
# beacon
if P6=$(pgrep $S6)
then
    echo "6. $S6 is up and running, PID is $P6 <br/>" >> /var/www/up/up.htm
else
    echo "6. $S6 is not running" | mail -s "$S6 down" $mail
fi
# xfbbd
if P7=$(pgrep $S7)
then
    echo "7. $S7 is up and running, PID is $P7 - Uptime" `ps -o etime= -p "$P7"` "<br/>" >> /var/www/up/up.htm
else
    echo "7. $S7 is not running" | mail -s "$S7 down" $mail
fi
# jnos
if P8=$(pgrep $S8)
then
    echo "8. $S8 is up and running, PID is $P8 - Uptime" `ps -o etime= -p "$P8"` "<br/>" >> /var/www/up/up.htm
else
    echo "8. $S8 is not running" | mail -s "$S8 down" $mail
fi
# linuxnet
if P9=$(pgrep $S9)
then
    echo "9. $S9 is up and running, PID is $P9 - Uptime" `ps -o etime= -p "$P9"` "<br/>" >> /var/www/up/up.htm
else
    echo "9. $S9 is not running" | mail -s "$S9 down" $mail
fi
# ax25ipd
if P10=$(pgrep $S10)
then
    echo "10. $S10 is up and running, PID is $P10 - Uptime" `ps -o etime= -p "$P10"` "<br/>" >> /var/www/up/up.htm
else
    echo "10. $S10 is not running" | mail -s "$S10 down" $mail
fi
# ax25udp
if P11=$(pgrep $S11)
then
    echo "11. $S11 is up and running, PID is $P11 - Uptime" `ps -o etime= -p "$P11"` "<br/>" >> /var/www/up/up.htm
else
    echo "11. $S11 is not running" | mail -s "$S11 down" $mail
fi
# rstatrxd
if P12=$(pgrep $S12)
then
    echo "12. $S12 is up and running, PID is $P12 - Uptime" `ps -o etime= -p "$P12"` "<br/>" >> /var/www/up/up.htm
else
    echo "12. $S12 is not running" | mail -s "$S12 down" $mail
fi
# slattach
if P13=$(pgrep $S13)
then
    echo "13. $S13 is up and running, PID is $P13 - Uptime" `ps -o etime= -p "$P13"` "<br/>" >> /var/www/up/up.htm
else
    echo "13. $S13 is not running" | mail -s "$S13 down" $mail
fi
# socat
if P14=$(pgrep $S14)
then
    echo "14. $S14 is up and running, PID is $P14 <br/>" >> /var/www/up/up.htm
else
    echo "14. $S14 is not running" | mail -s "$S14 down" $mail
fi
# kissnetd
if P15=$(pgrep $S15)
then
    echo "15. $S15 is up and running, PID is $P15 <br/>" >> /var/www/up/up.htm
else
    echo "15. $S15 is not running" | mail -s "$S15 down" $mail
fi
# kissattach
if P16=$(pgrep $S16)
then
    echo "16. $S16 is up and running, PID is $P16 <br/>" >> /var/www/up/up.htm
else
    echo "16. $S16 is not running" | mail -s "$S16 down" $mail
fi
# apache2
if P17=$(pgrep $S17)
then
    echo "17. $S17 is up and running, PID is $P17 <br/>" >> /var/www/up/up.htm
else
    echo "17. $S17 is not running" | mail -s "$S17 down" $mail
fi

 

Linux commando “ps ax”

 2604 ?        S      0:00 /usr/bin/perl /usr/local/sbin/rip44d -p passwd -t 44
 2609 tty3     Ss+    0:01 ./jnos -C -g2 -u3 -f nos.cfg -i
 2610 ?        Ss     0:00 /bin/su -c /usr/bin/perl -w /spider/perl/cluster.pl sysop
 2704 ?        Ss     0:00 sh -c /usr/bin/perl -w /spider/perl/cluster.pl
 2705 ?        S      0:01 /usr/bin/perl -w /spider/perl/cluster.pl
 5007 ?        S      0:00 kissattach /dev/ttyUSB0 ax0
 5430 ?        S      0:00 kissattach /dev/ttyUSB1 ax1
 5494 pts/2    S+     0:00 listen -acirt
 5498 pts/1    S      0:00 kissnetd -p 2
 5505 ?        S      0:00 kissattach -l /dev/pts/3 ax2 44.137.31.73
 5516 pts/1    S      0:00 kissnetd -p 2
 5523 ?        S      0:00 kissattach -l /dev/pts/5 ax3 44.137.31.73
 5534 pts/1    S      0:00 socat -d -d -ly PTY,link=/dev/ttyq1 PTY,link=/dev/ptyq1
 5536 pts/1    S      0:00 slattach -s 38400 -p slip /dev/ptyq1
 5549 pts/1    S      0:00 socat -d -d -ly PTY,link=/dev/ttyq2 PTY,link=/dev/ptyq2
 5554 ?        S      0:00 kissattach -m 256 /dev/ptyq2 ax4 44.137.31.73
 5561 ?        S      0:00 ax25udp -c /etc/ax25/ax25ipd-10093.conf
 5564 pts/1    S      0:00 socat -d -d -ly PTY,link=/dev/ttyq3 PTY,link=/dev/ptyq3
 5569 ?        S      0:00 kissattach -m 256 /dev/ptyq3 ax5 44.137.31.73
 5574 ?        S      0:00 ax25ipd -c /etc/ax25/ax25ipd-axip.conf
 5579 pts/1    S      0:00 socat -d -d -ly PTY,link=/dev/ttyq4 PTY,link=/dev/ptyq4
 5585 ?        S      0:00 kissattach -m 256 /dev/ptyq4 ax6 44.137.31.73
 5606 pts/1    S      0:00 ./linuxnet
 5607 pts/1    S      0:00 ./rstatrxd /var/www/cgi-bin/postat/
 5616 ?        S      0:00 beacon -c PI1LAP-15 -t 10 -d ID ax3 Network node PI1LAP-15 Zeeland, JO11VN
 5617 ?        S      0:00 beacon -c PI1LAP-15 -t 10 -d ID ax2 Network node PI1LAP-15 Zeeland, JO11VN
 5618 ?        S      0:00 beacon -c PI1LAP-15 -t 10 -d ID ax0 Network node PI1LAP-15 Zeeland, JO11VN
 5619 ?        S      0:00 beacon -c PI1LAP-15 -t 10 -d ID ax1 Network node PI1LAP-15 Zeeland, JO11VN
 5620 ?        S      0:00 /usr/local/sbin/ax25d
 5622 ?        S      0:00 /usr/local/sbin/mheardd
 5624 pts/1    S      0:00 /usr/local/sbin/ax25rtd
 5626 ?        S      0:00 /usr/local/sbin/flexd
 5628 ?        S      0:00 /usr/local/sbin/netromd -c -i -p 1 -t 15
 5636 pts/1    S      0:00 /bin/bash /usr/local/sbin/fbb -s -a
 5638 pts/1    S      0:00 /usr/local/sbin/xfbbd -s -a

 

ax25 start file

Ax25 start file die ik gebruik voor pi1lap/pi8lap/pd2lt
(nog toe te voegen start/stop/status)

#!/bin/sh
# Start AX25/Netrom networking daemons.
# Script written and modified by Niels pd2lt
# Date of last modification: 03-11-2017

### BEGIN INIT INFO
# Provides:       ax25
# Required-Start: $network $remote_fs $syslog
# Required-Stop:  $network $remote_fs $syslog
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6
# Description:    AX25 server
### END INIT INFO

set +e   # Don't exit on error status

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/xnet:/usr/local/etc/ax25

DESC="AX25 server"

ENABLED=1

        modprobe mkiss
        modprobe ax25
        modprobe netrom
        modprobe rose


        # Dual port TNC KPC-9612
        mkiss -s 9600 -x 2 /dev/ttyUSB0 > /tmp/unix98
        export PTS0=`more /tmp/unix98 | grep -w /dev | cut -b -11`
        export PTS1=`more /tmp/unix98 | grep -w /dev | cut -b 12-`
        sleep 1
        # Port 1k2 144.850Mhz
        kissattach $PTS0 ax0 > /tmp/ax25-config.tmp
        awk '/device/ { print $7 }' /tmp/ax25-config.tmp > /tmp/ax25-config-tmp
        read Device < /tmp/ax25-config-tmp

        ifconfig $Device 44.137.31.73 netmask 255.255.255.224
        sleep 2
        # Port 9k6 430.950Mhz
        kissattach $PTS1 ax1 > /tmp/ax25-config.tmp
        awk '/device/ { print $7 }' /tmp/ax25-config.tmp > /tmp/ax25-config-tmp
        read Device < /tmp/ax25-config-tmp

        ifconfig $Device 44.137.31.73 netmask 255.255.255.224
        sleep 5

        # attach rose port
        rsattach rose0
        ifconfig rose0 44.137.31.73 netmask 255.255.255.224
        rsparms -call PI1LAP-10

        # link local pi8lap (xnet)
        tmpfile="/tmp/$$.startax2.pts"
        kissnetd -p 2 > "$tmpfile" &
        sleep 2
        attachthem () {
                read PTS1 PTS2
                kissattach -l $PTS1 ax2 44.137.31.73
                ifconfig ax2 44.137.31.73 netmask 255.255.255.224 up
                sleep 1
                sed -i "s,attach sdev3 kiss 3 1 19200 /dev/.*$,attach sdev3 kiss 3 1 19200 $PTS2," /usr/local/xnet/AUTOBOOT.NET
        }

        tail -n 1 $tmpfile | attachthem
        rm $tmpfile
        sleep 3

        # Link local pi1lap-4 (xnet)
        tmpfile="/tmp/$$.startax3.pts"
        kissnetd -p 2 > "$tmpfile" &
        sleep 2
        attachthem () {
                read PTS1 PTS2
                kissattach -l $PTS1 ax3 44.137.31.73
                ifconfig ax3 44.137.31.73 netmask 255.255.255.224 up
                sleep 1
                sed -i "s,attach sdev4 kiss 4 1 19200 /dev/.*$,attach sdev4 kiss 4 1 19200 $PTS2," /usr/local/xnet/AUTOBOOT.NET
        }

        tail -n 1 $tmpfile | attachthem
        rm $tmpfile
        sleep 3

        # create slip link Linux <-> Xnet
        socat -d -d -ly PTY,link=/dev/ttyq1 PTY,link=/dev/ptyq1 &
        sleep 2
                slattach -s 38400 -p slip /dev/ptyq1 &
                sleep 1
                ifconfig sl0 44.137.31.69 netmask 255.255.255.255 pointopoint 44.137.31.70 mtu 236 up
                sleep 1

        # create axudp device
        socat -d -d -ly PTY,link=/dev/ttyq2 PTY,link=/dev/ptyq2 &
        sleep 2
                kissattach -m 256 /dev/ptyq2 ax4 44.137.31.73
                ax25udp -c /etc/ax25/ax25ipd-10093.conf > /tmp/axudp
                ifconfig ax4 44.137.31.73 netmask 255.255.255.224 up
        sleep 1

        # create axip device
        socat -d -d -ly PTY,link=/dev/ttyq3 PTY,link=/dev/ptyq3 &
        sleep 2
                kissattach -m 256 /dev/ptyq3 ax5 44.137.31.73
                ax25ipd -c /etc/ax25/ax25ipd-axip.conf > /tmp/axip
                ifconfig ax5 44.137.31.73 netmask 255.255.255.224 up
        sleep 1

        # create socat device (jnos-uro)
        socat -d -d -ly PTY,link=/dev/ttyq4 PTY,link=/dev/ptyq4 &
        sleep 2
                kissattach -m 256 /dev/ptyq4 ax6 44.137.31.73
                ifconfig ax6 44.137.31.73 netmask 255.255.255.224 up
        sleep 1

        # MFnos running in DOSEmu
        # Set the comport in de file /etc/dosemu/dosemu.comf $_com1 = "dev/ttyq5"
        #socat -d -d -ly PTY,link=/dev/ttyq5 PTY,link=/dev/ptyq5 &
        #       slattach -n -q -p slip -s 38400 /dev/ptyq5 &
        #sleep 2
        # KISS inteface for MFnos / slip
        #       kissattach /dev/ptyq5 ax6 44.137.31.73
        #       kissparms -p ax6 -c 1 -f y -t 10 -s 100 -r 255
        #       axparms -setcall ax6 pi1lap-10
        #
        #       ifconfig ax3 44.88.0.9 netmask 255.255.255.224 up
        #sleep 2

        # create nr0 device (lapuro/pi1lap-5) uronode
                ifconfig nr0 down
                nrattach -i 44.137.31.73 -m 512 nr0
                ifconfig nr0 44.137.31.73 netmask 255.255.255.224 hw netrom PI1LAP-5 up

        # create nr1 device (lapbbs/pi8lap) f6fbb
                ifconfig nr1 down
                nrattach -i 44.137.31.73 -m 512 nr1
                ifconfig nr1 44.137.31.73 netmask 255.255.255.224 hw netrom PI8LAP up

        # create nr2 device (lapdx/pi1lap-4) dxspider
                ifconfig nr2 down
                nrattach -i 44.137.31.73 -m 512 nr2
                ifconfig nr2 44.137.31.73 netmask 255.255.255.224 hw netrom PI1LAP-4 up

        # create nr3 device (lappac/pi1lap-7) fpac
                ifconfig nr3 down
                nrattach -i 44.137.31.73 -m 512 nr3
                ifconfig nr3 44.137.31.73 netmask 255.255.255.224 hw netrom PI1LAP-7 up

        # start xnet
        cd /usr/local/xnet
        rm *.CFG &> /dev/null
        sleep 2
        ./linuxnet < /dev/tty2 > /dev/tty2 2>&1 &
        ./rstatrxd /var/www/cgi-bin/postat/ &> /dev/null &
        sleep 2

        # route
        # Xnet route
        ip route add 44.137.31.70 dev sl0 table 44 src 44.137.31.69
        # Mfnos route to 192.168.1.110
        #route add 44.137.31.75 gw 192.168.1.112

        # beacons
        beacon -c PI1LAP-15 -t 10 -d  ID ax0 "Network node PI1LAP-15 Zeeland, JO11VN" &
        beacon -c PI1LAP-15 -t 10 -d  ID ax1 "Network node PI1LAP-15 Zeeland, JO11VN" &
        beacon -c PI1LAP-15 -t 10 -d  ID ax2 "Network node PI1LAP-15 Zeeland, JO11VN" &
        beacon -c PI1LAP-15 -t 10 -d  ID ax3 "Network node PI1LAP-15 Zeeland, JO11VN" &

        # start ax25 deamons
        /usr/local/sbin/ax25d
        /usr/local/sbin/mheardd
        /usr/local/sbin/ax25rtd
        /usr/local/sbin/flexd
        /usr/local/sbin/netromd -c -i -p 1 -t 15
        fbb -s -a -l /etc/ax25/fbb.log

axports

axports file

# /etc/ax25/axports
#
# The format of this file is:
#
# name  callsign        speed   paclen  window  description
# ----- -----------     ------- ------- ------- ---------------------------
ax0     PI1LAP-1        9600    128     4       144.850Mhz 1k2
ax1     PI1LAP-2        9600    128     4       430.950Mhz 9k6
ax2     PI1LAP-3        19200   256     4       Link local BBS pi8lap
ax3     PI1LAP-6        19200   256     4       Link local Dx pi1lap-4
ax4     PI1LAP-8        19200   256     2       AX25/udp via pi1lap-8
ax5     PI1LAP-9        19200   256     2       AX25/ip via pi1lap-9
ax6     PD9Q-7          19200   256     2       Link local Jnos pd9q
rose0   PI1LAP-11       9600    128     4       Rose port

 

Start (X)Net/kissattach/slip at boot

I have written the startup script below so that all services are started. Now of course it is nice if this also happens when booting the server. First the start script.

#!/bin/sh
#
tmpfile="/tmp/$$.startax0.pts"
#
kissnetd -p 2 > "$tmpfile" &
#
sleep 2
#
attachthem () {
        read PTS1 PTS2
        echo "Starting PTS gekloot voor poort AX0 :)"
        kissattach -l $PTS1 ax0 192.168.1.113
	ifconfig ax0 netmask 255.255.255.0
        sleep 1
        sed -i "s,attach sdev3 kiss 3 1 115200 /dev/.*$,attach sdev3 kiss 3 1 115200 $PTS2," /usr/local/xnet/AUTOBOOT.NET
}

tail -n 1 $tmpfile | attachthem
rm $tmpfile
#
tmpfile="/tmp/$$.startax1.pts"
#
kissnetd -p 2 > "$tmpfile" &
#
sleep 2

attachthem () {
	read PTS1 PTS2
	echo "Starting PTS gekloot voor poort AX1 :)"
        kissattach -l $PTS1 ax1 192.168.1.113
        ifconfig ax1 netmask 255.255.255.0
        sleep 1
        sed -i "s,attach sdev4 kiss 4 1 115200 /dev/.*$,attach sdev4 kiss 4 1 115200 $PTS2," /usr/local/xnet/AUTOBOOT.NET
}

tail -n 1 $tmpfile | attachthem
rm $tmpfile
################## Klote slip link ###################################
XNET_DIR=/usr/local/xnet
LINIP=192.168.1.200     # LINUX-IP   address
XNET=192.168.1.201  # XNET  address
#
cd /usr/local/xnet
./dev &
#
sleep 2
#
attachthem () {
        read PTS1 PTS2
        echo "Starting PTS gekloot voor de slip link :)"
        slattach -s 38400 -p slip $PTS1 &
        sleep 1
        ifconfig sl0 $LINIP netmask 255.255.255.255 pointopoint $XNET mtu 236 up
        sleep 1
        sed -i "s,attach sdev6 slip 38400 /dev/.*$,attach sdev6 slip 38400 $PTS2," /usr/local/xnet/AUTOBOOT.NET
}

tail -n 1 /tmp/slip | attachthem
rm /tmp/slip

cd /usr/local/sbin
./ppconversd &
sleep 3
#
cd /usr/local/xnet
./rstatrxd /var/www/cgi-bin/postat/ &
sleep 2
#
  /sbin/modprobe netrom
  /usr/local/sbin/nrattach -i 192.168.1.113 -m 512 netrom
  /usr/local/sbin/nrattach -i 192.168.1.113 -m 512 netcon
  /usr/local/sbin/nrattach -i 192.168.1.113 -m 512 netbbs
# Init Netrom
   /usr/local/sbin/netromd -i -l -t 30
# Enable External Logons
  /usr/local/sbin/ax25d &
  /bin/sleep 2
# Start Mheard daemon
 /usr/local/sbin/mheardd
# start fbb
 /usr/local/sbin/fbb &
# Nu dan eindelijk Xnet
./linuxnet < /dev/tty2 > /dev/tty2 2>&1 &

Now I have created the following file in /etc/init.d with the name xnet.

#!/bin/sh
### BEGIN INIT INFO
# Provides:          xnet
# Required-Start: $remote_fs $syslog $network
# Required-Stop: $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Run /usr/local/xnet/xnet if it exist
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin

. /lib/init/vars.sh
. /lib/lsb/init-functions

do_start() {
        if [ -x /usr/local/xnet/xnet ]; then
                [ "$VERBOSE" != no ] && log_begin_msg "Running pi1lap)"
                /usr/local/xnet/xnet
                ES=$?
                [ "$VERBOSE" != no ] && log_end_msg $ES
                return $ES
        fi
}

case "$1" in
    start)
        do_start
        ;;
    restart|reload|force-reload)
        echo "Error: argument '$1' not supported" >&2
        exit 3
        ;;
    stop)
        ;;
    *)
        echo "Usage: $0 start|stop" >&2
        exit 3
        ;;
esac

Now it has to be added.
update-rc.d xnet defaults
update-rc.d xnet enable

Well, reboot and see if everything is alright.