freeswitch.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. ###################
  2. Freeswitch install
  3. ###################
  4. |
  5. | **Upgrade Move Source**
  6. ::
  7. mv /usr/src/freeswitch freeswitch-version
  8. | **Git Release**
  9. ::
  10. cd /usr/src
  11. git clone -b v1.6 https://freeswitch.org/stash/scm/fs/freeswitch.git
  12. cd freeswitch
  13. ./bootstrap.sh
  14. | or
  15. | **Git Head**
  16. ::
  17. cd /usr/src
  18. git clone https://freeswitch.org/stash/scm/fs/freeswitch.git
  19. cd freeswitch
  20. ./bootstrap.sh
  21. | or
  22. | **files.freeswitch.org**
  23. ::
  24. cd /usr/src
  25. wget http://files.freeswitch.org/freeswitch-1.4.26.zip
  26. unzip freeswitch-1.4.26.zip
  27. cd freeswitch-1.4.26
  28. 1.4.x is considered EOL use the steps below for 1.6.x
  29. cd /usr/src
  30. wget http://files.freeswitch.org/freeswitch-1.6.20.zip
  31. unzip freeswitch-1.6.20.zip
  32. cd freeswitch-1.6.20
  33. | **Ubuntu Dependencies**
  34. ::
  35. apt-get install autoconf automake devscripts gawk g++ git-core libjpeg-dev libncurses5-dev libtool make python-dev gawk pkg-config libtiff-dev libperl-dev libgdbm-dev libdb-dev gettext libssl-dev libcurl4-openssl-dev libpcre3-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libedit-dev libldns-dev libpq-dev memcached libmemcached-dev
  36. | **Debian Dependencies**
  37. ::
  38. apt-get install autoconf automake devscripts gawk g++ git-core libjpeg-dev libncurses5-dev libtool libtool-bin make python-dev gawk pkg-config libtiff5-dev libperl-dev libgdbm-dev libdb-dev gettext libssl-dev libcurl4-openssl-dev libpcre3-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libedit-dev libldns-dev libpq-dev memcached libmemcached-dev
  39. | **CentOS**
  40. ::
  41. yum install git gcc-c++ autoconf automake libtool wget python ncurses-devel zlib-devel libjpeg-devel openssl-devel e2fsprogs-devel sqlite-devel libcurl-devel pcre-devel speex-devel ldns-devel libedit-devel libmemcached-devel
  42. | Configure services to auto start
  43. ::
  44. chkconfig --add memcached && chkconfig --levels 33 memcached on
  45. chkconfig --add freeswitch && chkconfig --levels 35 freeswitch on
  46. | **modules.conf**
  47. | uncomment the FreeSWITCH modules that are needed.
  48. ::
  49. mod_avmd
  50. mod_callcenter
  51. mod_memcache
  52. mod_cidlookup
  53. mod_curl
  54. mod_translate
  55. | Used for MP3 support
  56. ::
  57. mod_shout
  58. | **Postgres driver**
  59. ::
  60. ./configure --enable-core-pgsql-support
  61. | **Run Make**
  62. ::
  63. make
  64. | **Remove FreeSWITCH files**
  65. | This step is only needed for a FreeSWITCH upgrade.
  66. | Once it has been confirmed that the compile was successful then remove files from previous version of FreeSWITCH
  67. ::
  68. rm -rf /usr/local/freeswitch/{lib,mod,bin}/*
  69. | **Install**
  70. ::
  71. make install
  72. | **File Permissions**
  73. | Set the file permissions instructions may vary based on the OS and install directory.
  74. | Debian and Ubuntu
  75. ::
  76. chown -R www-data:www-data /usr/local/freeswitch
  77. | CentOS or Other Unix operating systems
  78. | (need make sure that the web server has access to IVR recordings, Fax, and Voicemail)
  79. ::
  80. adduser --disabled-password --quiet --system --home /usr/local/freeswitch --gecos "FreeSWITCH Voice Platform" --ingroup daemon freeswitch
  81. chown -R freeswitch:daemon /usr/local/freeswitch/
  82. chmod -R o-rwx /usr/local/freeswitch/
  83. | **Install Sound Files**
  84. | Run this on new installs.
  85. ::
  86. cd /usr/src/freeswitch
  87. make sounds-install moh-install
  88. make hd-sounds-install hd-moh-install
  89. make cd-sounds-install cd-moh-install
  90. **Startup Script**
  91. | Run on new install only. Create the file '/etc/init.d/freeswitch' with the following code:
  92. ::
  93. #!/bin/bash
  94. ### BEGIN INIT INFO
  95. # Provides: freeswitch
  96. # Required-Start: $local_fs $remote_fs
  97. # Required-Stop: $local_fs $remote_fs
  98. # Default-Start: 2 3 4 5
  99. # Default-Stop: 0 1 6
  100. # Description: Freeswitch debian init script.
  101. # Author: Matthew Williams
  102. #
  103. ### END INIT INFO
  104. # Do NOT "set -e"
  105. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  106. PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
  107. DESC="Freeswitch"
  108. NAME=freeswitch
  109. DAEMON=/usr/local/freeswitch/bin/$NAME
  110. DAEMON_ARGS="-nc -nonat -reincarnate"
  111. PIDFILE=/usr/local/freeswitch/run/$NAME.pid
  112. SCRIPTNAME=/etc/init.d/$NAME
  113. FS_USER=www-data #freeswitch
  114. FS_GROUP=www-data #daemon
  115. # Exit if the package is not installed
  116. [ -x "$DAEMON" ] || exit 0
  117. # Read configuration variable file if it is present
  118. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  119. # Load the VERBOSE setting and other rcS variables
  120. . /lib/init/vars.sh
  121. # Define LSB log_* functions.
  122. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  123. . /lib/lsb/init-functions
  124. #
  125. # Function that sets ulimit values for the daemon
  126. #
  127. do_setlimits() {
  128. ulimit -c unlimited
  129. ulimit -d unlimited
  130. ulimit -f unlimited
  131. ulimit -i unlimited
  132. ulimit -n 999999
  133. ulimit -q unlimited
  134. ulimit -u unlimited
  135. ulimit -v unlimited
  136. ulimit -x unlimited
  137. ulimit -s 240
  138. ulimit -l unlimited
  139. return 0
  140. }
  141. #
  142. # Function that starts the daemon/service
  143. #
  144. do_start()
  145. {
  146. # Set user to run as
  147. if [ $FS_USER ] ; then
  148. DAEMON_ARGS="`echo $DAEMON_ARGS` -u $FS_USER"
  149. fi
  150. # Set group to run as
  151. if [ $FS_GROUP ] ; then
  152. DAEMON_ARGS="`echo $DAEMON_ARGS` -g $FS_GROUP"
  153. fi
  154. # Return
  155. # 0 if daemon has been started
  156. # 1 if daemon was already running
  157. # 2 if daemon could not be started
  158. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null -- \
  159. || return 1
  160. do_setlimits
  161. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --background -- \
  162. $DAEMON_ARGS \
  163. || return 2
  164. # Add code here, if necessary, that waits for the process to be ready
  165. # to handle requests from services started subsequently which depend
  166. # on this one. As a last resort, sleep for some time.
  167. }
  168. #
  169. # Function that stops the daemon/service
  170. #
  171. do_stop()
  172. {
  173. # Return
  174. # 0 if daemon has been stopped
  175. # 1 if daemon was already stopped
  176. # 2 if daemon could not be stopped
  177. # other if a failure occurred
  178. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  179. RETVAL="$?"
  180. [ "$RETVAL" = 2 ] && return 2
  181. # Wait for children to finish too if this is a daemon that forks
  182. # and if the daemon is only ever run from this initscript.
  183. # If the above conditions are not satisfied then add some other code
  184. # that waits for the process to drop all resources that could be
  185. # needed by services started subsequently. A last resort is to
  186. # sleep for some time.
  187. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  188. [ "$?" = 2 ] && return 2
  189. # Many daemons don't delete their pidfiles when they exit.
  190. rm -f $PIDFILE
  191. return "$RETVAL"
  192. }
  193. #
  194. # Function that sends a SIGHUP to the daemon/service
  195. #
  196. do_reload() {
  197. #
  198. # If the daemon can reload its configuration without
  199. # restarting (for example, when it is sent a SIGHUP),
  200. # then implement that here.
  201. #
  202. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  203. return 0
  204. }
  205. case "$1" in
  206. start)
  207. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  208. do_start
  209. case "$?" in
  210. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  211. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  212. esac
  213. ;;
  214. stop)
  215. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  216. do_stop
  217. case "$?" in
  218. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  219. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  220. esac
  221. ;;
  222. status)
  223. status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
  224. ;;
  225. #reload|force-reload)
  226. #
  227. # If do_reload() is not implemented then leave this commented out
  228. # and leave 'force-reload' as an alias for 'restart'.
  229. #
  230. #log_daemon_msg "Reloading $DESC" "$NAME"
  231. #do_reload
  232. #log_end_msg $?
  233. #;;
  234. restart|force-reload)
  235. #
  236. # If the "reload" option is implemented then remove the
  237. # 'force-reload' alias
  238. #
  239. log_daemon_msg "Restarting $DESC" "$NAME"
  240. do_stop
  241. case "$?" in
  242. 0|1)
  243. do_start
  244. case "$?" in
  245. 0) log_end_msg 0 ;;
  246. 1) log_end_msg 1 ;; # Old process is still running
  247. *) log_end_msg 1 ;; # Failed to start
  248. esac
  249. ;;
  250. *)
  251. # Failed to stop
  252. log_end_msg 1
  253. ;;
  254. esac
  255. ;;
  256. *)
  257. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  258. echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  259. exit 3
  260. ;;
  261. esac
  262. exit 0
  263. Make the script executable and make it auto start on system boot:
  264. ::
  265. chmod +x /etc/init.d/freeswitch
  266. update-rc.d freeswitch defaults
  267. |
  268. Monit
  269. ------
  270. Used to monitor processes on UNIX systems.
  271. http://mmonit.com/monit/
  272. Install
  273. ^^^^^^^^^
  274. ::
  275. apt-get install monit
  276. Edit Monit /etc/default/monit and set the "startup" variable to 1 in order to allow monit to start.
  277. Configure
  278. ^^^^^^^^^^
  279. Fail2Ban
  280. ~~~~~~~~~~
  281. ::
  282. cd /etc/monit.d
  283. touch fail2ban
  284. nano fail2ban
  285. Add the following to the file and save it.
  286. ::
  287. check process fail2ban with pidfile /var/run/fail2ban/fail2ban.pid
  288. group services
  289. start program = "/etc/init.d/fail2ban start"
  290. stop program = "/etc/init.d/fail2ban stop"
  291. if 5 restarts within 5 cycles then timeout
  292. SIP
  293. ~~~~~
  294. To monitor SIP from local or remote server
  295. ::
  296. cd /etc/monit.d
  297. touch sip
  298. nano sip
  299. ::
  300. check host fusionpbx with address your-ip
  301. if failed port 5060 protocol sip with target monit@monit:5060
  302. then alert
  303. FreeSWITCH
  304. ~~~~~~~~~~~~
  305. ::
  306. cd /etc/monit/conf.d
  307. or
  308. ::
  309. cd /etc/monit.d
  310. touch freeswitch
  311. nano freeswitch
  312. Add the following
  313. ::
  314. #check process freeswitch with pidfile /usr/local/freeswitch/run/freeswitch.pid
  315. check process freeswitch with pidfile /run/freeswitch/freeswitch.pid
  316. start program = "/usr/bin/service freeswitch start"
  317. stop program = "/usr/bin/service freeswitch stop"
  318. or
  319. ::
  320. #check process freeswitch with pidfile /usr/local/freeswitch/run/freeswitch.pid
  321. #start program = "/usr/local/freeswitch/bin/./freeswitch -nc -u www-data"
  322. #stop program = "/usr/local/freeswitch/bin/./freeswitch -stop"
  323. check process freeswitch with pidfile /run/freeswitch/freeswitch.pid
  324. start program = "/usr/bin/./freeswitch -nc -u www-data"
  325. stop program = "/usr/bin/./freeswitch -stop"
  326. Additional Options
  327. ~~~~~~~~~~~~~~~~~~~
  328. ::
  329. if 5 restarts within 5 cycles then timeout
  330. if cpu > 60% for 2 cycles then alert
  331. if cpu > 80% for 5 cycles then alert
  332. if totalmem > 2000.0 MB for 5 cycles then restart
  333. if children > 2500 then restart
  334. Monit Daemon Add to the main monit config file.
  335. ::
  336. #monit daemon
  337. set httpd port 2812 and
  338. use address localhost
  339. allow localhost
  340. Monit Commands
  341. ~~~~~~~~~~~~~~~
  342. ::
  343. monit -h
  344. monit status