From db4a146924fbeccb6caded357a2c9116fe494f02 Mon Sep 17 00:00:00 2001 From: DanB Date: Wed, 4 Mar 2015 18:29:47 +0100 Subject: [PATCH] Part two - fix session initialization leading to nil pointer error in session manager, refactored tutorial init scripts, use /tmp as run_dir --- .../fs_json/cgrates/etc/init.d/cgrates | 18 +++++------ .../fs_json/freeswitch/etc/init.d/freeswitch | 32 ++++++++++++------- sessionmanager/session.go | 6 ++-- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/data/tutorials/fs_json/cgrates/etc/init.d/cgrates b/data/tutorials/fs_json/cgrates/etc/init.d/cgrates index 65cb0a701..b55f21683 100755 --- a/data/tutorials/fs_json/cgrates/etc/init.d/cgrates +++ b/data/tutorials/fs_json/cgrates/etc/init.d/cgrates @@ -21,23 +21,20 @@ DAEMON=/usr/bin/cgr-engine USER=cgrates GROUP=cgrates DAEMON_OPTS="" -RUNDIR=/tmp/$NAME/run +TUTFOLDER=/usr/share/cgrates/tutorials/fs_json/cgrates +TMP_DIR=/tmp/cgr_fsjson/cgrates +SCRIPTNAME=$TUTFOLDER/etc/init.d/$NAME +RUNDIR=$TMP_DIR/run PIDFILE=$RUNDIR/cgr-engine.pid STACKTRACE=$RUNDIR/$NAME.strace -SCRIPTNAME=$TUTFOLDER/etc/init.d/$NAME -DEFAULTS=$TUTFOLDER/etc/default/$NAME ENABLE=true -TUTFOLDER=/usr/share/cgrates/tutorials/fs_json/cgrates -ENGINE_OPTS="-config=$TUTFOLDER/etc/cgrates/cgrates.cfg" -HISTDIR=/tmp/$NAME/history -CDREDIR=/tmp/$NAME/cdre +DAEMON_OPTS="-config_dir=/usr/share/cgrates/tutorials/fs_json/cgrates/etc/cgrates" +HISTDIR=$TMP_DIR/history +CDREDIR=$TMP_DIR/cdre # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 -# Read configuration variable file if it is present -[ -r $DEFAULTS ] && . $DEFAULTS - # Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh @@ -78,6 +75,7 @@ do_start() # 1 if daemon was already running # 2 if daemon could not be started echo "\n### Started at:" `date`>>$STACKTRACE + echo $DAEMON $DAEMON_OPTS $PIDFILE start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test\ || return 1 start-stop-daemon --start --quiet --chuid $USER:$GROUP --make-pidfile --pidfile $PIDFILE --background\ diff --git a/data/tutorials/fs_json/freeswitch/etc/init.d/freeswitch b/data/tutorials/fs_json/freeswitch/etc/init.d/freeswitch index 2be40c31b..fc15fbbea 100755 --- a/data/tutorials/fs_json/freeswitch/etc/init.d/freeswitch +++ b/data/tutorials/fs_json/freeswitch/etc/init.d/freeswitch @@ -19,22 +19,37 @@ DAEMON=/usr/bin/freeswitch USER=freeswitch GROUP=freeswitch TUTDIR=/usr/share/cgrates/tutorials/fs_json/freeswitch +SCRIPTNAME=$TUTDIR/etc/init.d/$NAME +TMP_DIR=/tmp/cgr_fsjson/freeswitch CONFDIR=$TUTDIR/etc/$NAME -DEFAULTS=$TUTDIR/etc/default/freeswitch -RUNDIR=/var/run/$NAME -LOGDIR=/var/log/freeswitch +RUNDIR=$TMP_DIR//run +LOGDIR=$TMP_DIR/log PIDFILE=$RUNDIR/$NAME.pid -SCRIPTNAME=/etc/init.d/$NAME -WORKDIR=/var/lib/$NAME +WORKDIR=$TMP_DIR/lib DBDIR=$WORKDIR/db/ DAEMON_ARGS="-rp -conf $CONFDIR -db $DBDIR -log $LOGDIR -u $USER -g $GROUP -nonat -nc" [ -x $DAEMON ] || exit 0 -[ -r DEFAULTS ] && . DEFAULTS . /lib/init/vars.sh . /lib/lsb/init-functions +if [ ! -d $RUNDIR ]; then + mkdir -p $RUNDIR + chown -R $USER:$GROUP $RUNDIR + chmod -R ug=rwX,o= $RUNDIR +fi + +if [ ! -d $LOGDIR ]; then + mkdir -p $LOGDIR + chown -R $USER:$GROUP $LOGDIR +fi + +if [ ! -d $DBDIR ]; then + mkdir -p $DBDIR + chown -R $USER:$GROUP $DBDIR +fi + do_start() { if ! [ -f $CONFDIR/freeswitch.xml ]; then echo "$NAME is not configured so not starting.">&2 @@ -42,11 +57,6 @@ do_start() { return 3 fi - # Directory in /var/run may disappear on reboot (e.g. when tmpfs used for /var/run). - mkdir -p $RUNDIR - chown -R $USER:$GROUP $RUNDIR - chmod -R ug=rwX,o= $RUNDIR - start-stop-daemon --start --quiet \ --pidfile $PIDFILE --exec $DAEMON --name $NAME --user $USER \ --test > /dev/null \ diff --git a/sessionmanager/session.go b/sessionmanager/session.go index 592478cf5..50072488c 100644 --- a/sessionmanager/session.go +++ b/sessionmanager/session.go @@ -56,11 +56,11 @@ func NewSession(ev utils.Event, sm SessionManager) *Session { stopDebit: make(chan bool), sessionManager: sm, } - sRuns := make([]*engine.SessionRun, 0) - if err := sm.Rater().GetSessionRuns(ev, &sRuns); err != nil || len(sRuns) == 0 { + //sRuns := make([]*engine.SessionRun, 0) + if err := sm.Rater().GetSessionRuns(ev, &s.sessionRuns); err != nil || len(s.sessionRuns) == 0 { return nil } - for runIdx := range sRuns { + for runIdx := range s.sessionRuns { go s.debitLoop(runIdx) // Send index of the just appended sessionRun } return s