[Home]

Summary:ASTERISK-09555: [patch] /etc/init.d/asterisk is not "Linux Standard Base" compatible
Reporter:Iñaki Baz Castillo (ibc)Labels:
Date Opened:2007-05-31 05:14:26Date Closed:2008-02-28 19:11:49.000-0600
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Core/Configuration
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) asterisk.new
( 1) debian.init
( 2) rc.debian.asterisk.new
( 3) rc.debian.asterisk.patch
Description:As we can read at http://www.linux-foundation.org/spec/refspecs/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html:

"For all other init-script actions, the init script shall return an exit status of zero if the action was successful. Otherwise, the exit status shall be non-zero, as defined below. In addition to straightforward success, the following situations are also to be considered successful":

- "running start on a service already running"

But this is not true since "/etc/init.d/asterisk start" return 1 if Asterisk was already running. It should return 0.

In fact this is because the default behaviout of "start-stop-daemon" which returns error (1) after "start" if the service was already running. So it could be Debian issue.
Comments:By: Iñaki Baz Castillo (ibc) 2007-05-31 05:39:59

I said "this is because the default behaviour of "start-stop-daemon" which returns error (1) after "start" if the service was already running. So it could be Debian issue.", but many services in Debian using start-stop-daemon use the --oknodo option ("return exit status 0 instead of 1 if no actions are taken") so it's an Asterisk init script issue.

I've discovered this is in fact a bug in "safe_asterisk" script. It Asterisk is running and I execute "/etc/init.d/asterisk start" or "/usr/sbin/safe_asterisk" the I get the following EVERY time:

 Asterisk ended with exit status 1
 Asterisk died with code 1.
 Automatically restarting Asterisk.
 Asterisk ended with exit status 1
 Asterisk died with code 1.
 Automatically restarting Asterisk.
 Asterisk ended with exit status 1
 Asterisk died with code 1.
 Automatically restarting Asterisk.
 ...

and there exist at the same time two "safe_asterisk" processes. This is terrible because if I want to stop Asterisk I must do "CLI> stop now" TWO times (or more if there are more "safe_asterisk" running).

So I think "safe_asterisk" should test if it's already running before doing other "start".

PD: Finally, doing "/etc/init.d/asterisk start" returnes 0 even if Asterisk was already running, it's ok, but not in fact because the "safe_asterisk" bug I've related.

By: Iñaki Baz Castillo (ibc) 2007-05-31 06:20:14

I said "doing '/etc/init.d/asterisk start' returns 0 even if Asterisk was already running, it's ok, but not in fact because the 'safe_asterisk' bug I've related."

Not exactly. I've tried without "safe_asterisk", so $DAEMON is /usr/sbin/asterisk instead of /usr/sbin/safe_asterisk, and "start" action returns 1 if Asterisk was already running, this is because:

   start-stop-daemon --start --exec $DAEMON -- $ASTARGS

It should be:

   start-stop-daemon --oknodo --start --exec $DAEMON -- $ASTARGS

Then it'd return 0 (the correct behaviour of LSB).

By: Iñaki Baz Castillo (ibc) 2007-05-31 06:42:24

And one more thing, I see in the Asterisk init script:

 start)
     echo -n "Starting $DESC: "
     start-stop-daemon --start --exec $DAEMON
     echo "$NAME."
 ;;

That final "echo" will cause the action ALWAYS return 0 !!

It should be:

 start)
     echo -n "Starting $DESC: $NAME."
     start-stop-daemon --oknodo --start --exec $DAEMON
 ;;

By: Jason Parker (jparker) 2007-06-01 12:55:21

Can you summarize what exactly needs to be changed?  You've changed your mind a few times now. :)

By: Tzafrir Cohen (tzafrir) 2007-06-01 13:38:43

please don't use safe_asterisk.

That said, if you really want to use safe_asterisk, which doesn't really bother making itself a PID file, you should have start-stop-daemon generating it a PID file.

