[Home]

Summary:ASTERISK-13900: Issue starting Asterisk with LinuxHA
Reporter:Chris Maciejewski (chris-mac)Labels:
Date Opened:2009-04-05 11:22:10Date Closed:2009-04-30 01:49:00
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Resources/res_musiconhold
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) 20090428__bug14831.diff.txt
( 1) 20090430__bug14831.diff.txt
( 2) asterisk-startup.txt
( 3) modules.conf
Description:Just noticed strange behaviour of Music on Hold.

When I start asterisk for the first time (after the server was powered on), and try to put a SIP call on hold, console shows:

DEBUG[5845]: res_musiconhold.c:726 get_mohbyname: Music on Hold class 'default' not found in memory

the following CLI command shows nothing:
asterisk -r -x "moh show classes"

Only after asterisk is restarted MoH works OK, and 'asterisk -r -x "moh show classes"' shows:
--------------------
Class: default
Mode: files
Directory: /var/lib/asterisk/moh
--------------------

My musiconhold.conf:
----------------
[general]
cachertclasses=yes

[default]
mode=files
directory=/var/lib/asterisk/moh
----------------

Already tried with cachertclasses=yes/no with the same result.

Best regards,
Chris
Comments:By: Leif Madsen (lmadsen) 2009-04-21 21:38:18

Try doing a:

preload => res_musiconhold.so

in your modules.conf

By: Chris Maciejewski (chris-mac) 2009-04-22 01:17:29

Unfortunately "preload => res_musiconhold.so" didn't solve my problem.

Asterisk still showing:

[Apr 22 07:15:17] DEBUG[5943]: res_musiconhold.c:726 get_mohbyname: Music on Hold class 'default' not found in memory

Please find my modules.conf attached.

By: Leif Madsen (lmadsen) 2009-04-22 07:50:52

OK, then can you attach the console output while Asterisk is loading?

asterisk -cvvvn | tee /tmp/asterisk-startup.txt

By: Chris Maciejewski (chris-mac) 2009-04-22 11:01:01

