RE: RH9 Processes Failing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 12 Jan 2004, salvatore wrote:
> Needless to say, Im a bit new at this.  Ive been researching since your
> suggestion, and I havent found where a file in /etc/rc.d/init.d actually
> runs the application.

>From the looks of things you only looked at one "application" - there are 
many others and this one is probably not the best example.

A very good example to follow would be "smartd" (if you have it on your 
system) - I've pasted it below and commented it, it should be markedly 
easy to adpat.

> For example, here is the contents of the yum file there:
> ***
> # cat yum
> #!/bin/bash
> #
> # yum           This shell script enables the automatic use of YUM
> #
> # Author:       Seth Vidal <skvidal@xxxxxxxxxxxx>
> #
> # chkconfig:    - 50 01

This section tells chkconfig what runlevels to start and stop the script

> #
> # description:  Enable daily run of yum, a program updater.
> # processname:  yum
> # config: /etc/yum.conf

These are also used by chkconfig (I think) but tend to be good for 
reference

> #
> 
> # source function library
> . /etc/rc.d/init.d/functions
> 

This loads the general "redhat" function libraries which give a bunch of 
single line commands to make things easier and more "redhatty" such as 
killing processes and starting a process with a pretty "[ OK ]" if the 
startup worked.

> lockfile=/var/lock/subsys/yum
> 
> RETVAL=0
> 
> start() {
>         echo -n $"Enabling nightly yum update: "
>         touch "$lockfile" && success || failure
>         RETVAL=$?
>         echo
> }

This is the bit that does the actual startup - it creates a new command 
called "start" that touches /var/lock/subsys/yum, this in turn probably 
tells another process (possibly called from cron daily) that when it wakes 
up it should do something meaningful

> 
> stop() {
>         echo -n $"Disabling nightly yum update: "
>         rm -f "$lockfile" && success || failure
>         RETVAL=$?
>         echo
> }

This probably tells the same process that there is no need to do anything 
meaningful


> 
> restart() {
>         stop
>         start
> }
> 
> case "$1" in
>   start)
>         start
>         ;;

"create the lockfile that tells yum to do something when we run it daily"

>   stop)
>         stop
>         ;;

"delete the lockfile that tells yum to do something when we run it daily"

>   restart|force-reload)
>         restart
>         ;;
>   reload)
>         ;;
>   condrestart)
>         [ -f "$lockfile" ] && restart
>         ;;
>   status)
>         if [ -f $lockfile ]; then
>                 echo $"Nightly yum update is enabled."
>                 RETVAL=0
>         else
>                 echo $"Nightly yum update is disabled."
>                 RETVAL=3
>         fi
>         ;;
>   *)
>         echo $"Usage: $0
> {start|stop|status|restart|reload|force-reload|condrest
> art}"
>         exit 1
> esac
> 
> exit $RETVAL
> ***
> 
> What about that script actually runs anything?

This script doesnt run anything perse, but as above, it "enables" yum such 
that when another process is called it does something.

The part here you would be intested in is the structure of a start/stop 
file. Then you can figure out where it "does something" and "un-does 
something" and how it fits into the startup of the system (the chkconfig 
stuff and the case statement) and then write your own start/stop script.

A good simple example is as follows

[quote - smartd start/stop script ]
#!/bin/bash

# ucsc-smartsuite init file for smartd
#
# description: Self Monitoring and Reporting Technology (SMART) Daemon
#
# processname: smartd 
# chkconfig: - 45 45


# source function library
. /etc/rc.d/init.d/functions

case "$1" in
  start)
        echo -n "Starting smartd: "
        daemon /usr/sbin/smartd
        touch /var/lock/subsys/smartd
        echo
        ;;
  stop)
        echo -n "Shutting down smartd: "
        killproc smartd
        rm -f /var/lock/subsys/smartd
        echo
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  status)
        status smartd
        ;;
  *)
        echo "Usage: smartd {start|stop|restart|status}"
        exit 1
esac

exit 0

[/quote]

Here we can see all the elements of a start/stop script setting up the 
chkconfig entries, loading the function libs, then calling the start 
section, which "does stuff" and the stop section which "un-does stuff", in 
this case the "does stuff" is 

1. Print a pretty message               :- echo -n "Starting smartd: "                                                               
2. run the program and print the result :- daemon /usr/sbin/smartd                                                                   
3. set a lock file                      :- touch /var/lock/subsys/smartd                                                             
4. clean up the line                    :- echo                                                                                      

the "un-does stuff" is..

1. Print a pretty message             :- echo -n "Shutting down smartd: "
2. Kill the process called "smartd"   :- killproc smartd 
3. Remove the lockfile                :- rm -f /var/lock/subsys/smartd 
4. clean up the line                  :- echo

The chkconfig line tells us where the script should be inserted into the 
startup sequence and the shutdown sequence, this is important for a number 
of reasons and they depend on the program you are startting/stopping. The 
line also tells us what runlevels the program needs to run at which is 
also important. (no point in starting the networking daemons such as used 
for e-mail and remote connection if we are running in "no networking" mode 
- similarly, no point in starting the Xwindows helper apps if we are not 
running Xwindows)

chkconfig stuff..

# chkconfig: - 45 45

This says "Run this command in all run levels at position 45"

some examples that would be handy are..

# chkconfig: 235 80 30

"run this at run levels 2, 3 and 5 (the common networking+multi-user 
modes) at startup position 80 and shutdown position 30"

80 is sorta at the end of the start sequence and can be used for things 
such as web servers that require that some other services are started 
earlier (such as networking)

for things such as a web cam, you may require that

1. the system has initialised
2. The file systems are mounted
3. The networking system is running
4. A web server is running

as such you will want to start your camera after the http server has 
started (check the httpd chkconfig line)

> Where can I learn more about doing what Im looking for?

HTH somewhat,


-- 
Steve.


-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux