Init script

Get help with installing, upgrading and running Asterisk.

Moderators: muppetmaster, Moderator, Support

Init script

Postby moferreira » Mon Nov 18, 2013 1:58 pm

Hi,

I can download, compile, config and run Asterisk from the CentOS 6.4 console. However, when I try to start it as service using "service asterisk start" it does not work. Following some other forum threads, on my install I am also doing:

adduser -c "asterisk" -r -s /bin/false asterisk

chown -R asterisk:asterisk /usr/lib/asterisk/
chown -R asterisk:asterisk /var/lib/asterisk/
chown -R asterisk:asterisk /var/spool/asterisk/
chown -R asterisk:asterisk /var/log/asterisk/
chown -R asterisk:asterisk /var/run/asterisk/
chown -R asterisk:asterisk /usr/sbin/asterisk
chown -R asterisk:asterisk /etc/asterisk

On asterisk.conf I have:
[options]
runuser = asterisk
rungroup = asterisk

Any hint on how I can get the init script to get working?

Mo
moferreira
Newsterisk
 
Posts: 11
Joined: Sat Nov 16, 2013 6:20 am

Re: Init script

Postby wallnutmonkeys » Tue Nov 19, 2013 8:42 am

Hi Mo, Are you getting an error? and what version of asterisk are you running?
wallnutmonkeys
Newsterisk
 
Posts: 28
Joined: Thu Feb 10, 2011 9:52 pm

Re: Init script

Postby moferreira » Wed Nov 20, 2013 12:55 pm

I am using Asterisk 11. When I try to start the service via init script it says "Starting Asterisk...", but then nothing happens after this. It must be something stupid I am doing (or not doing :oops: ).

I will do some checks about who is running it as I have set asterisk.conf to run Asterisk as user "asterisk" but I never checked, when I invoke it from the console, if it runs as "root" or asterisk user. This might be the problem... But the reality is that you download, compile, make config, make install, make the samples and, when you try to start it using "service start asterisk", it doesn't start.
moferreira
Newsterisk
 
Posts: 11
Joined: Sat Nov 16, 2013 6:20 am

Re: Init script

Postby wallnutmonkeys » Wed Nov 20, 2013 1:14 pm

I had a similar issue with asterisk 11 on centos 6.4 a few weeks (or months) back, "ldconfig" needed to be run after asterisk compilation/installation. Can you try that and see? Also, I presume you can start asterisk without the startup scripts? can you confirm

cheers
wallnut
wallnutmonkeys
Newsterisk
 
Posts: 28
Joined: Thu Feb 10, 2011 9:52 pm

Re: Init script

Postby moferreira » Thu Nov 21, 2013 3:29 pm

Yes, I can start Asterisk running "asterisk -cvvv". It will fail to start if you don't issue a "ldconfig" after compiling/installing. If you don't do it, it will fail looking for "libasteriskssl.so.1". But if you don't do a "ldconfig", you can still start it if you do a "export LD_LIBRARY_PATH=/usr/lib" (in my case I compile it using "./configure --prefix=/usr").

So, I think the install script should include a "ldconfig". But anyway, the init script does not work even if you do a make, make install, make config and make samples. But as I said, I am not sure if the init is failing because the asterisk user I create does not have the necessary rights to do what is necessary. So any hint is more than welcome! But I guess I am not "unique" so more people had (or are having) the same problem.

Cheers!
moferreira
Newsterisk
 
Posts: 11
Joined: Sat Nov 16, 2013 6:20 am

Re: Init script

Postby david55 » Thu Nov 21, 2013 3:59 pm

On normal Linux and Unix systems, /usr/lib is on the default LD_LIBRARYPATH.
david55
Moves Like Spencer
 
Posts: 12570
Joined: Fri Sep 26, 2008 5:03 am

Re: Init script

Postby moferreira » Fri Nov 22, 2013 4:09 pm

Sorry David but what is "normal"? I think my install is quite "normal", I think... What I do is:
1 - I install CentOS 6.4 from minimal install ISO.

2 - As soon as I get it installed, I disable postfix, selinux, iptables, update and then reboot the system:

chkconfig postfix off
chkconfig iptables off
sed -i 's|SELINUX=enforce|SELINUX=disable|' /etc/selinux/config
yum update -y && reboot

3 - After this I install all dependencies:

yum install gcc.x86_64 gcc-c++.x86_64 ntp \
make.x86_64 wget.x86_64 subversion.x86_64 \
libxml2-devel.x86_64 ncurses-devel.x86_64 \
openssl-devel.x86_64 sqlite-devel libpcap -y

4 - Then I fix the time:

ntpdate pool.ntp.org
chkconfig ntpd on
service ntpd start

5 - Get the code and compile it:

svn checkout http://svn.asterisk.org/svn/asterisk/branches/11 asterisk
cd /usr/local/src/asterisk
./configure --prefix=/usr
make
make install
make config
make samples

