From 54669c93a0ab244d6d93279e28fb8b303feabba7 Mon Sep 17 00:00:00 2001 From: DanB Date: Sun, 30 Nov 2014 17:37:26 +0100 Subject: [PATCH] Init script with automatic stacktrace --- cmd/cgr-engine/cgr-engine.go | 1 - data/scripts/pkg/debian/cgrates.init | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index fbe7a826b..19dc55d19 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -502,7 +502,6 @@ func main() { // Start the servers go serveRpc(rpcWait) go serveHttp(httpWait) - <-exitChan if *pidFile != "" { diff --git a/data/scripts/pkg/debian/cgrates.init b/data/scripts/pkg/debian/cgrates.init index e2417f293..c43670c95 100755 --- a/data/scripts/pkg/debian/cgrates.init +++ b/data/scripts/pkg/debian/cgrates.init @@ -20,10 +20,10 @@ NAME=cgrates DAEMON=/usr/bin/cgr-engine USER=cgrates GROUP=cgrates -ENGINE_OPTS="" +DAEMON_OPTS="" RUNDIR=/var/run/$NAME PIDFILE=$RUNDIR/cgr-engine.pid -COREDUMP=$RUNDIR/cgr-coredump.log +STACKTRACE=$RUNDIR/$NAME.strace SCRIPTNAME=/etc/init.d/$NAME DEFAULTS=/etc/default/$NAME ENABLE=false @@ -50,7 +50,8 @@ fi # Install the run folder if [ ! -d $RUNDIR ]; then mkdir $RUNDIR - chown $USER:$GROUP $RUNDIR + touch $STACKTRACE + chown -R $USER:$GROUP $RUNDIR fi @@ -63,12 +64,14 @@ do_start() # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started - echo "Started at:" `date`>>$COREDUMP - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null 2>>$COREDUMP \ + echo "\n" + echo "### Started at:" `date`>>$STACKTRACE + echo "\n" + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test\ || return 1 - start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --exec $DAEMON --chuid $USER:$GROUP --background -- \ - $ENGINE_OPTS \ - || return 2 + start-stop-daemon --start --quiet --chuid $USER:$GROUP --make-pidfile --pidfile $PIDFILE --background\ + --startas /bin/bash -- -c "exec $DAEMON $DAEMON_OPTS >> $STACKTRACE 2>&1" \ + || return 2 } #