#!/bin/sh /etc/rc.common # Init script for aprx # This script starts the APRX daemon and the display output script. START=99 # variable definitions PROG="aprx" APRX_BIN="/usr/sbin/$PROG" APRX_LOG_DIR="/var/log/aprx" APRX_CNF="/tmp/aprx.conf" APRX_CNF_DEFAULT="/etc/aprx.conf" APRX_CNF_DIR="/home/aprx/config/" APRX_CNF_SELECT="config.use" APRX_LOG_DISPLAY="/home/bin/display_aprx_log_loop" DISPLAY="/dev/Display" system_config() { local cfg="$1" config_get hostname "$cfg" hostname } start() { # check if the APRX program exists at all. [ -x "$APRX_BIN" ] || return 1 # create the tmp config directory if it does not exist yet [ -d "$APRX_LOG_DIR" ] || mkdir -p $APRX_LOG_DIR # read out the to be used configuration from the APRX_CNF_SELECT file # and copy it to the tmp config that is used at runtime [ -f "$APRX_CNF_DIR$APRX_CNF_SELECT" ] && cp -f $APRX_CNF_DIR$(awk '/^aprx./ { print }' $APRX_CNF_DIR$APRX_CNF_SELECT) $APRX_CNF # if there is still no config file use the default one from APRX_CNF_DEFAULT [ -e "$APRX_CNF" ] || cp -f $APRX_CNF_DEFAULT $APRX_CNF sleep 1 #----------- START the APRX daemon -------------- # start the APRX daemon APRX_BIN with our config file APRX_CNF. $APRX_BIN -f $APRX_CNF & sleep 1 # check if the APRX program was started successfully by checking the existence of PID file. if [ -f /var/run/aprx.pid ] ; then # APRX start successful. Print out info to display. echo "$PROG started successfully" > $DISPLAY # read out the APRX config file APRX_CNF and print out the lines that are starting with #Display to the display. awk '/^#Display:/ { $1=""; print }' $APRX_CNF > $DISPLAY # do the same again but write to log file. logger -t "$PROG" "..started successfully" awk '/^#Display:/ { $1=""; print }' $APRX_CNF sleep 1 # start the APRX_LOG_DISPLAY script. This routine compares the the log file # further explanation can be found in the script itselfe. $APRX_LOG_DISPLAY& else # APRX start failed. Print out info to display. echo "$PROG startup FAILED" > $DISPLAY # do the same again but write to log file. logger -t "$PROG" "..startup FAILED" fi } stop() { # stops all processes of APRX. killall $PROG # check if PID file still exists. if [ -f /var/run/aprx.pid ] ; then # PID file still exists. stop was not successful. Print out this information to display. echo "$PROG still running" > $DISPLAY # do the same again but write to log file. logger -t "$PROG" "..still running" else # PID file gone. stop was successful. Print out this information to display. echo "$PROG stopped" > $DISPLAY # do the same again but write to log file. logger -t "$PROG" "..stopped" fi } restart() { stop start }