#!/bin/bash # # dplus startup script - Written by Brian Roode, NJ6N - nj6n@soara.org # # 2008-03-28 | nj6n | Created based on version 1 dstar init script # 2008-03-30 | nj6n | Add update files capability # 2008-04-07 | nj6n | Pointed to the new G2 Dsync Page 1.0d # 2008-04-08 | nj6n | Add update from nj6n.com web site for G2 # user / gateway data 1.0e # 2008-04-09 | nj6n | Check return code of CURL upon update... (1.0f) # 2008-04-15 | nj6n | Run watch_dplus if it's available. (1.0g) # 2008-04-28 | nj6n | Display version number on status request (1.0h) # 2008-07-10 | nj6n | Removed V1 gateway/user data retrieval and # redundant logging. (2.0) # 2008-07-29 | nj6n | call "success" function upon success... # 2012-01-07 | nj6n | added "update" to check for new version (calls updater script) (2.1) # # VERSION=2.1 # # dplus D-STAR utility startup script # # Description: starts, stops, restarts dplus daemon # # chkconfig: 345 74 26 # description: Manages AA4RC's dplus application # if [ $UID != 0 ]; then echo echo "ERROR: This script must be run as the root user!" echo " Please use 'su' or log in as root and try again." echo exit 1 fi # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. [ -r /etc/sysconfig/network ] && . /etc/sysconfig/network TOOLS="/dstar/tools" DPLUS=$TOOLS/dplus STARTUP_MESSAGE="/dstar/dv/system-ready.dv" DSTARGW=/opt/products/dstar/dstar_gw DSIPSVD=$DSTARGW/dsipsvd/dsipsvd.conf DSGWD=$DSTARGW/dsgwd/dsgwd.conf LOG=/var/log/dplus.log # export LD_LIBRARY_PATH=/opt/products/dstar/pgsql/lib # DPLUS_VER=`$DPLUS -v 2>/dev/null` # Check that networking is up. [ "${NETWORKING}" = "no" ] && exit 1 # # Make sure the dstar gateway configuration files exist # if [ ! -r $DSIPSVD ]; then echo "$DSIPSVD doesn't exist!" failure echo exit fi if [ ! -r $DSGWD ]; then echo "$DSGWD doesn't exist!" failure echo exit fi # # Read gateway call and DNS path from config file. # GW_CALL=`egrep -e '^ZR_CALLSIGN' $DSIPSVD | sed -e 's/ //g' | awk -F"=" '{print $2}' |sed -e 's/\r//'` # # Display version # version() { echo "$VERSION" exit } start() { # Start daemons. # # start dplus, if it exists, otherwise complain, then quit. # if [ ! -x $DPLUS ]; then echo -n "$DPLUS: not installed!" failure echo exit fi if [ -n "`/sbin/pidof $DPLUS`" ]; then echo -n "$DPLUS: already running!" failure echo exit else echo -n "Starting $DPLUS " /usr/bin/nohup $DPLUS -c $GW_CALL > $LOG 2>&1 & sleep 2 if [ -n "`/sbin/pidof dplus`" ]; then success /bin/echo if [ -f $STARTUP_MESSAGE ]; then for module in {a,b,c} do cp $STARTUP_MESSAGE /dstar/tmp/play-$module.dvtool sleep 2 done fi else failure echo return 1 fi fi } stop() { # Stop dplus echo -n "Stopping: dplus " PID1=`/sbin/pidof dplus` RETVAL=$? if [ $RETVAL -ne 0 ]; then echo -e "\n\tERROR: $DPLUS is NOT running!" else /bin/kill $PID1 success /bin/echo fi } restart() { stop sleep 2 start } update () { /dstar/tools/dplus-check.sh 2>/dev/null exit } status() { PID=`/sbin/pidof dplus` RETVAL=$? if [ $RETVAL -ne 0 ]; then echo "dplus is NOT running!" else echo "dplus is running, PID = $PID, version = $DPLUS_VER" fi } # See how we were called. case "$1" in start) start ;; stop) stop ;; restart) restart ;; version) version ;; update) update ;; status) status ;; *) echo -e $"\nUsage: \n\t$0 {option}" echo -e "\n\tOptions:\n" echo -e "\trestart - restarts dplus" echo -e "\tstart - starts dplus" echo -e "\tstatus - display status" echo -e "\tstop - stops dplus" echo -e "\tversion - display script version and exit" echo -e "\n" exit 1 esac exit $RETVAL