Cross compilation and configuration of perp from scratch

Posted by Fly on Wed, 01 Dec 2021 05:13:37 +0100

summary

perp is an excellent and low resource consuming open source multi process management framework, which is mostly used in embedded system environment. Since there are few resources on the Internet other than those on the official website, I'll record my previous experience and share it with you.

Compared with restart D, perp has more functions and more processes to monitor.

Resource occupation:
ROM: 556K (maximum occupancy, can be cropped)

reference material

http://b0llix.net/perp/site.cgi?page=about

Cross compilation

process

Download the source package from the official website

1,tar -zxvf perp-2.07.tar.gz
2,vi conf.mk
 modify CC,STRIP Cross compile tool for  
Modify the installation path, for example/home/ss/perp_install
3,make distclean;make ;make install

report errors

Report: mk_outvec,mk_rlimit, mksysstr related errors

Reason: the above compiled tools are used during compilation, that is, they are used on the compilation host, and cross compilation compiles them into the target machine architecture.
Solution: modify lasagna/Makefile and compile them with native GCC

outvec/mk_outvec : outvec/mk_outvec.c
    gcc $(CFLAGS) -o $@ outvec/mk_outvec.c

....

rlimit/mk_rlimit : rlimit/mk_rlimit.c
    gcc $(CFLAGS) -o $@ rlimit/mk_rlimit.c
    
....

sysstr/mksysstr : sysstr/mksysstr.c
    gcc $(CFLAGS) -o $@ sysstr/mksysstr.c

to configure

make install obtains some bin files, as follows:

ss@ss-vm:~/koal_sdk/third_part$ ls perp_install/usr/sbin/ -l
 Total consumption 664
-rwxr-xr-x 1 ss ss 27928 11 June 26-15:34 perpboot
-rwxr-xr-x 1 ss ss 26020 11 June 26-15:34 perpctl
-rwxr-xr-x 1 ss ss 60500 11 June 26-15:34 perpd
-rwxr-xr-x 1 ss ss 19404 11 June 26-15:34 perphup
-rwxr-xr-x 1 ss ss 31924 11 June 26-15:34 perpls
-rwxr-xr-x 1 ss ss 24676 11 June 26-15:34 perpok
-rwxr-xr-x 1 ss ss  5273 11 June 26-15:34 perp-setup
-rwxr-xr-x 1 ss ss 29620 11 June 26-15:34 perpstat
-rwxr-xr-x 1 ss ss 24452 11 June 26-15:34 runargs
-rwxr-xr-x 1 ss ss 19240 11 June 26-15:34 runargv0
-rwxr-xr-x 1 ss ss 23748 11 June 26-15:34 runchoom
-rwxr-xr-x 1 ss ss 19596 11 June 26-15:34 rundetach
-rwxr-xr-x 1 ss ss 25264 11 June 26-15:34 rundeux
-rwxr-xr-x 1 ss ss 29548 11 June 26-15:34 runenv
-rwxr-xr-x 1 ss ss 24544 11 June 26-15:34 runfile
-rwxr-xr-x 1 ss ss 30484 11 June 26-15:34 runlimit
-rwxr-xr-x 1 ss ss 23036 11 June 26-15:34 runlock
-rwxr-xr-x 1 ss ss 20532 11 June 26-15:34 runpause
-rwxr-xr-x 1 ss ss 19324 11 June 26-15:34 runsession
-rwxr-xr-x 1 ss ss 44172 11 June 26-15:34 runtool
-rwxr-xr-x 1 ss ss 27024 11 June 26-15:34 runtrap
-rwxr-xr-x 1 ss ss 22380 11 June 26-15:34 runuid
-rwxr-xr-x 1 ss ss 14880 11 June 26-15:34 sissylog
-rwxr-xr-x 1 ss ss 38508 11 June 26-15:34 tinylog
-rwxr-xr-x 1 ss ss  1375 11 June 26-15:34 tinylog_run

Among them, only perpctl, perpls and perpd are commonly used

1. Create running rules for processes to be monitored

1. Create / etc/perp
2. Create the target directory under / etc/perp /, for example:

/etc/perp
└── perp_demo
    ├── rc.log
    ├── rc.main

