syslog time different with `date`

default:
debian9.4, /etc/timezone: US/Samoa

begin:
# tzselect
TZ='Asia/Shanghai'; export TZ
# echo "TZ='Asia/Shanghai'; export TZ" >> /etc/profile && source /etc/profile

then:
# date -R;hwclock
Tue, 12 Jun 2018 20:58:03 +0800
2018-06-12 20:58:03.057531+0800

syslog time wrong

last:
# because not change the localtime file
change localtime file link

ps:
#supervisor use the localtime by python as the same as syslog
import syslog; syslog.syslog('test test');
#it cat get: Jun 13 14:27:10 debian python: test test

supervisor manage program with daemon

dhcpd cmd:/usr/sbin/dhcpd -q -cf /etc/dhcp/dhcpd.conf -pf /var/run/dhcpd.pid eth0

supervisor log will tell: exited: dhcpd (exit status 1; not expected)

because the dhcpd is a daemon process and it will run in background while start, so supervisor will restart the process util over the retry times.

SUPERVISOR记录
foreman-base/supervisord.conf
daemon proxy

dhcpd.conf:

[program:dhcpd_proxy]
directory=/etc/supervisor/conf.d
command=bash foreground_dhcp.sh
stderr_logfile=/var/log/supervisor/dhcpd-stderr.log
stdout_logfile=/var/log/supervisor/dhcpd-stdout.log
user=root
priority=2
autostart=true
autorestart=true
;autorestart=unexpected

foreground_dhcp.sh:

#! /usr/bin/env bash
set -eu

pidfile="/run/dhcpd.pid"
command="/usr/sbin/dhcpd -q -cf /etc/dhcp/dhcpd.conf"
stdout="/var/log/supervisor/dhcpd-stdout.log"

# Proxy signals
function kill_app(){
 kill $(cat $pidfile)
 exit 0 # exit okay
}
trap "kill_app" SIGINT SIGTERM

echo `date`': restart the foreground dhcpd-proxy process !!!' >> $stdout
# kill the dhcpd process before start
if [ -f $pidfile ] && kill -9 $(cat $pidfile); then
 echo `date`': kill dhcpd process success, because the foreground dhcpd-proxy process was killed !' >> $stdout
else
 echo `date`': kill dhcpd process fail, because the dhcpd daemon process was killed !' >> $stdout
fi

# for release the process, the same as below
sleep 2
# Launch daemon
$command
sleep 2

# Loop while the pidfile and the process exist
while [ -f $pidfile ] && kill -0 $(cat $pidfile) ; do
 sleep 0.5
done
exit 1000 # exit unexpected

dhcp failover

### master:

option domain-name "wh.wifi.com";
option domain-name-servers 192.168.87.135,192.168.87.134;

ddns-update-style none;
authoritative;

ping-check true;
default-lease-time 86400;
max-lease-time 172800;

log-facility local7;

failover peer "dhcp-failover" {
 primary;
 address 10.160.16.58;
 port 647;
 peer address 10.160.16.59;
 peer port 847;
 max-response-delay 60;
 max-unacked-updates 10;
 load balance max seconds 3;
 mclt 3600;
 split 128;
}

include "/etc/dhcp/dhcpd.hot";

### slave:

option domain-name "wh.wifi.com";
option domain-name-servers 192.168.87.135,192.168.87.134;

ddns-update-style none;
authoritative;

ping-check true;
default-lease-time 86400;
max-lease-time 172800;

log-facility local7;

failover peer "dhcp-failover" {
 secondary;
 address 10.160.16.59;
 port 847;
 peer address 10.160.16.58;
 peer port 647;
 max-response-delay 60;
 max-unacked-updates 10;
 load balance max seconds 3;
}

include "/etc/dhcp/dhcpd.hot";

### dhcpd.hot:

subnet 10.160.72.0 netmask 255.255.252.0 {
 option routers 10.160.72.1;
 pool {
  failover peer "dhcp-failover";
  range 10.160.72.100 10.160.75.200;
 }
}
# for avoid the error: Not configured to listen on any interfaces!
subnet 10.160.16.0 netmask 255.255.254.0 {
 option routers 10.160.16.1;
 option domain-name "outnet.com";
 option domain-name-servers 10.160.16.1;
 next-server 10.160.16.2;
 filename "pxelinux.0";
 default-lease-time 600;
 pool {
  failover peer "dhcp-failover";
  range 10.160.16.5 10.160.16.9;
 }
}

use `trap` in shell script

use [trap command EXIT] at the begin in the shell script follow the [#!/bin/bash] for catch the signal, and use [trap – EXIT] at the end of the shell script for cancel the signal while exit the script normally.

#!/bin/bash
function cmd() {
 do something while exit this script before meeting "trap -EXIT"
}
trap cmd EXIT
# Exit immediately if a command exits with a non-zero exit status.
set -e
###just do it
trap -EXIT