Syslog in Telem Devices

From Phobos Wiki
Revision as of 13:22, 24 February 2015 by MarkTomm (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In telem devices, syslog is stared atr boot in the S01logging script located in /etc/init.d.

root@telem-gw6e /home/martem $ cat /etc/init.d/S01logging
#!/bin/sh
#
# Start logging
#

# Read config file if it is present.
if [ -r /etc/default/syslogd ]
then
    . /etc/default/syslogd
fi

case "$1" in
  start)
    echo -n "Starting logging: "

    ! rm -rf /tmp/log
    ! rm -rf /var/log
    mkdir -p /tmp/log
    ln -s /tmp/log /var/log
    ln -s /var/local/telem/log /var/log/telem
    touch /var/log/wtmp


    if [ "$SYSLOGD_REMOTE" = "yes" ]; then
    start-stop-daemon -S -q -p /var/run/syslog.pid --exec /sbin/syslogd -- -O /var/log/telem/messages -s 1024 -b 3 -L -R $SYSLOGD_REMOTE_SERVER:514
    else
    start-stop-daemon -S -q -p /var/run/syslog.pid --exec /sbin/syslogd -- -O /var/log/telem/messages -s 1024 -b 3
    fi

    ln -s /var/log/telem/messages /var/log/messages

        if [ "$TELEM_GW_SYSLOG_REMOTE" = "yes" ]; then
        /usr/local/bin/telem/telem_syslog.sh $TELEM_GW_SYSLOG_REMOTE_SERVER &> /dev/null &
    fi
    start-stop-daemon -S -q -p /var/run/klogd.pid --exec /sbin/klogd
    echo "OK"
    ;;
  stop)
    echo -n "Stopping logging: "
    start-stop-daemon -K -q -p /var/run/syslog.pid
    start-stop-daemon -K -q -p /var/run/klogd.pid
        killall -9 syslogd
        killall -9 klogd
        killall -9 telem_syslog.sh
    killall -9 socat
    echo "OK"
    ;;
  restart|reload)
    ;;
  *)
    echo $"Usage: $0 {start|stop|restart}"
    exit 1
esac

exit $?

Example of /etc/default/syslog

root@telem-gw6e /home/martem $ cat /etc/default/syslogd
SYSLOGD_REMOTE=no
SYSLOGD_REMOTE_SERVER=192.168.255.11
TELEM_GW_SYSLOG_REMOTE=no
TELEM_GW_SYSLOG_REMOTE_SERVER=192.168.255.11

Contents of /usr/local/bin/telem/telem_syslog.sh

root@telem-gw6e /home/martem $ cat /usr/local/bin/telem/telem_syslog.sh
#!/bin/sh

while true
do
    logger "telem_syslog:start"
    /usr/bin/socat -t 20 -T 20 udp4-recvfrom:514,bind=127.0.0.1,ignoreeof udp4-sendto:$1:514
    logger "telem_syslog:exit"
done

MarkTomm 24. veebruar 2015, kell 15:22 (EET)