Skip to content

davidcsi/FreeSWITCH-Billing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

#
#Note: 
#     This installation example is based on a "Turnkey LAMP" appliance 
#     running on a VM. The same step should apply to a freshly installed 
#     debian/ubuntu.
#     If installing on a new debian/ubuntu, you will need to install and 
#     configure Apache2 and MySQL.
#
#
#Atfter finishing you LAMP installation:
#
#Prepare pre-requisites:
     apt-get update &&
     apt-get install git-core build-essential autoconf automake libtool libncurses5 libncurses5-dev make \
                    libjpeg-dev pkg-config unixodbc unixodbc-dev zlib1g-dev \
                    libcurl4-openssl-dev libexpat1-dev libssl-dev libtiff4-dev libx11-dev unixodbc-dev \
                    python2.6-dev zlib1g-dev libzrtpcpp-dev libasound2-dev libogg-dev libvorbis-dev libperl-dev \
                    libgdbm-dev libdb-dev python-dev uuid-dev bison autoconf g++ libncurses-dev libdb-dev \
                    libgdbm-dev lua5.1 liblua5.1-sql-mysql-2 dos2unix

                    
#Get the source code:

     cd /usr/local/src &&
     git clone git://git.freeswitch.org/freeswitch.git &&
     cd freeswitch &&
     ./bootstrap.sh

#edit modules.conf and UNcomment:

     sed -i "/mod_distributor/ s/#*//" modules.conf 
     sed -i "/mod_esl/ s/#*//" modules.conf
     sed -i "/xml_int\/mod_xml_curl/ s/#*//" modules.conf

#And Compile:

     ./configure && make all install cd-sounds-install cd-moh-install

# create init scripts

echo '#! /bin/sh
### BEGIN INIT INFO
# Provides:          freeswitch
# Required-Start:    $network $local_fs $remote_fs
# Required-Stop:     $network $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: The FreeSWITCH Voice Switching System
# Description:       An advanced platform for voice services
### END INIT INFO

# Author: Anthony Minesalle II <[email protected]>
#

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/freeswitch/bin
DESC="FreeSWITCH Voice Switching System"
NAME=freeswitch
DAEMON=/usr/local/freeswitch/bin/$NAME
USER=freeswitch
PIDFILE=/usr/local/freeswitch/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
WORKDIR=/usr/local/$NAME

# Check if we are being executed by init

CALLEDSCRIPT=`basename $0`

if [ -r /etc/default/$NAME ]; then . /etc/default/$NAME; fi

if [ "$FREESWITCH_ENABLED" != "true" ]; then
    echo "$DESC not enabled yet. Edit /etc/default/$NAME first."
    exit 0 ;
fi

# Exit if the package is not installed
# [ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that sets ulimit values for the daemon
#
do_setlimits() {
        ulimit -c unlimited
        ulimit -d unlimited
        ulimit -f unlimited
#        ulimit -i unlimited
        ulimit -n 999999
#        ulimit -q unlimited
#        ulimit -u unlimited
        ulimit -v unlimited
#        ulimit -x unlimited
        ulimit -s 240
        ulimit -l unlimited
        return 0
}

#
# 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 -d $WORKDIR -c $USER --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
		|| return 1
	do_setlimits
	start-stop-daemon -d $WORKDIR -c $USER --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
		$FREESWITCH_PARAMS \
		|| return 2
	# Add code here, if necessary, that waits for the process to be ready
	# to handle requests from services started subsequently which depend
	# on this one.  As a last resort, sleep for some time.
}

#
# 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
	$DAEMON -stop
	start-stop-daemon -d $WORKDIR -c $USER --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 -d $WORKDIR -c $USER --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 -c $USER --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
	;;
  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)
	#
	# If the "reload" usr/localion 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|restart|reload|force-reload}" >&2
	#echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
	exit 3
	;;
esac' > /etc/init.d/freeswitch

ln -s /usr/local/freeswitch/conf /etc/freeswitch
     
     echo '# Startup settings for FreeSWITCH
# Enable initd (let init handle start and stop of freeswitch).
# Set to "true" (lowercase) to enable.

FREESWITCH_ENABLED="true"

# The parameters Freeswitch should be started with

FREESWITCH_PARAMS="-nc"' > /etc/default/freeswitch
     
     adduser --disabled-password  --quiet --system --home /usr/local/freeswitch --gecos "FreeSWITCH Voice Platform" --ingroup daemon freeswitch
     chown -R freeswitch:daemon /usr/local/freeswitch/
     chmod -R o-rwx /usr/local/freeswitch/
     
     update-rc.d freeswitch defaults

