diff --git a/apier/apier_local_test.go b/apier/apier_local_test.go index 2bdf298ca..006791019 100644 --- a/apier/apier_local_test.go +++ b/apier/apier_local_test.go @@ -76,9 +76,6 @@ func TestCreateDirs(t *testing.T) { if err := os.RemoveAll(pathDir); err != nil { t.Fatal("Error removing folder: ", pathDir, err) } - if err := os.MkdirAll(pathDir, 0755); err != nil { - t.Fatal("Error creating folder: ", pathDir, err) - } } } diff --git a/apier/tutfscsv_local_test.go b/apier/tutfscsv_local_test.go index cb3b95598..bf66d3db7 100644 --- a/apier/tutfscsv_local_test.go +++ b/apier/tutfscsv_local_test.go @@ -41,7 +41,8 @@ func init() { fscsvCfg, _ = config.NewCGRConfig(&fscsvCfgPath) } -func TestFsCsvCreateDirs(t *testing.T) { +// Remove here so they can be properly created by init script +func TestFsCsvRemoveDirs(t *testing.T) { if !*testLocal { return } @@ -49,9 +50,6 @@ func TestFsCsvCreateDirs(t *testing.T) { if err := os.RemoveAll(pathDir); err != nil { t.Fatal("Error removing folder: ", pathDir, err) } - if err := os.MkdirAll(pathDir, 0755); err != nil { - t.Fatal("Error creating folder: ", pathDir, err) - } } } @@ -102,18 +100,27 @@ func TestFsCsvInitDataDb(t *testing.T) { } } +func TestFsCsvStartFs(t *testing.T) { + if !*testLocal { + return + } + exec.Command("pkill", "freeswitch").Run() // Just to make sure another one is not running, bit brutal maybe we can fine tune it + go func() { + fs := exec.Command("/usr/share/cgrates/tutorials/fs_csv/freeswitch/etc/init.d/freeswitch", "start") + out, _ := fs.CombinedOutput() + engine.Logger.Info(fmt.Sprintf("CgrEngine-TestFsCsv: %s", out)) + }() + time.Sleep(time.Duration(*waitFs) * time.Millisecond) // Give time to rater to fire up +} + // Finds cgr-engine executable and starts it with default configuration func TestFsCsvStartEngine(t *testing.T) { if !*testLocal { return } - enginePath, err := exec.LookPath("cgr-engine") - if err != nil { - t.Fatal("Cannot find cgr-engine executable") - } exec.Command("pkill", "cgr-engine").Run() // Just to make sure another one is not running, bit brutal maybe we can fine tune it go func() { - eng := exec.Command(enginePath, "-config", fscsvCfgPath) + eng := exec.Command("/usr/share/cgrates/tutorials/fs_json/cgrates/etc/init.d/cgrates", "start") out, _ := eng.CombinedOutput() engine.Logger.Info(fmt.Sprintf("CgrEngine-TestFsCsv: %s", out)) }() @@ -267,5 +274,20 @@ func TestFsCsvStopEngine(t *testing.T) { if !*testLocal { return } - exec.Command("pkill", "cgr-engine").Run() + go func() { + eng := exec.Command("/usr/share/cgrates/tutorials/fs_csv/cgrates/etc/init.d/cgrates", "stop") + out, _ := eng.CombinedOutput() + engine.Logger.Info(fmt.Sprintf("CgrEngine-TestFsCsv: %s", out)) + }() +} + +func TestFsCsvStopFs(t *testing.T) { + if !*testLocal { + return + } + go func() { + fs := exec.Command("/usr/share/cgrates/tutorials/fs_csv/freeswitch/etc/init.d/freeswitch", "stop") + out, _ := fs.CombinedOutput() + engine.Logger.Info(fmt.Sprintf("CgrEngine-TestFsCsv: %s", out)) + }() } diff --git a/apier/tutfsjson_local_test.go b/apier/tutfsjson_local_test.go index 6d609a967..5219fb8ed 100644 --- a/apier/tutfsjson_local_test.go +++ b/apier/tutfsjson_local_test.go @@ -19,6 +19,7 @@ along with this program. If not, see package apier import ( + "flag" "fmt" "net/rpc/jsonrpc" "os" @@ -36,22 +37,22 @@ import ( var fsjsonCfgPath string var fsjsonCfg *config.CGRConfig +var waitFs = flag.Int("wait_fs", 1000, "Number of miliseconds to wait for FreeSWITCH to start") + func init() { fsjsonCfgPath = path.Join(*dataDir, "tutorials", "fs_json", "cgrates", "etc", "cgrates", "cgrates.cfg") fsjsonCfg, _ = config.NewCGRConfig(&fsjsonCfgPath) } -func TestFsJsonCreateDirs(t *testing.T) { +// Remove here so they can be properly created by init script +func TestFsJsonRemoveDirs(t *testing.T) { if !*testLocal { return } - for _, pathDir := range []string{cfg.CdreDir, cfg.HistoryDir} { + for _, pathDir := range []string{fsjsonCfg.CdreDir, fsjsonCfg.HistoryDir} { if err := os.RemoveAll(pathDir); err != nil { t.Fatal("Error removing folder: ", pathDir, err) } - if err := os.MkdirAll(pathDir, 0755); err != nil { - t.Fatal("Error creating folder: ", pathDir, err) - } } } @@ -102,18 +103,27 @@ func TestFsJsonInitDataDb(t *testing.T) { } } +func TestFsJsonStartFs(t *testing.T) { + if !*testLocal { + return + } + exec.Command("pkill", "freeswitch").Run() // Just to make sure another one is not running, bit brutal maybe we can fine tune it + go func() { + fs := exec.Command("/usr/share/cgrates/tutorials/fs_json/freeswitch/etc/init.d/freeswitch", "start") + out, _ := fs.CombinedOutput() + engine.Logger.Info(fmt.Sprintf("CgrEngine-TestFsJson: %s", out)) + }() + time.Sleep(time.Duration(*waitFs) * time.Millisecond) // Give time to rater to fire up +} + // Finds cgr-engine executable and starts it with default configuration func TestFsJsonStartEngine(t *testing.T) { if !*testLocal { return } - enginePath, err := exec.LookPath("cgr-engine") - if err != nil { - t.Fatal("Cannot find cgr-engine executable") - } exec.Command("pkill", "cgr-engine").Run() // Just to make sure another one is not running, bit brutal maybe we can fine tune it go func() { - eng := exec.Command(enginePath, "-config", fsjsonCfgPath) + eng := exec.Command("/usr/share/cgrates/tutorials/fs_json/cgrates/etc/init.d/cgrates", "start") out, _ := eng.CombinedOutput() engine.Logger.Info(fmt.Sprintf("CgrEngine-TestFsJson: %s", out)) }() @@ -196,5 +206,20 @@ func TestFsJsonStopEngine(t *testing.T) { if !*testLocal { return } - exec.Command("pkill", "cgr-engine").Run() + go func() { + eng := exec.Command("/usr/share/cgrates/tutorials/fs_json/cgrates/etc/init.d/cgrates", "stop") + out, _ := eng.CombinedOutput() + engine.Logger.Info(fmt.Sprintf("CgrEngine-TestFsJson: %s", out)) + }() +} + +func TestFsJsonStopFs(t *testing.T) { + if !*testLocal { + return + } + go func() { + fs := exec.Command("/usr/share/cgrates/tutorials/fs_json/freeswitch/etc/init.d/freeswitch", "stop") + out, _ := fs.CombinedOutput() + engine.Logger.Info(fmt.Sprintf("CgrEngine-TestFsJson: %s", out)) + }() } diff --git a/data/tutorials/fs_csv/cgrates/etc/init.d/cgrates b/data/tutorials/fs_csv/cgrates/etc/init.d/cgrates index 061df46e3..730a8c17a 100755 --- a/data/tutorials/fs_csv/cgrates/etc/init.d/cgrates +++ b/data/tutorials/fs_csv/cgrates/etc/init.d/cgrates @@ -14,18 +14,24 @@ # Do NOT "set -e" # PATH should only include /usr/* if it runs after the mountnfs.sh script +RUNDIR=/tmp/$NAME/run +PIDFILE=$RUNDIR/cgr-engine.pid PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="CGRateS real-time charging system" NAME=cgrates DAEMON=/usr/bin/cgr-engine USER=cgrates GROUP=cgrates -TUTFOLDER=/usr/share/cgrates/tutorials/fs_csv/cgrates +TUTFOLDER=/usr/share/cgrates/tutorials/fs_json/cgrates ENGINE_OPTS=-config=$TUTFOLDER/etc/cgrates/cgrates.cfg -PIDFILE=/tmp/cgr-engine_tutfscsv.pid +PIDFILE=/tmp/cgr-engine_tutfsjson.pid SCRIPTNAME=$TUTFOLDER/etc/init.d/$NAME DEFAULTS=$TUTFOLDER/etc/default/$NAME ENABLE=false +HISTDIR=/tmp/$NAME/history +CDREDIR=/tmp/$NAME/cdre +CDRCINDIR=/tmp/$NAME/cdr/cdrc/in +CDRCOUTDIR=/tmp/cgrates/cdr/cdrc/out # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 @@ -46,6 +52,30 @@ if [ "$ENABLE" != "true" ]; then exit 0 fi +# Install the run folder +if [ ! -d $RUNDIR ]; then + mkdir -p $RUNDIR + chown $USER:$GROUP $RUNDIR +fi +# Install the cdre folder +if [ ! -d $CDREDIR ]; then + mkdir -p $CDREDIR + chown $USER:$GROUP $CDREDIR +fi +# Install the history folder +if [ ! -d $HISTDIR ]; then + mkdir -p $HISTDIR + chown $USER:$GROUP $HISTDIR +fi +if [ ! -d $CDRCINDIR ]; then + mkdir -p $CDRCINDIR + chown $USER:$GROUP $CDRCINDIR +fi +if [ ! -d $CDRCOUTDIR ]; then + mkdir -p $CDRCOUTDIR + chown $USER:$GROUP $CDRCOUTDIR +fi + # # Function that starts the daemon/service diff --git a/data/tutorials/fs_json/cgrates/etc/init.d/cgrates b/data/tutorials/fs_json/cgrates/etc/init.d/cgrates index e6c27e56f..54bbb073b 100755 --- a/data/tutorials/fs_json/cgrates/etc/init.d/cgrates +++ b/data/tutorials/fs_json/cgrates/etc/init.d/cgrates @@ -14,6 +14,8 @@ # Do NOT "set -e" # PATH should only include /usr/* if it runs after the mountnfs.sh script +RUNDIR=/tmp/$NAME/run +PIDFILE=$RUNDIR/cgr-engine.pid PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="CGRateS real-time charging system" NAME=cgrates @@ -26,6 +28,8 @@ PIDFILE=/tmp/cgr-engine_tutfsjson.pid SCRIPTNAME=$TUTFOLDER/etc/init.d/$NAME DEFAULTS=$TUTFOLDER/etc/default/$NAME ENABLE=false +HISTDIR=/tmp/$NAME/history +CDREDIR=/tmp/$NAME/cdre # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 @@ -46,6 +50,22 @@ if [ "$ENABLE" != "true" ]; then exit 0 fi +# Install the run folder +if [ ! -d $RUNDIR ]; then + mkdir -p $RUNDIR + chown $USER:$GROUP $RUNDIR +fi +# Install the cdre folder +if [ ! -d $CDREDIR ]; then + mkdir -p $CDREDIR + chown $USER:$GROUP $CDREDIR +fi +# Install the history folder +if [ ! -d $HISTDIR ]; then + mkdir -p $HISTDIR + chown $USER:$GROUP $HISTDIR +fi + # # Function that starts the daemon/service