From 0924f4104c081ada10d5dfd9ebe107654997d350 Mon Sep 17 00:00:00 2001 From: DanB Date: Sat, 11 Jan 2014 16:41:06 +0100 Subject: [PATCH] Fixup loader to take from datadir, adding tutorials/fs_csv/cgrates configurations --- cmd/cgr-loader/cgr-loader.go | 16 +- .../fs_csv/cgrates/etc/cgrates/cgrates.cfg | 116 +++++++++++++ .../fs_csv/cgrates/etc/default/cgrates | 17 ++ .../fs_csv/cgrates/etc/init.d/cgrates | 162 ++++++++++++++++++ pkg/debian/cgrates.default | 8 +- 5 files changed, 312 insertions(+), 7 deletions(-) create mode 100644 data/tutorials/fs_csv/cgrates/etc/cgrates/cgrates.cfg create mode 100644 data/tutorials/fs_csv/cgrates/etc/default/cgrates create mode 100755 data/tutorials/fs_csv/cgrates/etc/init.d/cgrates diff --git a/cmd/cgr-loader/cgr-loader.go b/cmd/cgr-loader/cgr-loader.go index b51afdb40..6293b993d 100644 --- a/cmd/cgr-loader/cgr-loader.go +++ b/cmd/cgr-loader/cgr-loader.go @@ -61,7 +61,7 @@ var ( flush = flag.Bool("flushdb", false, "Flush the database before importing") tpid = flag.String("tpid", "", "The tariff plan id from the database") - dataPath = flag.String("path", ".", "The path to folder containing the data files") + dataPath = flag.String("path", "./", "The path to folder containing the data files") version = flag.Bool("version", false, "Prints the application version.") verbose = flag.Bool("verbose", false, "Enable detailed verbose logging output") dryRun = flag.Bool("dry_run", false, "When true will not save loaded data to dataDb but just parse it for consistency and errors.") @@ -132,8 +132,18 @@ func main() { log.Fatal(err, "\n\t", v.Message) } } - loader = engine.NewFileCSVReader(ratingDb, accountDb, ',', utils.DESTINATIONS_CSV, utils.TIMINGS_CSV, utils.RATES_CSV, utils.DESTINATION_RATES_CSV, utils.RATING_PLANS_CSV, utils.RATING_PROFILES_CSV, utils.ACTIONS_CSV, utils.ACTION_TIMINGS_CSV, utils.ACTION_TRIGGERS_CSV, utils.ACCOUNT_ACTIONS_CSV) - } + loader = engine.NewFileCSVReader(ratingDb, accountDb, ',', + path.Join(*dataPath, utils.DESTINATIONS_CSV), + path.Join(*dataPath, utils.TIMINGS_CSV), + path.Join(*dataPath, utils.RATES_CSV), + path.Join(*dataPath, utils.DESTINATION_RATES_CSV), + path.Join(*dataPath, utils.RATING_PLANS_CSV), + path.Join(*dataPath, utils.RATING_PROFILES_CSV), + path.Join(*dataPath, utils.ACTIONS_CSV), + path.Join(*dataPath, utils.ACTION_TIMINGS_CSV), + path.Join(*dataPath, utils.ACTION_TRIGGERS_CSV), + path.Join(*dataPath, utils.ACCOUNT_ACTIONS_CSV)) + } err = loader.LoadAll() if err != nil { log.Fatal(err) diff --git a/data/tutorials/fs_csv/cgrates/etc/cgrates/cgrates.cfg b/data/tutorials/fs_csv/cgrates/etc/cgrates/cgrates.cfg new file mode 100644 index 000000000..a5ccac8c6 --- /dev/null +++ b/data/tutorials/fs_csv/cgrates/etc/cgrates/cgrates.cfg @@ -0,0 +1,116 @@ +# CGRateS Configuration file +# +# This file contains the default configuration hardcoded into CGRateS. +# This is what you get when you load CGRateS with an empty configuration file. +# [global] must exist in all files, rest of the configuration is inter-changeable. + +[global] +# ratingdb_type = redis # Rating subsystem database: . +# ratingdb_host = 127.0.0.1 # Rating subsystem database host address. +# ratingdb_port = 6379 # Rating subsystem port to reach the database. +# ratingdb_name = 10 # Rating subsystem database name to connect to. +# ratingdb_user = # Rating subsystem username to use when connecting to database. +# ratingdb_passwd = # Rating subsystem password to use when connecting to database. +# accountdb_type = redis # Accounting subsystem database: . +# accountdb_host = 127.0.0.1 # Accounting subsystem database host address. +# accountdb_port = 6379 # Accounting subsystem port to reach the database. +# accountdb_name = 11 # Accounting subsystem database name to connect to. +# accountdb_user = # Accounting subsystem username to use when connecting to database. +# accountdb_passwd = # Accounting subsystem password to use when connecting to database. +# stordb_type = mysql # Stor database type to use: +# stordb_host = 127.0.0.1 # The host to connect to. Values that start with / are for UNIX domain sockets. +# stordb_port = 3306 # The port to reach the logdb. +# stordb_name = cgrates # The name of the log database to connect to. +# stordb_user = cgrates # Username to use when connecting to stordb. +# stordb_passwd = CGRateS.org # Password to use when connecting to stordb. +# dbdata_encoding = msgpack # The encoding used to store object data in strings: +# rpc_encoding = json # RPC encoding used on APIs: . +# default_reqtype = rated # Default request type to consider when missing from requests: <""|prepaid|postpaid|pseudoprepaid|rated>. +# default_tor = 0 # Default Type of Record to consider when missing from requests. +# default_tenant = 0 # Default Tenant to consider when missing from requests. +# default_subject = 0 # Default rating Subject to consider when missing from requests. +# rounding_method = *middle # Rounding method for floats/costs: <*up|*middle|*down> +# rounding_decimals = 4 # Number of decimals to round float/costs at + +[balancer] +# enabled = false # Start Balancer service: . +# listen = 127.0.0.1:2012 # Balancer listen interface: <""|x.y.z.y:1234>. + +[rater] +enabled = true # Enable RaterCDRSExportPath service: . +# balancer = disabled # Register to Balancer as worker: . +# listen = 127.0.0.1:2012 # Rater's listening interface: . + +[scheduler] +enabled = true # Starts Scheduler service: . + +[cdrs] +enabled = true # Start the CDR Server service: . +# listen=127.0.0.1:2022 # CDRS's listening interface: . +# extra_fields = # Extra fields to store in CDRs +mediator = internal # Address where to reach the Mediator. Empty for disabling mediation. <""|internal> + +[cdre] +# cdr_format = csv # Exported CDRs format +# extra_fields = # List of extra fields to be exported out in CDRs +export_dir = /tmp # Path where the exported CDRs will be placed + +[cdrc] +enabled = true # Enable CDR client functionality +# cdrs = 127.0.0.1:2022 # Address where to reach CDR server +# cdrs_method = http_cgr # Mechanism to use when posting CDRs on server +# run_delay = 0 # Sleep interval in seconds between consecutive runs, 0 to use automation via inotify +cdr_type = freeswitch_csv # CDR file format . +cdr_in_dir = /var/log/freeswitch/cdr-csv # Absolute path towards the directory where the CDRs are stored. +cdr_out_dir = /tmp # Absolute path towards the directory where processed CDRs will be moved. +cdr_source_id = freeswitch_csv # Free form field, tag identifying the source of the CDRs within CGRS database. +# accid_field = 0 # Accounting id field identifier. Use index number in case of .csv cdrs. +# reqtype_field = 1 # Request type field identifier. Use index number in case of .csv cdrs. +# direction_field = 2 # Direction field identifier. Use index numbers in case of .csv cdrs. +# tenant_field = 3 # Tenant field identifier. Use index numbers in case of .csv cdrs. +# tor_field = 4 # Type of Record field identifier. Use index numbers in case of .csv cdrs. +# account_field = 5 # Account field identifier. Use index numbers in case of .csv cdrs. +# subject_field = 6 # Subject field identifier. Use index numbers in case of .csv CDRs. +# destination_field = 7 # Destination field identifier. Use index numbers in case of .csv cdrs. +# answer_time_field = 8 # Answer time field identifier. Use index numbers in case of .csv cdrs. +# duration_field = 9 # Duration field identifier. Use index numbers in case of .csv cdrs. +# extra_fields = 10:supplier,11:orig_ip # Extra fields identifiers. For .csv, format: :[,:] + +[mediator] +enabled = true # Starts Mediator service: . +# listen=internal # Mediator's listening interface: . +# rater = 127.0.0.1:2012 # Address where to reach the Rater: +# rater_reconnects = 3 # Number of reconnects to rater before giving up. +# run_ids = # Identifiers of each extra mediation to run on CDRs +# reqtype_fields = # Name of request type fields to be used during extra mediation. Use index number in case of .csv cdrs. +# direction_fields = # Name of direction fields to be used during extra mediation. Use index numbers in case of .csv cdrs. +# tenant_fields = # Name of tenant fields to be used during extra mediation. Use index numbers in case of .csv cdrs. +# tor_fields = # Name of tor fields to be used during extra mediation. Use index numbers in case of .csv cdrs. +# account_fields = # Name of account fields to be used during extra mediation. Use index numbers in case of .csv cdrs. +# subject_fields = # Name of fields to be used during extra mediation. Use index numbers in case of .csv cdrs. +# destination_fields = # Name of destination fields to be used during extra mediation. Use index numbers in case of .csv cdrs. +# answer_time_fields = # Name of time_answer fields to be used during extra mediation. Use index numbers in case of .csv cdrs. +# duration_fields = # Name of duration fields to be used during extra mediation. Use index numbers in case of .csv cdrs. + +[session_manager] +enabled = true # Starts SessionManager service: . +# switch_type = freeswitch # Defines the type of switch behind: . +# rater = 127.0.0.1:2012 # Address where to reach the Rater. +# rater_reconnects = 3 # Number of reconnects to rater before giving up. +# debit_interval = 5 # Interval to perform debits on. + +[freeswitch] +# server = 127.0.0.1:8021 # Adress where to connect to FreeSWITCH socket. +# passwd = ClueCon # FreeSWITCH socket password. +# reconnects = 5 # Number of attempts on connect failure. + +[history_server] +enabled = true # Starts History service: . +# listen = 127.0.0.1:2013 # Listening addres for history server: +history_dir = /tmp/cgr_history # Location on disk where to store history files. +# save_interval = 1s # Interval to save changed cache into .git archive + +[history_agent] +# enabled = false # Starts History as a client: . +# server = 127.0.0.1:2013 # Address where to reach the master history server: + diff --git a/data/tutorials/fs_csv/cgrates/etc/default/cgrates b/data/tutorials/fs_csv/cgrates/etc/default/cgrates new file mode 100644 index 000000000..4e7add309 --- /dev/null +++ b/data/tutorials/fs_csv/cgrates/etc/default/cgrates @@ -0,0 +1,17 @@ +# defaults file for CGRateS real-time charging system + +# start CGRateS init.d script? +# starts with "true" +ENABLE=true + +# Start with specific user/group +#USER=cgrates +#GROUP=cgrates + +# what extra options to give cgrates binary? +# See cgr-engine -h for options +#ENGINE_OPTS='' + +# Don't forget to create an appropriate config file, +# else the CGRateS system will not start. + diff --git a/data/tutorials/fs_csv/cgrates/etc/init.d/cgrates b/data/tutorials/fs_csv/cgrates/etc/init.d/cgrates new file mode 100755 index 000000000..82e004b2c --- /dev/null +++ b/data/tutorials/fs_csv/cgrates/etc/init.d/cgrates @@ -0,0 +1,162 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: cgrates +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: CGRateS real-time charging system +# Description: Control CGRateS - carrier grade real-time charging system +### END INIT INFO + +# Author: DanB +# +# Do NOT "set -e" + +# PATH should only include /usr/* if it runs after the mountnfs.sh script +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 +ENGINE_OPTS=-config=$TUTFOLDER/etc/cgrates/cgrates.cfg +PIDFILE=/tmp/cgr-engine_tutfscsv.pid +SCRIPTNAME=$TUTFOLDER/etc/init.d/$NAME +DEFAULTS=$TUTFOLDER/etc/default/$NAME +ENABLE=false + +# 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 + +# Define LSB log_* functions. +# Depend on lsb-base (>= 3.2-14) to ensure that this file is present +# and status_of_proc is working. +. /lib/lsb/init-functions + +if [ "$ENABLE" != "true" ]; then + echo "$DESC not yet configured. Edit $DEFAULTS first." + exit 0 +fi + + +# +# Function that starts the daemon/service +# +do_start() +{ + # Return + # 0 if daemon has been started + # 1 if daemon was already running + # 2 if daemon could not be started + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ + || return 1 + start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --exec $DAEMON --chuid $USER:$GROUP --background -- \ + $ENGINE_OPTS \ + || return 2 +} + +# +# Function that stops the daemon/service +# +do_stop() +{ + # Return + # 0 if daemon has been stopped + # 1 if daemon was already stopped + # 2 if daemon could not be stopped + # other if a failure occurred + start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME + RETVAL="$?" + [ "$RETVAL" = 2 ] && return 2 + # Wait for children to finish too if this is a daemon that forks + # and if the daemon is only ever run from this initscript. + # If the above conditions are not satisfied then add some other code + # that waits for the process to drop all resources that could be + # needed by services started subsequently. A last resort is to + # sleep for some time. + start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON + [ "$?" = 2 ] && return 2 + # Many daemons don't delete their pidfiles when they exit. + rm -f $PIDFILE + return "$RETVAL" +} + +# +# Function that sends a SIGHUP to the daemon/service +# +do_reload() { + # + # If the daemon can reload its configuration without + # restarting (for example, when it is sent a SIGHUP), + # then implement that here. + # + start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME + return 0 +} + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + status) + status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + #reload|force-reload) + # + # If do_reload() is not implemented then leave this commented out + # and leave 'force-reload' as an alias for 'restart'. + # + #log_daemon_msg "Reloading $DESC" "$NAME" + #do_reload + #log_end_msg $? + #;; + restart|force-reload) + # + # If the "reload" option is implemented then remove the + # 'force-reload' alias + # + log_daemon_msg "Restarting $DESC" "$NAME" + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 ;; # Old process is still running + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 + exit 3 + ;; +esac + +: diff --git a/pkg/debian/cgrates.default b/pkg/debian/cgrates.default index a7d49cbce..4e7add309 100644 --- a/pkg/debian/cgrates.default +++ b/pkg/debian/cgrates.default @@ -2,15 +2,15 @@ # start CGRateS init.d script? # starts with "true" -ENABLE=false +ENABLE=true # Start with specific user/group -USER=cgrates -GROUP=cgrates +#USER=cgrates +#GROUP=cgrates # what extra options to give cgrates binary? # See cgr-engine -h for options -ENGINE_OPTS='' +#ENGINE_OPTS='' # Don't forget to create an appropriate config file, # else the CGRateS system will not start.