Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 594964 - net-misc/asterisk-* init script improvements.
Summary: net-misc/asterisk-* init script improvements.
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Jaco Kroon
URL:
Whiteboard:
Keywords: PullRequest
Depends on:
Blocks: 624038
  Show dependency tree
 
Reported: 2016-09-23 22:27 UTC by Maciej S. Szmigiero
Modified: 2020-03-20 09:10 UTC (History)
1 user (show)

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


Attachments
asterisk.init9 (asterisk,9.77 KB, text/plain)
2016-09-25 20:06 UTC, Jaco Kroon
Details
diff showing the changes made for review (asterisk.init.diff,2.79 KB, patch)
2016-09-25 20:08 UTC, Jaco Kroon
Details | Diff
asterisk.init10 (asterisk.initd10,10.07 KB, text/plain)
2017-11-15 21:23 UTC, Jaco Kroon
Details
asterisk.confd (asterisk.confd,2.46 KB, text/plain)
2017-11-15 21:23 UTC, Jaco Kroon
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Maciej S. Szmigiero 2016-09-23 22:27:39 UTC
In file /etc/conf.d/asterisk installed by net-misc/asterisk-11.23.1 variable
ASTERISK_USER is described as having option to run asterisk as some user with all
groups that user is a member of.

This setting used to work at least in net-misc/asterisk-11.21.2.