And then still hope for the best.

By: Iñaki Baz Castillo (ibc) 2007-06-04 04:44:41

Asterisk init script V1.3 is not LSB compliant so finally I've created a new script V1.4 and attached it and the patch.

Changelog is included in the file but I explain it here:

- I've eliminated "SAFE_ASTERISK" since it doesn't work as LSB script. Maybe it could be an **independent** /etc/init.d/safe_asterisk and the user chooses which one to use, but for now it's not easy to integrate two of them in the same script.

- Used "/lib/lsb/init-functions".

- "start" is improved to be LSB compliant with "--oknodo" and it returns 0 if Asterisk was already running (LSB behaviour).
In V1.3 "start" returned always 0, but just because the annoying --echo "$NAME."-- at the end of the action, so it the "start" action really fails it return 0 (??).

- The same in "stop" case.

- "restart|force-reload" uses "$0 stop & sleep 2 & $0 start" to be LSB compliant. In this way when restarting a NON running Asterisk starts Asterisk and return 0.
The previous way:
 $DAEMON -rx 'restart gracefully' > /dev/null 2> /dev/null && echo -n "$NAME"
returned always 0 even if Asterisk wasn't running before so it was no started by "restart" action (not LSB compliant).


With this script Asterisk could be managed, for example, as HeartBeat resource because it needs LSB compliant scripts (the actions return code is important and can't not be anything).


I hope you have this in consideration.
Regards.


Note:
I consider very useful this document:
* LSB Init Script Actions: http://www.linux-foundation.org/spec/refspecs/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html

By: Tzafrir Cohen (tzafrir) 2007-06-04 05:23:49

version 1.3? hmmm, why are CVS revisions still used there?
Perhaps the missing $ at the end of the $Id: line.

Another petty style comment: please try to preserve the original indentation, so your patch will be minimal and will show the actual differences.

By: Iñaki Baz Castillo (ibc) 2007-06-04 05:33:37

I've changed the original indentation since it was unclear (sometimes there was a TAB, sometimes 2 spaces...). I think it's better now but if you prefer me to preserve the original indentation please say me it again.

About the CVS revisions and the $Id I know nothig about it, should the line "$Id: ..." dissapear?

By: Iñaki Baz Castillo (ibc) 2007-06-04 05:50:38

I've done the new script preserving the indentation but I can't upload it and the patch because first I need to deelte the existing ones and It seems I've not permissions for that. Could anyone delete the actual attached files?

Thanks a lot.

By: Tzafrir Cohen (tzafrir) 2007-06-04 06:31:42

just give it a new name. debian.init (and the next one could be debian.init_1)
I assume you refer to contrib/init.d/rc.debian.asterisk , but it would be safer to state so explicitly. Or use an svn diff that states so implicitly...

I know the indentation there is lousy and inconsistent. But that is left for a separate housecleaning patch.

Generally you should not touch the $Id$ line. It gets updated automatically by CVS/SVN. That line did not get updated because a $ was missing in the end. So don't bother changing it. Those changes should be ignored (and it is a bug now that they are not).

I see even your new version preservers the "exit 0" in the end. Is that intentional?

Also: your script assumes that /lib/lsb/init-functions exists. It is part of lsb-base (at least on Etch) and a Required package on Etch. However on Sarge it is an Extra package and the system can live without it.

Any idea what is the minimally-required version of lsb-base for the suggested script to work?

How do you want to handle the following scenarion:

One runs 'asterisk' and then sends it to background. Next runs of "asterisk -r 'stop now'" will stall forever waiting for a response from the socket. But the asterisk "daemon" is sleeping. Is the a matter for a separate bug, or something that the asterisk init.d script should handle?

For the record: I'm all for removing safe_asterisk ;-)

By: Tzafrir Cohen (tzafrir) 2007-06-04 06:35:04

sorry, but I forgot to ask:

Is the patch disclaimed?

By: Iñaki Baz Castillo (ibc) 2007-06-04 07:56:37

// About the name:

Ok, I've added now as "debian.init".


// About the $Id:

Note that I didn't use SVN, I just get tha 1.3 version and modified it "by hand", without SVN commands. As I understand, I've eliminated the $Id line, but not sure if that is correct and maybe I should add a $ at the end of the line.


// About "exit 0" at the end:

Sincerely I don't know the purpose of that "exit 0" at the end, but have seen other script including it. Anyway I'm sure it could be removed and now I've removed it ;)


// About /lib/lsb/init-functions:

Efectively my script doesn't work in Sarge because "lsb-base" functions don't include the "log_daemon_msg". But now I've changed it to "log_begin_msg" and works well with "lsb-base 2.0-7" of Debian Sarge and with Etch version 3.1-23.1 (tested).

And yes, in Sarge "lsb-base" is not an included package by default, but one of the targets of Debian is being closed to LSB so personally I think is not a bad idea Asterisk to depend on "lsb-base" in Sarge to work well (just the init script).


// One runs 'asterisk' and then sends it to background. Next runs of "asterisk -r 'stop now'" will stall forever waiting for a response from the socket. But the asterisk "daemon" is sleeping. Is the a matter for a separate bug, or something that the asterisk init.d script should handle?

Humm, I start asterisk with "/etc/init.d/asterisk start", so asterisk it at background.
Now in other terminal exec:  asterisk -rx 'stop now'
so Asterisk just ends correctly, nothig strange occurs.


// Is the patch disclaimed?

Not sure about the meaning of this question. If you ask about the licence of the patch please, they are 4 lines no more XD. Maybe you could specify more what you mean.

Regards.

By: Tzafrir Cohen (tzafrir) 2007-06-04 09:54:17

Regarding disclaimer: if you haven't submitted any patch before to Asterisk, see http://asterisk.org/developers/bug-guidelines , and specifically the section "The License Agreement (disclaimer)".

By: Iñaki Baz Castillo (ibc) 2007-06-05 10:18:40

I have sent the fax with the disclaimer, but still haven't received Digium confirmation (in fact I'm not sure if I should receive something).

