Asterisk

7 Notes
+ Apache config files (Jan. 5, 2015, 3:21 p.m.)

Contents of file: /etc/apache2/sites-enabled/000-default.conf <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html ScriptAlias /cgi-bin/ /var/cgi-bin/ <Directory "/var/cgi-bin"> AllowOverride All Options None Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> ----------------------------------------------------------------------------- Create a file named .htaccess in the /var/cgi-bin with this content. AuthType Basic AuthName "Restricted Access" AuthUserFile /var/cgi-bin/.htpasswd Require user mohsen ----------------------------------------------------------------------------- htpasswd -c /etc/apache2/.htpasswd mohsen And enter a desired password to create the password file. -----------------------------------------------------------------------------

+ Creating /etc/init.d/asterisk (Jan. 5, 2015, 12:38 p.m.)

1-cp asterisk-13.1.0/contrib/init.d/rc.debian.asterisk /etc/init.d/asterisk 2-Change the lines to these values: DAEMON=/usr/sbin/asterisk ASTVARRUNDIR=/var/run/asterisk ASTETCDIR=/etc/asterisk If you run it right now, you will get the error: Restarting asterisk (via systemctl): asterisk.serviceFailed to restart asterisk.service: Unit asterisk.service failed to load: No such file or directory. failed! I restarted the server (reboot) and after booting up it was run successfully (/etc/init.d/asterisk start)

+ Perl Packages/Libraries for Debian (Jan. 2, 2015, 10:59 a.m.)

Before starting installation, be careful that, you will need to install some packages from synaptic, and they might cause/need to install another version of `asterisk` and `asterisk-core`, and lots of other libraries, which these all might break the one you just installed! So make sure that the packages you need, should be installed via source, and not say YES to apt-get without checking the libraries! -------------------------------------------------------------------------------- 1-apt-get install libghc-ami-dev 2-Install this file `dpkg --install libasterisk-ami-perl_0.2.8-1_all.deb` If you don't have it, refer to the following link for creating this .deb file http://www.debian-administration.org/article/78/Building_Debian_packages_of_Perl_modules 3-Copy the codecs binary `codec_g729-ast130-gcc4-glibc2.2-x86_64-core2.so` to the path `/usr/lib/asterisk/modules` Rename it to `code_g729.so` and based on other modules in this directory, set the chmod and chown of the file. You can find it from this link: http://asterisk.hosting.lv/

+ Running Asterisk as a Service (Dec. 15, 2014, 1:14 p.m.)

The most common way to run Asterisk in a production environment is as a service. Asterisk includes both a make target for installing Asterisk as a service, as well as a script - live_asterisk - that will manage the service and automatically restart Asterisk in case of errors. Asterisk can be installed as a service using the make config target: # make config /etc/rc0.d/K91asterisk -> ../init.d/asterisk /etc/rc1.d/K91asterisk -> ../init.d/asterisk /etc/rc6.d/K91asterisk -> ../init.d/asterisk /etc/rc2.d/S50asterisk -> ../init.d/asterisk /etc/rc3.d/S50asterisk -> ../init.d/asterisk /etc/rc4.d/S50asterisk -> ../init.d/asterisk /etc/rc5.d/S50asterisk -> ../init.d/asterisk Asterisk can now be started as a service: # service asterisk start * Starting Asterisk PBX: asterisk [ OK ] And stopped: # service asterisk stop * Stopping Asterisk PBX: asterisk [ OK ] And restarted: # service asterisk restart * Stopping Asterisk PBX: asterisk [ OK ] * Starting Asterisk PBX: asterisk [ OK ]

+ Executing as another User (Dec. 15, 2014, 1:12 p.m.)

Do not run as root Running Asterisk as root or as a user with super user permissions is dangerous and not recommended. There are many ways Asterisk can affect the system on which it operates, and running as root can increase the cost of small configuration mistakes. Asterisk can be run as another user using the -U option: # asterisk -U asteriskuser Often, this option is specified in conjunction with the -G option, which specifies the group to run under: # asterisk -U asteriskuser -G asteriskuser When running Asterisk as another user, make sure that user owns the various directories that Asterisk will access: # sudo chown -R asteriskuser:asteriskuser /usr/lib/asterisk # sudo chown -R asteriskuser:asteriskuser /var/lib/asterisk # sudo chown -R asteriskuser:asteriskuser /var/spool/asterisk # sudo chown -R asteriskuser:asteriskuser /var/log/asterisk # sudo chown -R asteriskuser:asteriskuser /var/run/asterisk # sudo chown asteriskuser:asteriskuser /usr/sbin/asterisk

+ Commands (Dec. 15, 2014, 11:29 a.m.)

