Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 473224 - net-misc/asterisk-* - ability to start multiple asterisk instances on the same gentoo install!
Summary: net-misc/asterisk-* - ability to start multiple asterisk instances on the sam...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Server (show other bugs)
Hardware: All Linux
: Normal enhancement (vote)
Assignee: Tony Vroon (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-13 20:28 UTC by Jaco Kroon
Modified: 2013-07-23 09:19 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
updated asterisk init.d (asterisk,8.36 KB, text/plain)
2013-06-13 20:43 UTC, Jaco Kroon
Details
diff showing differences (asterisk-init-new.diff,5.81 KB, patch)
2013-06-25 13:28 UTC, Jaco Kroon
Details | Diff
updated asterisk init.d v2 (asterisk,8.66 KB, text/plain)
2013-06-26 18:38 UTC, Jaco Kroon
Details
diff from original to v2 (asterisk-init-new-v2.dif,7.43 KB, patch)
2013-06-26 18:42 UTC, Jaco Kroon
Details | Diff
updated asterisk init.d v3 (asterisk,9.00 KB, text/plain)
2013-06-26 19:31 UTC, Jaco Kroon
Details
diff from original to v3 (asterisk-init-new-v3.diff,8.73 KB, patch)
2013-06-26 19:33 UTC, Jaco Kroon
Details | Diff
updated asterisk init.d v4 (asterisk,9.02 KB, text/plain)
2013-06-26 20:05 UTC, Jaco Kroon
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jaco Kroon 2013-06-13 20:28:41 UTC
I've got a few very wack ideas for which I need to be able to run multiple instances of asterisk (bound to different IPs) on the same machine.  I've considered various options (including virtual machines on the same host, but the "density" I can get from that isn't sufficiently cost-effective, so basically the only option that gets me to the cost margins I need is multiple asterisk instances).  Another option that has been proposed is lxc containers (which may still be useful but imposes other restrictions on me that makes other interactions harder than it needs to be.

Reproducible: Always
Comment 1 Jaco Kroon 2013-06-13 20:43:26 UTC
Created attachment 350918 [details]
updated asterisk init.d

Tony,

Significantly earlier than promised.  As it turns out this is almost trivially easy.  From the distribution side anyway.  So I'd like to hash out documentation status as well in this bug, and then probably would like to put a blog entry on http://jkroon.uls.co.za/ which you can reference.  So here are the steps you need to take with the new init script in place:

1.  ln -s asterisk /etc/init.d/asterisk.${name}
2.  mkdir /etc/asterisk/${name}
3.  cp /etc/asterisk/*.conf /etc/asterisk/${name}
4.  chown -R root:asterisk /etc/asterisk/${name}
5.  Edit all config files and make 100% sure that the bind addresses for various things will not clash, eg, ensure that you have 192.168.0.1 and 192.168.0.2 configured on your ethernet, then make sure that asterisk.name1 binds everything to 192.168.0.1 and that asterisk.name2 binds everything to 192.168.0.2.  Conflicts here will cause you MAJOR headaches.
6.  Invoke /etc/init.d/asterisk.${name} as you would normally /etc/init.d/asterisk.
7.  You probably want to edit the newly created asterisk.conf, enable the [directories] section and override a few directories (see below).

A few things to note:

* For 7 above, probably everything that points to /var/lib/asterisk and /var/spool/asterisk will need to be updated, although, it's quite possible to share /var/lib/asterisk, but each system definitely needs it's own /var/spool/asterisk, and astdbdir - which by default is in /var/lib/asterisk but should probably actually be /var/spool/asterisk by default too (we need to discuss this point).
* I use root:asterisk as I don't want asterisk accidentally writing to the configuration files (4 above).
* In step 3 the idea is basically to get the set of default config files (I have a different strategy for this long term, but for most users that would look at this the above seems the sanest).
* You can set ASTERISK_{LOGDIR,RUNDIR,CONFDIR} in /etc/conf.d/asterisk.${name} to override the default calculated locations (same holds now for /etc/conf.d/asterisk).
* By default the logdir, rundir and confdir variables will be based on RC_SVCNAME, in particular, logdir and rundir will just create folders next to the normal asterisk dir (ie, /var/run/${RC_SVCNAME} and /var/log/${RC_SVCNAME}, but the config files - to help avoid name clutter in /etc will use /etc/${RC_SVCNAME/.//}, resulting in names such as /etc/asterisk/${name} for init.d/asterisk.${name}.

Further things to be done is probably just adding stuff to conf.d/asterisk about this, and DEFINITELY pointing at some kind of documentation (even if for the moment it's this bug report).
Comment 2 Jaco Kroon 2013-06-13 20:56:25 UTC
Oh, also wanted to add, I've made a few logic changes even for normal operation:

1.  If asterisk fails to start, signal the wrapper to terminate too, or rc ends up thinking asterisk is stopped but the wrapper keeps trying to start it.

2.  The log tag of the loop has changed from asterisk_wrapper to wrapper:asterisk(name) - or just wrapper:asterisk if we're not using names.  This is just so that you can identify which log entries are for which wrappers.

3.  I added explicit -C parameters to all invocations of asterisk to ensure that it connects to the correct asterisk.ctl, so for old systems this will just result in -C /etc/asterisk/asterisk.conf - which is the default anyway - but it's simpler to make this explicit.

4.  is_running will now just grab the PID from the pid file, and then use /proc to check if this is an asterisk instance or not.  This should be even lighter on resources than the old check, which does pidof (the executable of which iterates through all folders in /proc anyway).  So far this seems to work quite nicely.

5.  I updated the loop that fixes permissions.  Your previous loop dit things double, and did stuff I didn't agree with (if it found multiple files/folders with wrong user it would chown -R multiple times).  This variant may end up being much more verbose on fixing errors (if so I'll tone it down), and it doesn't use -R (find will find the whole lot anyway, and this time without the special stat previously executed for all files under rundir and logdir - usually not many, but still).  I'm also not confinced of the permissions, we probably want 640 for files and 750 for folders by default (which I can easily do with a similar find -exec variant (we could even reduce this whole thing to three commands:

find "${ast_rundir}" "${ast_logdir}" ! -user "${USER}" -exec chown "${USER}" {} +
find "${ast_rundir}" "${ast_logdir}" -type d ! -perm 0750 -exec chmod 0750 {} +
find "${ast_rundir}" "${ast_logdir}" -type f ! -perm 0750 -exec chmod 0640 {} +

Do we actually care about the group as well?
Comment 3 Jaco Kroon 2013-06-25 13:28:51 UTC
Created attachment 351914 [details, diff]
diff showing differences

For review purposes I've also created a diff now.
Comment 4 Jaco Kroon 2013-06-26 18:38:46 UTC
Created attachment 352006 [details]
updated asterisk init.d v2
Comment 5 Jaco Kroon 2013-06-26 18:42:17 UTC
Created attachment 352008 [details, diff]
diff from original to v2
Comment 6 Jaco Kroon 2013-06-26 19:31:52 UTC
Created attachment 352010 [details]
updated asterisk init.d v3

Changes from v1 => v2

* Replace most instances of `...` with "$(...)" (fix both quoting and use of ``.  Both `` and $() is posix compliant, however, the core gentoo devs prefer $().  Without the quotes dash (benchmark for Gentoo) seems to be choking somewhere.
* Add checks that USER and GROUP (after splitting ${ASTERISK_USER}) exists by utilizing getent passwd and getent group (meaning the users can come in via NSS config (possibly not in /etc/passwd and /etc/group - which is crucial for me).

Changes from v2 => v3:

* Add additional ASTERISK_WAITBOOTED option to wait on start() for asterisk to fully boot.  Asterisk can sometimes take a LONG time to start, I've had need before to have the init script wait for it to fully boot.  Note that this won't affect the return value from the start() function itself.
* Found and eliminated a few more `...` instances.
* Added additional quoting to prevent potential escape problems.

Tony, I'm not going to attach a new conf.d file, but I suggest adding this at the bottom:

#
# Set to yes to have start() wait for asterisk to fully boot.
#
ASTERISK_WAITBOOTED=no

Default is no because usually there is no point in waiting for it to fully boot, nor is it the current default (and I prefer not changing behaviour unless there is good reason to).
Comment 7 Jaco Kroon 2013-06-26 19:33:07 UTC
Created attachment 352012 [details, diff]
diff from original to v3

Because it's often easier to review a diff than a whole new file...
Comment 8 Jaco Kroon 2013-06-26 20:05:57 UTC
Created attachment 352014 [details]
updated asterisk init.d v4

Thanks to ryao (#gentoo-dev) for confirming that NICE variable should NOT be local.  This should fix the (currently broken) ASTERISK_NICE configuration option.  This is the only additional change from v3 to v4, thus I'm going to leave the additional diff.  If someone wants I'll create and upload.

@ Tony - I have no further changes to make so unless someone spots something wrong - this is the final version.  I would recommend seeing if you can get hold of kerframil and notify him we're going to push this and we'd like him to test.
Comment 9 Tony Vroon (RETIRED) gentoo-dev 2013-07-23 09:19:30 UTC
+*asterisk-11.5.0 (23 Jul 2013)
+*asterisk-1.8.23.0 (23 Jul 2013)
+
+  23 Jul 2013; Tony Vroon <chainsaw@gentoo.org> +asterisk-1.8.23.0.ebuild,
+  +asterisk-11.5.0.ebuild, +files/1.8.0/asterisk.initd6:
+  Bugfix releases on both branches. Completely revised init script by Jaco
+  Kroon that supports running multiple Asterisk instances on a single host,
+  closes bug #473224.