This directory stores the start, stop, restart and log records of the process to be monitored.

rc.main

Example:

#!/bin/sh
exec 2>&1

TARGET=${1}
SVNAME=${2}


## start target:
start() {
    echo "*** ${SVNAME}: starting perp_demo..."
    exec \
      app_demo
}


## reset target:
reset() {
    case $3 in
      'exit' )
          echo "*** ${SVNAME}: exited status $4" ;;
      'signal' )
          echo "*** ${SVNAME}: killed on signal $5" ;;
      * )
          echo "*** ${SVNAME}: stopped ($3)" ;;
    esac
    exit 0
}


## branch to target:
eval ${TARGET} "$@"

### EOF

rc.log

Example:

#!/bin/sh

if test ${1} = 'start' ; then
  exec tinylog_run ${2}
fi

exit 0
### EOF

Log the process into the / var/log / process name / current file.

2. Setting environment variables

export PERP_BASE=/etc/perp
Purpose: tools such as Perls will be based on the perp in env_ Base finds the corresponding configuration file. If there is no environment variable, it will report:

perpls fatal: failure connecting to perpd control socket ./.control/perpd.sock: file does not exist (ENOENT)

3. Start the perpd server

perp /etc/perp  

4. After configuration, verify the results

If everything is normal, Perls can see the running status of the monitoring process

perpd

effect

perpd is a daemon that receives, for example, instructions issued by perpls/perpctl and processes them according to rules.

When perpd runs, it will scan rc.log and rc.main files in the specified directory. When scanning, it will switch to the directory where rc.main is located and execute:

./rc.main start/stop/reset svname [ args...  ]

rc.log records the log of runtime. This file is optional.
rc.main contains rules for starting and stopping processes. This file must exist.

use

perpd /etc/perp

perpls

Function: displays the monitored process information

# perpls 
[+ +++ ---]  perp_demo  uptime: 58242s/-s  pids: 262/-

Explanation:
[+ + + -]: run panel, including 3 parts, followed by the name of monitoring service, uptime: startup time
Panel part I:
+: normal startup and operation
-: the process is not monitored by perpd or is stopped and not pulled up
Part II:
.: the process stops as follows:

# perpls 
[+ +++ ---]  perp_demo  uptime: 58242s/-s  pids: 262/-
# perpctl d perp_demo
perp_demo: ok
# perpd[261]: monitoring 0 client connections
*** perp_demo: killed on signal SIGTERM

# perpls
perpd[261]: monitoring 1 client connection
[+ ... ---]  perp_demo  uptime: -s/-s  pids: -/-

r: It means that the process will go down in a short time after it gets up, that is, the process is pulled up and exited frequently, and the process is abnormal
p: Indicates that the process is paused
o: The identity process is executed only once
Part III:
Don't think about it

perpctl

Role: control the status of the monitored process
Only the common methods are described below.

perpctl d

perpctl d process name: that is, d(down) drops the process. The example is as follows:

# perpls 
[+ +++ ---]  perp_demo  uptime: 58242s/-s  pids: 262/-
# perpctl d perp_demo
perp_demo: ok
# perpd[261]: monitoring 0 client connections
*** perp_demo: killed on signal SIGTERM

# perpls
perpd[261]: monitoring 1 client connection
[+ ... ---]  perp_demo  uptime: -s/-s  pids: -/-

perpctl u

perpctl u process name: that is, the process started by u(up). The example is as follows:

# perpls
perpd[261]: monitoring 1 client connection
[+ ... ---]  perp_demo  uptime: -s/-s  pids: -/-
# perpctl u perp_demo
perp_demo: ok
# *** perp_demo: starting perp_demo...
ss test

# perpls
[+ +++ ---]  perp_demo  uptime: 5s/-s  pids: 286/-

perpctl o

o(once). If the process does not get up, pull it up and mark that it is only pulled up once. Then kill the process and it will not be pulled up.

# perpls
[+ +++ ---]  perp_demo  uptime: 5s/-s  pids: 286/-
# perpctl o perp_demo
perp_demo: ok
# perpls
[+ +o+ ---]  perp_demo  uptime: 193s/-s  pids: 286/-

Topics: Linux Embedded system IoT