LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   could use some help with my init.d script.... (http://www.linuxquestions.org/questions/linux-general-1/could-use-some-help-with-my-init-d-script-34220/)

BrianK 10-30-2002 10:45 PM

could use some help with my init.d script....
 
hello all... I'm new to this whole daemon thing.. trying to feel my way through. If someone could point me in the right direction, I'd be much appreciative.

I need to start my server program when the machine boots.. I figured it would need to startup at run level 3 & be started at level 4 & 5... the priority is low, so I've made links to this script in rc3, 4, &5.d as S99mlserver and in rc0,1,&2.d as K8mlserver. The script is /etc/init.d/mlserver and looks like this:

Code:

#!/bin/bash
#
# chkconfig: 345 99 8
#             

# See how we were called.
case "$1" in
  start)
        # Start up the server
        /usr/local/martianServer
        ;;
  stop)
        # Stop the server
        kill -9 martianServer
        ;;
  restart|reload)
        # stop it & start it again
        kill -9 martianServer
        /usr/local/martianServer
        ;;
  *)
        # do not advertise unreasonable commands that there is no reason
        # to use with this device
        echo $"Usage: $0 {start|stop|restart|reload}"
        exit 1
esac

exit 0

also... do I need to do anything with chkconfig? should that be run at some point on the command line? Does the fact that something else starts with S99 screw up the startup? I assume that when the machine starts up, it runs through the rc#.d for each of the links as "link start" (in other words it passes the "start" argument to the linked script) - is that right? Is kill -9 a good way to stop the program, or is that bad form?

and help would be great.. thanks.

DavidPhillips 10-31-2002 12:21 AM

the S99 is relative to when it starts, so I guess you answered that yourself, the consideration is when do you want it to start in the sequence, maybe considering networking, firewall, etc. they don't need to be a unique number.


[root@www init.d]# chkconfig --list scriptname will show you what's setup

[root@www init.d]# chkconfig --list squid
squid 0:off 1:off 2:off 3:on 4:on 5:on 6:off


if it's links are not in the runlevels I can do

[root@www init.d]# chkconfig --add squid

[root@www init.d]# grep chkconfig squid
# chkconfig: - 90 25


the script contains the settings for chkconfig to use. so the links will be created

on this one the runlevels are set in the script as well

[root@www init.d]# grep chkconfig syslog
# chkconfig: 2345 12 88

you can use chkconfig to set one up like this...

some examples..

[root@www init.d]# chkconfig --list squid
squid 0:off 1:off 2:off 3:on 4:on 5:on 6:off

[root@www init.d]# chkconfig --level 2345 squid on

[root@www init.d]# chkconfig --list squid
squid 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@www init.d]# chkconfig --level 2 squid off

[root@www init.d]# chkconfig --list squid
squid 0:off 1:off 2:off 3:on 4:on 5:on 6:off

Mik 10-31-2002 03:33 AM

Does the kill -9 processname actually work? Depending on how your scripts are start up there should be helper functions around for starting and stopping daemons. Usually something like startproc and stopproc. They usually create a file with the pid of the daemon in /var/run. This pid is used to kill the daemon properly. One thing you shouldn't forget is that if you don't shut down properly the pid file won't get removed. So if you haven't setup your scripts properly to clear these files then your daemon would probably not start on the next boot.
But you should look at the other scripts there should be plenty of examples of how it's done.

BrianK 10-31-2002 08:21 PM

thanks guys... that was what I needed. :)


All times are GMT -5. The time now is 08:21 AM.