I just found out something very odd. This problem only occurs when Asterisk is started by Heartbeat daemon via haresources (http://www.linux-ha.org/haresources ).

Despite /var/lib/asterisk/moh is owned by asterisk:asterisk res_musiconhold fails at line 958. See line 19 of asterisk-startup.txt attached.



By: Chris Maciejewski (chris-mac) 2009-04-22 15:07:20

I changed line 957-960 of res_musiconhold.c to:

957: if (chdir(path) < 0) {
958: ast_log(LOG_WARNING, "chdir() failed: %s - path: %s\n", strerror(errno),path);
959: return -1;
960: }

and now I am getting the following error, when starting Asterisk via HA:

[Apr 22 21:02:29] WARNING[5878]: res_musiconhold.c:958 moh_scan_files: chdir() failed: Permission denied - path: /var/lib/heartbeat/cores/root

So looks like 'path' variable is set to '/var/lib/heartbeat/cores/root' (because Asterisk is not changing it's working directory to "/" - as it probably should when demonizing), and for some reason res_musiconhold.c wants chdir() into that directory?



By: Leif Madsen (lmadsen) 2009-04-23 13:08:24

I think Asterisk starts in the directory you call it from. How are you starting Asterisk?

This almost seems like you need to modify your asterisk.conf file for the paths?

By: Chris Maciejewski (chris-mac) 2009-04-24 14:14:38

Yes, Asterisk starts in the directory you call it from.
However I don't think this is a correct behaviour of a daemon process.

AFAIK all daemons should change their working directory to '/' (which would fix this bug).

Please see mailing list discussion about this topic:

http://lists.digium.com/pipermail/asterisk-dev/2009-April/038048.html

In fact, the summary of this bug is not exactly correct, as Asterisk will currently fail to load MoH if started in any directory which is not accessible by "-G user -U user" - not only in LinuxHA environment.



By: Leif Madsen (lmadsen) 2009-04-26 09:13:15

Thanks for the feedback, and the link to the discussion! I will re-assign this issue.

By: Chris Maciejewski (chris-mac) 2009-04-29 03:11:43

Patch solves the MoH/LinuxHA issue, however in my opinion:

1. Summary of this bug should be changed to "Asterisk starting directory should be '/', not CWD"

2. Patch should be modified, so it *always* (when Asterisk is not started with -c option) sets "/" as a working directory. Not only if the directory in which Asterisk is started is not accessible (as it is the case now).

3. The reason for the above:

"Linux System Programming" - Robert Love
http://books.google.com/books?id=k_ocKY0iegsC&pg=PA159&dq=linux+daemon+programing&lr=#PPA159,M1
"Change the working directory to the root directory via chdir(). This is done because inherited working directory can be anywhere on the filesystem. Daemons tend to run for the duration of the system's uptime, and you don't want to keep some randoms directory open, and thus prevent an administrator from unmounting the filesystem containing that directory."

"Wikidepia - Daemon_(computer_software)"
http://en.wikipedia.org/wiki/Daemon_(computer_software)
"The common method for a process to become a daemon involves:
[...]Setting the root directory ("/") as the current working directory so that the process will not keep any directory in use that may be on a mounted file system (allowing it to be unmounted)."

"Linux Journal - Linux Network Programming, Part 2 - by Ivan Griffin and John Nelson"
http://www.linuxjournal.com/article/2335
"[...]Daemons are typically started at boot-up and remain running throughout the uptime life of the system. If a daemon was started from a mounted file system, it would be impossible to unmount the file system until the daemon was killed. As a result, it is a sensible daemon programming practice to perform a chdir() to / (or perhaps to a file system which holds files relevant to the operation of the daemon)."

Best regards,
Chris



By: Tilghman Lesher (tilghman) 2009-04-29 08:55:54

That's possible, but I'd modify it by saying that we only change directories when Asterisk is run as a daemon.  A very common case is to run Asterisk as a console program (the -c option).

In any case, I am reluctant to change behavior in a released version of Asterisk, mainly because I am concerned with possible side effects of that change.  One of those is the location of the core file.  You've stated there's a workaround, but I'm still concerned about changing existing behavior.

By: Chris Maciejewski (chris-mac) 2009-04-29 12:21:38

When Asterisk is started with -c as a console program it is not running in the background (becoming a daemon), so no need to change working directory to "/" at all. In this case current behaviour is correct.

I didn't notice 1.6.1 was released yesterday :-)

Maybe instead of changing to "/" we can change to "/var/lib/asterisk" or whatever directory is set as 'astvarlibdir' in asterisk.conf file?

By: Digium Subversion (svnbot) 2009-04-30 01:47:14

Repository: asterisk
Revision: 191283

U   trunk/main/asterisk.c

------------------------------------------------------------------------
r191283 | tilghman | 2009-04-30 01:47:13 -0500 (Thu, 30 Apr 2009) | 11 lines

Change working directory to / under certain conditions.
If backgrounding and no core will be produced, then changing the directory
won't break anything; likewise, if the CWD isn't accessible by the current
user, then a core wasn't possible anyway.
(closes issue ASTERISK-13900)
Reported by: chris-mac
Patches:
      20090428__bug14831.diff.txt uploaded by tilghman (license 14)
      20090430__bug14831.diff.txt uploaded by tilghman (license 14)
Tested by: chris-mac

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

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

By: Digium Subversion (svnbot) 2009-04-30 01:48:01

Repository: asterisk
Revision: 191284

_U  branches/1.6.0/
U   branches/1.6.0/main/asterisk.c

------------------------------------------------------------------------
r191284 | tilghman | 2009-04-30 01:48:01 -0500 (Thu, 30 Apr 2009) | 18 lines

Merged revisions 191283 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

........
 r191283 | tilghman | 2009-04-30 01:47:13 -0500 (Thu, 30 Apr 2009) | 11 lines
 
 Change working directory to / under certain conditions.
 If backgrounding and no core will be produced, then changing the directory
 won't break anything; likewise, if the CWD isn't accessible by the current
 user, then a core wasn't possible anyway.
 (closes issue ASTERISK-13900)
  Reported by: chris-mac
  Patches:
        20090428__bug14831.diff.txt uploaded by tilghman (license 14)
        20090430__bug14831.diff.txt uploaded by tilghman (license 14)
  Tested by: chris-mac
........

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

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

By: Digium Subversion (svnbot) 2009-04-30 01:48:51

Repository: asterisk
Revision: 191285

_U  branches/1.6.1/
U   branches/1.6.1/main/asterisk.c

------------------------------------------------------------------------
r191285 | tilghman | 2009-04-30 01:48:51 -0500 (Thu, 30 Apr 2009) | 18 lines

Merged revisions 191283 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

........
 r191283 | tilghman | 2009-04-30 01:47:13 -0500 (Thu, 30 Apr 2009) | 11 lines
 
 Change working directory to / under certain conditions.
 If backgrounding and no core will be produced, then changing the directory
 won't break anything; likewise, if the CWD isn't accessible by the current
 user, then a core wasn't possible anyway.
 (closes issue ASTERISK-13900)
  Reported by: chris-mac
  Patches:
        20090428__bug14831.diff.txt uploaded by tilghman (license 14)
        20090430__bug14831.diff.txt uploaded by tilghman (license 14)
  Tested by: chris-mac
........

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

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

By: Digium Subversion (svnbot) 2009-04-30 01:49:00

Repository: asterisk
Revision: 191286

_U  branches/1.6.2/
U   branches/1.6.2/main/asterisk.c

------------------------------------------------------------------------
r191286 | tilghman | 2009-04-30 01:48:59 -0500 (Thu, 30 Apr 2009) | 18 lines

Merged revisions 191283 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

........
 r191283 | tilghman | 2009-04-30 01:47:13 -0500 (Thu, 30 Apr 2009) | 11 lines
 
 Change working directory to / under certain conditions.
 If backgrounding and no core will be produced, then changing the directory
 won't break anything; likewise, if the CWD isn't accessible by the current
 user, then a core wasn't possible anyway.
 (closes issue ASTERISK-13900)
  Reported by: chris-mac
  Patches:
        20090428__bug14831.diff.txt uploaded by tilghman (license 14)
        20090430__bug14831.diff.txt uploaded by tilghman (license 14)
  Tested by: chris-mac
........

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

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