LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   service won't start at boot (https://www.linuxquestions.org/questions/linux-newbie-8/service-wont-start-at-boot-810004/)

jgonsalves 05-25-2010 09:05 AM

service won't start at boot
 
I have a service/daemon that won't start from boot.
I have used the chkconfig --add <script name> command that went ok
I also used the chkconfig <script name> on and that seems to be fine and I have made the script executable Chmod 777 <filename>. By all account it looks like the script is running at boot the the services has not started. When I do a ps -ef | grep ndb_mgmd this process is no there. the script can be run from the console and sems to run fine! can anyone shed some light on this. here is my script.

#!/bin/bash
# chkconfig: 345 70 30
# description: MySQL Cluster management server start/stop script
echo hello Paul >> /tmp/hello.txt
configdir=/var/lib/mysql-cluster/
configini=$configdir/config.ini
managementnodeid=1
portnumber=1186
initial=

STARTMGM="/usr/sbin/ndb_mgmd -f $configini --ndb-nodeid=$managementnodeid $initial --configdir=$configdir"

start() {
$STARTMGM
echo start >> /tmp/hello.txt
}

stop() {
ndb_mgm -c host=127.0.0.1:$portnumber -e "$managementnodeid stop"
echo stop >> /tmp/hello.txt
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac

smoker 05-25-2010 11:44 AM

Try putting your external commands in brackets :

ie.

Code:

start() {
$(/usr/sbin/ndb_mgmd -f "$configini --ndb-nodeid=$managementnodeid $initial --configdir=$configdir")
echo start >> /tmp/hello.txt
}

You can't call a variable like a function, so
Code:

start() {
$STARTMGM
echo start >> /tmp/hello.txt
}

won't work.

AFAIK, you have to double quote variables to expand them into their contents, so configini=$configdir/config.ini is probably not being defined properly either.

http://tldp.org/LDP/abs/html/

catkin 05-25-2010 12:26 PM

Hey smoker! What you been smoking?! :D

The /usr/sbin/ndb_mgmd command will run just fine without a surrounding $( ) and will not run with its arguments enclosed in double quotes as in "$configini --ndb-nodeid=$managementnodeid $initial --configdir=$configdir" because that will pass a single argument instead of several words.

And there is no need to double quote variables to expand them into their contents. If they contain embedded whitespace it may be necessary to avoid them being split into words at the whitespace but not when they are on the RHS of an assignment as in configini=$configdir/config.ini. It would work as configini="$configdir/config.ini" but such double quoting is not necessary.

@jgonsalves: IDK the ndb_mgm command but "$managementnodeid stop" is unusual; does it really need to be a single word? Should it not be "$managementnodeid" stop ? If so it's surprising that the script works when "run from the console". Are you 100% sure it works then?

jgonsalves 05-26-2010 06:52 AM

Thanks for the replies Guys but none of your suggestions worked. This script was copied from a duplicate server that seems to work fine and I can start and stop the script from the console. Iam running this on a Fedora 11 build. although I do think it's something to do with the script.

alli_yas 05-26-2010 07:20 AM

Quote:

although I do think it's something to do with the script.
Can you run the script from the terminal and post the output?

jgonsalves 05-26-2010 07:29 AM

Run with the start call
[root@UKLX-PRMGM ~]# /etc/init.d/ndb_mgmd start
2010-05-26 13:20:32 [MgmtSrvr] INFO -- NDB Cluster Management Server. mysql-5.1.39 ndb-7.0.9b
2010-05-26 13:20:32 [MgmtSrvr] INFO -- Loaded config from '/etc/mysql/ndb_1_config.bin.1'
[root@UKLX-PRMGM ~]#

Run with the stop call
[root@UKLX-PRMGM ~]# /etc/init.d/ndb_mgmd stop
Connected to Management Server at: 127.0.0.1:1186
Node 1 has shutdown.
Disconnecting to allow Management Server to shutdown

it all seems to working fine from the console but won't start up from boot

catkin 05-26-2010 08:07 AM

Quote:

Originally Posted by jgonsalves (Post 3981651)
Thanks for the replies Guys but none of your suggestions worked. This script was copied from a duplicate server that seems to work fine and I can start and stop the script from the console. Iam running this on a Fedora 11 build. although I do think it's something to do with the script.

OK.

When you write "it looks like the script is running at boot", what happens? Presumably /tmp/hello.txt is populated with "hello Paul" and "start" -- and you are confident those were written during boot, not during some previous testing (might be helpful to add /usr/bin/date >> /tmp/hello.txt before echo hello Paul >> /tmp/hello.txt).

In which case, if you get "start" in /tmp/hello.txt you are confident that the start function has run. The only effective line in the start function is $STARTMGM so we can focus on that. Perhaps that has a different value when run as a boot script and when run interactively (it's hard to see how but we've nothing else to work on). If not there is something about the process environment which the command runs in which is different.

How about adding some debugging to the start function?
Code:

for word in $STARTMGM
do
    echo "'$word'" >> /tmp/hello.txt
done
env >> /tmp/hello.txt
$STARTMGM &>> /tmp/hello.txt
/usr/bin/ps -ef | /usr/bin/grep -v grep | /usr/bin/grep ndb_mgmd >> /tmp/hello.txt

Then you could remove /tmp/hello.txt, run the script from a command line, rename /tmp/hello.txt, boot and then compare the new /tmp/hello.txt with the renamed one.

jgonsalves 05-26-2010 08:12 AM

I2010-05-26 13:07:19 [MgmtSrvr] INFO -- NDB Cluster Management Server. mysql-5.1.39 ndb-7.0.9b
2010-05-26 13:07:19 [MgmtSrvr] INFO -- Loaded config from '/etc/mysql/ndb_1_config.bin.1'
2010-05-26 13:07:19 [MgmtSrvr] ERROR -- The hostname this node should have according to the configuration does not match a local interface. Attempt to bind '192.168.202.232' failed with error: 99 'Cannot assign requested address' think I have found the problem I had A look in the boot log and found this:

I will try to put a sllep command in the csript to allow the ipaddress to be configured. unless you can give me a better alternative.

jgonsalves 05-26-2010 08:39 AM

-solved
 
Thanks for your help chaps I have put a 5 second sleep command in the script giving the system time to get an IP address and the process now come up at boot.

catkin 05-26-2010 08:42 AM

Putting a sleep in the script will certainly delay the boot and will not fix the problem if the boot script that sets up the IP requirements runs after this one.

You could change the # chkconfig: 345 70 30 line to # chkconfig: 345 98 01 (I think that is the right way round for a late start and early finish) and then run chkconfig to remove the old and run it again to add the new. With a bit of luck that will result in the script running late enough in the boot process for the IP to have been configured.


All times are GMT -5. The time now is 04:47 AM.