However, new init script introduced with net-misc/asterisk-11.23.0 version bump
(from bug #582512) broke this functionality since it unconditionally provides
"-G" command line parameter to asterisk (which previous version didn't do).

You can see in https://github.com/asterisk/asterisk/blob/11.23/main/asterisk.c#L3960
that with "rungroup" set (which is set if "-G" command line parameter is present)
the code skips initgroups() call and so runs without supplemental groups
(existing groups were dropped few lines earlier).
Comment 1 Tony Vroon (RETIRED) gentoo-dev 2016-09-24 16:42:37 UTC
Jaco, was that intentional?
Comment 2 Jaco Kroon 2016-09-25 18:11:33 UTC
Definitely not.  Always passing -G was intentional (my use-case it's pretty much a given that I need that).

Does asterisk initialize supplemental groups if you only pass -U?  From what I recall it then only does setuid() and ends up still having a group of root ... but I can retest that.  Based on the linked code it should be fine.  I'll upload a patch (and an updated version of the script in a moment).

I still haven't managed to fix the other screwup I mentioned to you in IRC:

<jkroon> Chainsaw, i picked up a possible issue with the wrapper in asterisk.
<jkroon> on restart it can actually spawn multiple wrappers.
<jkroon> still contemplating the best possible fix.
<jkroon> just so you are aware so long.
<jkroon> looks like I may need to create a lock file for the loop itself, with pid in it, and then use a signal to notify the wrapper to stop, which will only release the lock post-shutdown.
<jkroon> but i'll figure that one out.
<jkroon> not sure why it became a problem for us now.
<jkroon> seems to happen if asterisk doesn't actually stop in time and the next startup then causes problems

Will try and perform that here too at the same time.  In essense:

The wrapper itself rm's the .running file.  Whilst that file exists it keeps looping:

failure to shutdown in time (asterisk stop) leaves the file not existing but the loop still running.

next startup then creates the file again, and spawns a loop.

This then results in both loops continuing to run.
Comment 3 Jaco Kroon 2016-09-25 20:06:51 UTC
Created attachment 447886 [details]
asterisk.init9

The update to fix the wrapper script is even harder than I thought - but in the meantime we can at least fix -G without going backwards on the other changes.  You'll need to confirm test this one whether it does what's intended, but at the very least it should give you an indication:

 *   Starting asterisk as      : asterisk:asterisk  [ ok ]

vs:

 *   Starting asterisk as      : asterisk:asterisk (+suplementaries)   [ ok ]

And in the latter case the cmdline is:

/usr/sbin/asterisk -C /etc/asterisk/asterisk.conf -f -g -U asterisk

So it looks good now.  In the former case -G is still passed.
Comment 4 Jaco Kroon 2016-09-25 20:08:43 UTC
Created attachment 447888 [details, diff]
diff showing the changes made for review

As promised.  Want to discuss the wrapper loop situation with you first.  We may have to implement a max wait before forcibly killing asterisk.  Or at the very least possibly add an extra function achieve that (forcestop and forcerestart perhaps).  Including config to do that automatically after a configured timeout.
Comment 5 Maciej S. Szmigiero 2016-09-25 20:31:55 UTC
(In reply to Jaco Kroon from comment #2)
(..)
> Does asterisk initialize supplemental groups if you only pass -U?  From what
> I recall it then only does setuid() and ends up still having a group of root
> ... but I can retest that.  Based on the linked code it should be fine. 

Yes it does (as long as it was originally started as root) -
link in my first comment points to the code part where initgroups() is called.

Also, while waiting for this bug to be fixed I've commented
"OPTS="${OPTS} -G ${ast_group}" line in the init script and this resulted in 
supplemental groups being correctly added.
Comment 6 Jaco Kroon 2017-11-06 10:23:43 UTC
Tony,

This one we also still need to look at.

Kind Regards,
Jaco
Comment 7 Jaco Kroon 2017-11-15 21:23:07 UTC
Created attachment 504458 [details]
asterisk.init10

Updated version of update, building on previous, and implementing the following additional improvements:

* Ability to select alternate stop mechanism, selection between:
 - core stop now - drops all calls and shuts down immediately.
 - core stop gracefully - stop accepting new calls, shut down when all done.
 - core stop when convenient - keep accepting new calls, shut down at first opportunity.

* Ability to modify the total wait time (eg, normally I don't mind waiting even two hours for a call to finish, but I cannot afford to drop calls, thus why I'd also *normally* want to use "core stop when convenient"), including being able to wait indefinitely.

* Cosmetic changes to use ast_instancename variable in more locations.

Update to confd file also required to utilize these changes.

I did pick up that before outputting the waiting line it can take some time, which is due to the asterisk CLI not actually returning immediately.  I don't think this is a serious problem as it'll wait a few seconds normally.
Comment 8 Jaco Kroon 2017-11-15 21:23:49 UTC
Created attachment 504460 [details]
asterisk.confd
Comment 9 Larry the Git Cow gentoo-dev 2020-03-20 09:10:00 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=bef6c9937500cd1ff103da2117d7e20f268cfa47

commit bef6c9937500cd1ff103da2117d7e20f268cfa47
Author:     Jaco Kroon <jaco@uls.co.za>
AuthorDate: 2020-03-15 18:45:40 +0000
Commit:     Joonas Niilola <juippis@gentoo.org>
CommitDate: 2020-03-20 09:09:29 +0000

    net-misc/asterisk: version bump 13.32.0
    
    Normal release.
    
    Issues reported to Gentoo fixed from upstream was mysql's my_bool that
    went away.
    
    Include patches for binutils 2.34 (also submitted upstream so expect
    removal in next release).
    
    Also includes various init script improvements I've been running with
    for a while now.
    
    Closes: https://bugs.gentoo.org/594964
    Closes: https://bugs.gentoo.org/624038
    Closes: https://bugs.gentoo.org/710484
    Closes: https://bugs.gentoo.org/711582
    Package-Manager: Portage-2.3.89, Repoman-2.3.20
    Signed-off-by: Jaco Kroon <jaco@uls.co.za>
    Closes: https://github.com/gentoo/gentoo/pull/14986
    Signed-off-by: Joonas Niilola <juippis@gentoo.org>

 net-misc/asterisk/Manifest                         |   1 +
 net-misc/asterisk/asterisk-13.32.0.ebuild          | 332 ++++++++++++++++++
 .../files/asterisk-13.32.0-binutils-2.34.patch     |  17 +
 .../asterisk-historic-dahdiras-without-root.patch  |  23 ++
 .../asterisk-historic-dundi-null-dereference.patch |  40 +++
 ...terisk-historic-invert-gmine-search-order.patch |  12 +
 .../asterisk-historic-no-var-run-install.patch     |  14 +
 .../asterisk/files/asterisk-historic-uclibc.patch  |  23 ++
 net-misc/asterisk/files/confd-13.32.0              | 160 +++++++++
 net-misc/asterisk/files/initd-13.32.0              | 380 +++++++++++++++++++++
 10 files changed, 1002 insertions(+)