By: Iñaki Baz Castillo (ibc) 2007-06-13 10:42:21

The disclaimer has been sent and it's accepted.
So please take off the tag "Needs disclaimer" ;)

By: Iñaki Baz Castillo (ibc) 2007-06-20 04:00:35

Any new about considering this patch?

By: Iñaki Baz Castillo (ibc) 2007-07-11 02:55:33

Hi, I see "[License NONE]" in my attached script, what does it mean? should I specify one? I already sent the license disclaimer.

Thanks for any explanation.

By: Tzafrir Cohen (tzafrir) 2007-07-11 03:39:02

See the section regarding "License Agreement" in http://asterisk.org/developers/bug-guidelines .

By: Iñaki Baz Castillo (ibc) 2007-07-11 04:14:13

Thanks tzafrir, but I already read that document and sent the fax with my sign in the licence disclaimer. I don't understand what more should I do about the licence. Any help please? Can't you verify that I sent the disclaimer? (I sent if as scanned image by mail but Digium people received it and confirmed me that.

By: Iñaki Baz Castillo (ibc) 2007-08-27 20:49:03

Hi again.

Please, I'd like to receive any help, I sent my DISCLAIMER long time ago and it was received by Digium people (I sent it as a scanned image and got arriving confirmation by mail).

Could some body tell me what more do I need to do about the DISCLAIMER?

Thanks a lot.

By: Tzafrir Cohen (tzafrir) 2007-08-27 21:22:09

Is it possible for you to re-sign the license (the "license" link at the top, I believe). Sorry, the procedures have changed a bit.

By: Iñaki Baz Castillo (ibc) 2007-08-28 05:49:58

Ok, I've re-signed the license in the link at the top.

By: Iñaki Baz Castillo (ibc) 2007-09-24 02:58:15

I signed the license a month ago but still shows "License NONE".
Please, could somebody tell me why this still appears as "License NONE"? Note that the top link "Sign" is not available for me now since I already signed it.

Thanks for any help.

By: Tilghman Lesher (tilghman) 2007-10-04 16:16:31

Due to how licensing works, the licensing only takes effect for files which are uploaded AFTER the license is signed.  I have therefore deleted the patches, ready for you to reupload them.

By: Iñaki Baz Castillo (ibc) 2007-10-05 05:10:37

Ok, I've uploaded the files again. Thanks.

By: Julian J. M. (julianjm) 2007-11-02 13:18:44

I think that having LSB compliant init scripts is a Good Thing, specially when combined with heartbeat. Is there anything holding this back, apart from zero feedback?

BTW, the redhat script needs some work in this direction too.

By: pkempgen (pkempgen) 2008-01-11 22:21:51.000-0600

Maybe not the best place to ask, but it's somehow related:
tzafrir, would you mind telling us *why* you think safe_asterisk
is bad? Is it because there are problems with the script in the
way it is done? (I know it could be done better.) Is it because
you don't like watchdogs for daemons in general?
And if safe_asterisk is so bad, why does it still exists?

By: Faidon Liambotis (paravoid) 2008-01-13 05:52:23.000-0600

FWIW, the init.d script we have in Debian is quite different from this one.
It's LSB compliant since ages ago and implements several other features.

I'm not able to upload it here since I'm not the only one holding copyrights on it and hence I cannot disclaim it.

This was discussed briefly on IRC and an opinion was expressed that since it's licensed under the terms of the GPLv2 and is a shell script (binary == source), a disclaimer may not be needed.

In any case, you can find the latest version of our script there:
http://svn.debian.org/wsvn/pkg-voip/asterisk/trunk/debian/asterisk.init?op=file&rev=0&sc=0



By: Iñaki Baz Castillo (ibc) 2008-01-28 03:01:03.000-0600

Hi paravoid, you say that the Debian Asterisk script is LSB compliant, but I see:

 start)
   ...
   echo "."
   ;;