6 - As it will not work, I do:
ldconfig

That is it! Now, what am I doing wrong? I "think" I should be able to issue a "service aterisk start" and it should start Asterisk with the "sample" configuration. But it doesn't.

Anyway, I know it is quite difficult to adapt the code for all Linux flavors. However, what I want to find is what I should do, that is missing, to get it working from the init script. That is it!

Cheers!

Mo
moferreira
Newsterisk
 
Posts: 11
Joined: Sat Nov 16, 2013 6:20 am

Re: Init script

Postby david55 » Sat Nov 23, 2013 4:44 am

CentOS 5.7, Debian Wheezy, Slackware 14, SCO OpenServer, SunOS, the Zilog Unix I used, over thirty years ago, are normal. I have no experience of CentOS 6, but I can't think of any good reason why they would stop using /usr/lib.
david55
Moves Like Spencer
 
Posts: 12570
Joined: Fri Sep 26, 2008 5:03 am

Re: Init script

Postby david55 » Sat Nov 23, 2013 4:54 am

The reason it might need ldconfig would be that there was a previous library, of the same name, in a different place. The loader should search the default LD_LIBRARYPATH if there was no entry in the cache and the default LD_LIBRARYPATH should include /usr/lib.

If anything, what the LD_LIBRARYPATH issues suggests is that there is a library on the default LD_LIBRARYPATH that is unusable, but of the right name, so by eliminating the other directories on the default path, you are invalidating the cache entries for them.

In terms of the history of Unix, ldconfig and the shared object cache is relatively recent, compared with the use of /usr/lib.
david55
Moves Like Spencer
 
Posts: 12570
Joined: Fri Sep 26, 2008 5:03 am

Re: Init script

Postby moferreira » Sat Nov 23, 2013 11:58 am

Well... Some more info. I am using the following when I finish installing:

# Fix the problem with the library
ldconfig

# Make Asterisk run as asterisk user
adduser -c "asterisk" -r -s /bin/false asterisk
sed -i 's|;runuser|runuser|' /etc/asterisk/asterisk.conf
sed -i 's|;rungroup|rungroup|' /etc/asterisk/asterisk.conf

# Change necessary file permissions
chown -R asterisk:asterisk /usr/lib/asterisk/
chown -R asterisk:asterisk /var/lib/asterisk/
chown -R asterisk:asterisk /var/spool/asterisk/
chown -R asterisk:asterisk /var/log/asterisk/
chown -R asterisk:asterisk /var/run/asterisk/
chown -R asterisk:asterisk /usr/sbin/asterisk
# Finished

Now, if I start Asterisk issuing "asterisk -U asterisk -G asterisk -cvvvvv", it works. However, when I try "service asterisk start" and then I do a "service asterisk status" I get: "asterisk dead but subsys locked".

When I try to stop it, I get:

service asterisk stop
Stopping safe_asterisk: [ OK ]
Shutting down asterisk: [FAILED]

Now I am locked! I get no clue from where I should start to fix it.
moferreira
Newsterisk
 
Posts: 11
Joined: Sat Nov 16, 2013 6:20 am

Re: Init script

Postby miken32 » Wed Apr 09, 2014 10:11 pm

Just for anyone looking to troubleshoot similar problems, there are a few things going on that really shut Asterisk up and hide important debugging information. In my case safe_asterisk was starting up, but nothing else happened. Not a single byte of logging, so I had to get it making some noise.

First, in /etc/init.d/asterisk you can edit this line:
Code: Select all
daemon sh -c "$DAEMON $ASTARGS -c" >/dev/null </dev/null 2>&1 &

Remove the redirection to get some error messages:
Code: Select all
daemon sh -c "$DAEMON $ASTARGS -c"


If that doesn't do the trick, you can also prevent Asterisk from outputting to TTY9 by commenting out this line in /usr/sbin/safe_asterisk:
Code: Select all
TTY=9


By using these two methods I was able to figure out two problems that were tripping Asterisk up (missing PID file and typo in the asterisk.conf runuser.)
miken32
Newsterisk
 
Posts: 2
Joined: Mon Mar 05, 2012 11:27 am

Re: Init script

Postby larrymcp » Mon Jan 04, 2016 2:09 am

Hey! Got the answer, now over two years later... just posting this for posterity.

This answer was originally provided by Russell Bryant on another forum. If you're running 64-bit CentOS 6.x (and maybe others), libasteriskssl should be installed into /usr/lib64. If you're installing from source, Asterisk will install it to /usr/lib/ by default, which is wrong. To fix it, you must add an option when running configure:

Code: Select all
./configure --libdir=/usr/lib64
larrymcp
Newsterisk
 
Posts: 1
Joined: Mon Jan 04, 2016 2:03 am


Return to Asterisk Support

Who is online

Users browsing this forum: Google [Bot] and 1 guest