blak3r / yaai

SugarCRM Asterisk integration
http://www.sugarforge.org/projects/yaai
GNU General Public License v3.0
84 stars 85 forks source link

Running AsteriskLogger.php as a daemon on Linux #72

Open blak3r opened 11 years ago

blak3r commented 11 years ago

Has anyone successfully got asteriskLogger running as a daemon on linux? Looking for some feedback before I gave it a try on a customers box.

There is a script included in the package here: https://github.com/blak3r/yaai/blob/master/misc/asteriskLoggerService.txt

That can be used, I've never installed a daemon like this before... According to http://bitnami.org/article/how-to-install-services-on-linux you do something like:

Debian-like distribution (Debian, Ubuntu, etc)

1. Copy the installdir/ctlscript.sh file to /etc/init.d . It is advisable to rename this script to something more specific, like “bitnami-drupal”.

cp ${installdir}/ctlscript.sh /etc/init.d/bitnami-drupal

2. We will use rc-update.d to add the script to the desired runlevels.
update-rc.d -f bitnami-drupal start 80 2 3 4 5 . stop 30 0 1 6 .

As you can see, we define the priority (80 for start and 30 for stop) and the runlevels in which the script will be executed. The result of this command will be something like

Adding system startup for /etc/init.d/bitnami-drupal ...
 /etc/rc0.d/K30bitnami-bitnami-drupal -> ../init.d/drupal
 /etc/rc1.d/K30bitnami-bitnami-drupal -> ../init.d/drupal
 /etc/rc6.d/K30bitnami-drupal -> ../init.d/bitnami-drupal
 /etc/rc2.d/S80bitnami-drupal -> ../init.d/bitnami-drupal
 /etc/rc3.d/S80bitnami-drupal -> ../init.d/bitnami-drupal
 /etc/rc4.d/S80bitnami-drupal -> ../init.d/bitnami-drupal
 /etc/rc5.d/S80bitnami-drupal -> ../init.d/bitnami-drupal

And that’s it, the servers will be loaded at boot time. To revert the changes, just type
update-rc.d -f bitnami-drupal remove

Except replace all the references to bitnami-drupal with asteriskLogger.ctl or whatever you named the script.

@trustmaster

trustmaster commented 11 years ago

I'm currently using this script https://github.com/trustmaster/SugarAsterisk/blob/master/init.d/asterisk_logger

It ensures the logger is started after mysql, apache and asterisk (otherwise it would fail to start on boot). And it doesn't kill all PHP processes on stop, it only kills asteriskLogger. Tested on Debian and Ubuntu.

blak3r commented 11 years ago

Thanks for the script @trustmaster

I used it this weekend on a centos box. I'm not sure it was entirely necessary but I added

# chkconfig: 2345 80 30

I pushed your script with my one addition to https://raw.github.com/blak3r/yaai/master/misc/asterisk_logger

I found that despite changing some lines to try and make it start up as the last service. The soap connection was still failing and as a result "die"ing. I commited some changes to asteriskLogger to make it keep retrying the soap login until it's able to connect so that just makes it a little more resilient to working as a daemon.

@trustmaster I'm going to update the usermanual to include these instructions below. Do you see anything wrong with them? perhaps chmod should be something different? and perhaps the update-rc.d line doesn't need the start and stop stuff since it's set in the comments in the script?

Installation Steps

Here are the steps I took for installing it as a service on centos.

  1. wget https://raw.github.com/blak3r/yaai/master/misc/asterisk_logger -or- extract from the module zip you downloaded from sugarforge and get it from misc/asterisk_logger
  2. copy asterisk_logger to /etc/init.d/
  3. chmod 755 /etc/init.d/asterisk_logger
  4. Edit the script by opening /etc/init.d/asterisk_logger in your editor of choice
    • Changing the path to where your asteriskLogger resides (usually it's like /var/www/html/sugarcrm/custom/modules/Asterisk/asteriskLogger.php)
    • Set the user to whatever your apache service runs as.
  5. Install the Script (this step is distro dependent)
    • For Centos, Red Hat, Fedora Core, Suse, etc)
      chkconfig --add asterisk_logger
    • For Debian, Ubuntu, and similar update-rc.d -f asterisk_logger start 80 2 3 4 5 . stop 30 0 1 6 .

To test that you set up the script properly after step 4, you can run /etc/init.d/asterisk_logger start if you have errors you'll most likely see them on the console. You can also do tail -f if you have this configured in sugarconfig and you should see that it connected successfully.

trustmaster commented 11 years ago

Looks fine. The start/stop part is good to make sure it works on all Debian/Ubuntu versions.

blak3r commented 11 years ago

Great. Thanks for looking it over. I'll put it in the User Manual now.

On Wed, Oct 3, 2012 at 1:05 AM, Vladimir Sibirov notifications@github.comwrote:

Looks fine. The start/stop part is good to make sure it works on all Debian/Ubuntu versions.

— Reply to this email directly or view it on GitHubhttps://github.com/blak3r/yaai/issues/72#issuecomment-9095874.