So the last command executed after "start" is "echo ." that will always reply TRUE (0), even if the "start" action fails. That is not LSB compliant. Or maybe I'm wrong?

By: Faidon Liambotis (paravoid) 2008-01-28 21:40:18.000-0600

There is a "set -e" right there in the middle.
If start-stop-daemons exits with 1, so will the init script.

Unless of course asterisk is already running; this case is handled explicitely.

By: Iñaki Baz Castillo (ibc) 2008-01-29 02:24:38.000-0600

Yes, thanks, I didn't see it ;)

By: Digium Subversion (svnbot) 2008-02-28 15:53:09.000-0600

Repository: asterisk
Revision: 105113

U   branches/1.4/contrib/init.d/rc.debian.asterisk

------------------------------------------------------------------------
r105113 | tilghman | 2008-02-28 15:53:08 -0600 (Thu, 28 Feb 2008) | 7 lines

Update init script for LSB compat
(closes issue ASTERISK-9555)
Reported by: ibc
Patches:
      rc.debian.asterisk.patch uploaded by ibc (license 211)
Tested by: paravoid

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=105113

By: Digium Subversion (svnbot) 2008-02-28 19:11:49.000-0600

Repository: asterisk
Revision: 105176

_U  trunk/
U   trunk/contrib/init.d/rc.debian.asterisk

------------------------------------------------------------------------
r105176 | tilghman | 2008-02-28 19:11:43 -0600 (Thu, 28 Feb 2008) | 15 lines

Merged revisions 105113 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r105113 | tilghman | 2008-02-28 15:56:54 -0600 (Thu, 28 Feb 2008) | 7 lines

Update init script for LSB compat
(closes issue ASTERISK-9555)
Reported by: ibc
Patches:
      rc.debian.asterisk.patch uploaded by ibc (license 211)
Tested by: paravoid

........

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=105176