You can get a CLI (Command Line Interface) console to an already-running daemon by typing asterisk -r Another description for option '-r': In order to connect to a running Asterisk process, you can attach a remote console using the -r option ------------------------------ To disconnect from a connected remote console, simply hit Ctrl+C. ------------------------------ To shut down Asterisk, issue: core stop gracefully ------------------------------ There are three common commands related to stopping the Asterisk service. They are: core stop now - This command stops the Asterisk service immediately, ending any calls in progress. core stop gracefully - This command prevents new calls from starting up in Asterisk, but allows calls in progress to continue. When all the calls have finished, Asterisk stops. core stop when convenient - This command waits until Asterisk has no calls in progress, and then it stops the service. It does not prevent new calls from entering the system. There are three related commands for restarting Asterisk as well. core restart now - This command restarts the Asterisk service immediately, ending any calls in progress. core restart gracefully - This command prevents new calls from starting up in Asterisk, but allows calls in progress to continue. When all the calls have finished, Asterisk restarts. core restart when convenient - This command waits until Asterisk has no calls in progress, and then it restarts the service. It does not prevent new calls from entering the system. There is also a command if you change your mind. core abort shutdown - This command aborts a shutdown or restart which was previously initiated with the gracefully or when convenient options. ------------------------------ sip show peers - returns a list of chan_sip loaded peers voicemail show users - returns a list of app_voicemail loaded users core set debug 5 - sets the core debug to level 5 verbosity. ------------------------------ core show version ------------------------------ asterisk -h : Help. Run '/sbin/asterisk -h' to get a list of the available command line parameters. asterisk -C <configfile>: Starts Asterisk with a different configuration file than the default /etc/asterisk/asterisk.conf. -f : Foreground. Starts Asterisk but does not fork as a background daemon. -c : Enables console mode. Starts Asterisk in the foreground (implies -f), with a console command line interface (CLI) that can be used to issue commands and view the state of the system. -r : Remote console. Starts a CLI console which connects to an instance of Asterisk already running on this machine as a background daemon. -R : Remote console. Starts a CLI console which connects to an instance of Asterisk already running on this machine as a background daemon and attempts to reconnect if disconnected. -t : Record soundfiles in /var/tmp and move them where they belong after they are done. -T : Display the time in "Mmm dd hh:mm:ss" format for each line of output to the CLI. -n : Disable console colorization (for use with -c or -r) -i: Prompt for cryptographic initialization passcodes at startup. -p : Run as pseudo-realtime thread. Run with a real-time priority. (Whatever that means.) -q : Quiet mode (supress output) -v : Increase verbosity (multiple v's = more verbose) -V : Display version number and exit. -d : Enable extra debugging across all modules. -g : Makes Asterisk dump core in the case of a segmentation violation. -G <group> : Run as a group other than the caller. -U <user> : Run as a user other than the caller -x <cmd> : Execute command <cmd> (only valid with -r) ------------------------------

+ Installation (Dec. 14, 2014, 8:06 p.m.)

Before starting installation, be careful that, you need to install some packages from synaptic, and they might cause/need to install another version of `asterisk` and `asterisk-core`, and lots of other libraries, which these all might break the one you just installed! So make sure that the packages you need, should be installed via source, and not say YES to apt-get without checking the libraries! -------------------------------------------------------------------------------- Install these libraries first: 1-apt-get install libapache2-mod-auth-pgsql libanyevent-perl odbc-postgresql unixODBC unixODBC-dev libltdl-dev 2-Download the file asterisk-13-current.tar.gz from this link: http://downloads.asterisk.org/pub/telephony/asterisk/ a) Untar it. You will need this untarred asterisk file in the following steps. ----------- Building and Installing pjproject ----------- 1-Using the link http://www.pjsip.org/release/2.3/ download pjproject-2.3.tar.bz2 a) Untar and CD to the pjproject b) ./configure --prefix=/usr --enable-shared --disable-sound --disable-resample --disable-video --disable-opencore-amr CFLAGS='-O2 -DNDEBUG' c) make dep d) make e) make install f) ldconfig Now, for checking if you have successfully installed pjproject and asterisk detects the libraries, untar and CD to asterisk directory (I know you have not installed it yet, just move to the folder now :D), and enter the following command: g) apt-get install libjansson-dev uuid-dev snmpd libperl-dev libncurses5-dev libxml2-dev libsqlite3-dev *** important *** Before continuing to next step, you have to know that based on needs of Shetab company you need to enable `res_snmp` module. For enabling it you need to install `net-snmp_5.4.3`, and since it's not in the Synaptic, you have to install it from the source: 1-Download it from: https://launchpad.net/debian/+source/net-snmp/5.4.3~dfsg-2.8+deb7u1 2-Install it using ./configure, make and make install *** End of important *** h) ./configure --without-pwlib (If you don't use this --without switch, you will get the following error, even if you have installed those ptlib package already!) Cannot find ptlib-config - please install and try again i) make menuselect j) Browse to the eleventh category `Resource Modules` and make sure the `res_snmp` module at the bottom of the list is checked. Using escape key exit the menu and continue with installing asterisk. ----------- Building and Installing Asterisk ----------- 2- Make sure you are still in the asterisk directory). c) make I got so many errors surrounded by '**************' (so many asterisks) telling me these modules were needed: res_curl, res_odbcm, res_crypto, res_config_curl ... (and so many more) I just installed postgresql and the command `make` continued working with no errors! d) make install e) make samples f) make progdocs Now continue installation process with Perl packages from my tutorials. After that, refer to `Creating /etc/init.d/asterisk` in my tutorials.