#The freeSWITCH installation will be finished after this.
#
#************************************************************************************************************
#
#We need the ESL module for perl, so compile it:

     cd /usr/local/src/freeswitch/libs/esl/
     make perlmod
     make perlmod-install (*)

     (*) If the "make perlmod-install" command fails with 
         "install: cannot create regular file `/usr/local/share/perl/5.10.1': No such file or directory"
         You need to edit /usr/local/src/freeswitch/libs/esl/perl/Makefile and set PERL_SITEDIR to perl's correct path,
         in my case it was PERL_SITEDIR="/usr/share/perl/5.10.1/", and execute again. 

#Get Viking's source code:

     cd /home/$USER/
     git://github.com/davidcsi/FreeSWITCH-Billing.git
     cd FreeSWITCH-Billing

#Prepare Viking's db backend, add "viking" user and import the db structure:

     echo "create database viking" | mysql -u root -p[root db password]                         
     echo "CREATE USER 'viking'@'localhost' IDENTIFIED BY 'V1k1ng';GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, FILE, INDEX, ALTER, SUPER, CREATE TEMPORARY TABLES, CREATE VIEW, EVENT, TRIGGER, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EXECUTE ON *.* TO 'viking'@'localhost' IDENTIFIED BY 'V1k1ng' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;" | mysql -u root -p
     gunzip viking_db.sql.gz 
     mysql -u viking -pV1k1ng viking < viking_db.sql 

#Unpack the web GUI and copy it over to the server's www:
     tar -xvzf viking_web.tar.gz
     mv cdrpost /var/www/
     mv fsxml /var/www/        
     mv webint /var/www/      

edit /etc/hosts and add:

     echo "127.0.0.1  viking_db" >> /etc/hosts
     echo "127.0.0.1       fs" >> /etc/hosts

#REMOVE:

     rm /usr/local/freeswitch/conf/autoload_configs/sofia.conf.xml
     rm /usr/local/freeswitch/conf/autoload_configs/distributor.conf.xml
     rm /usr/local/freeswitch/conf/autoload_configs/dialplan_directory.conf.xml

#Create directories for freeswitch's logs

     mkdir /var/log/freeswitch
     mkdir /var/log/freeswitch/errors 

#Edit /usr/local/freeswitch/conf/autoload_configs/xml_cdr.conf.xml and uncomment and set:

     <param name="url" value="http://viking_db/cdrpost/post.php"/>
     <param name="retries" value="5"/>
     <param name="delay" value="5"/>
     <param name="log-b-leg" value="false"/>
     <param name="log-dir" value="/var/log/freeswitch"/>
     <param name="err-log-dir" value="/var/log/freeswitch/errors"/>

#Try to go into [SERVER_IP]/webint using admin/admin
#
#************************************************************************************************************

#make a link to fs_cli from /usr/bin, will save you a lot of typing...

     ln -s /usr/local/freeswitch/bin/fs_cli /usr/bin/fs_cli

#Start freeSWITCH, I like to start it in "screen":

     screen -S fs
     ulimit -s 240 && /usr/local/freeswitch/bin/freeswitch -nc

     To exit press: CTRL+A CTRL+D

#Unzip the scripts file:

     mkdir /opt/fs-viking
     mv viking_script.zip /opt/fs-viking/.
     cd /opt/fs-viking/
     unzip viking_script.zip

#and copy FS's scripts to viking's folder:

     mv /opt/fs-viking/*.lua /usr/local/freeswitch/scripts/.

#Now, create a link to lua's mysql.so:

     mkdir /usr/bin/luasql
     ln -s /usr/bin/luasql /usr/local/freeswitch/scripts/luasql
     ln -s /usr/lib/liblua5.1-sql-mysql.so.2.0.0 /usr/bin/luasql/mysql.so

#Uncomment in /usr/local/freeswitch/conf/autoload_configs/modules.conf.xml 

     <load module="mod_xml_cdr"/>
     <load module="mod_distributor"/>
     
#Edit and set in /usr/local/freeswitch/conf/autoload_configs/lua.conf.xml the following: 

    <param name="module-directory" value="/usr/lib/lua/5.1/?.so"/>
    <param name="module-directory" value="/usr/bin/luasql/?.so"/>
     
         
Mark the scripts as executable: 

     chmod +x /opt/fs-viking/*

# I found that sometimes the format on the files is in DOS, so fix that with

     dos2unix /opt/fs-viking/*
     

#To create initial config, execute: 
     
     /opt/fs-viking/freeswitch_reload_config.pl DUMMY XML


To start the scripts that reload FS configs and ongoing calls:

     And add to crontab
     # m h  dom mon dow   command
     * * * * *       /opt/fs-viking/watchdog_viking_reload.sh
     * * * * *       /opt/fs-viking/watchdog_viking_get_calls.sh



About

Billing for freeSWITCH

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages