home *** CD-ROM | disk | FTP | other *** search
/ chilidog.highland.cc.ks.us / chilidog.highland.cc.ks.us.zip / chilidog.highland.cc.ks.us / backup / bradford.20120521.etc.tar.gz / bradford.20120521.etc.tar / etc / init.d / skeleton.compat < prev    next >
Text File  |  2005-10-18  |  13KB  |  367 lines

  1. #!/bin/bash
  2. #
  3. #     Template LSB system startup script for example service/daemon FOO
  4. #     Copyright (C) 1995--2005  Kurt Garloff, SUSE / Novell Inc.
  5. #          
  6. #     This library is free software; you can redistribute it and/or modify it
  7. #     under the terms of the GNU Lesser General Public License as published by
  8. #     the Free Software Foundation; either version 2.1 of the License, or (at
  9. #     your option) any later version.
  10. #                  
  11. #     This library is distributed in the hope that it will be useful, but
  12. #     WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14. #     Lesser General Public License for more details.
  15. #      
  16. #     You should have received a copy of the GNU Lesser General Public
  17. #     License along with this library; if not, write to the Free Software
  18. #     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
  19. #     USA.
  20. #
  21. # /etc/init.d/FOO
  22. # LSB compatible service control script; see http://www.linuxbase.org/spec/
  23. # Please send feedback to http://www.suse.de/feedback/
  24. # Note: This template uses functions rc_XXX defined in /etc/rc.status on
  25. # UnitedLinux/SUSE/Novell based Linux distributions. However, it will work
  26. # on other distributions as well, by using the LSB (Linux Standard Base) 
  27. # or RH functions or by open coding the needed functions.
  28. # Read http://www.tldp.org/HOWTO/HighQuality-Apps-HOWTO/ if you prefer not 
  29. # to use this template.
  30. #
  31. # chkconfig: 345 99 00
  32. # description: FOO XYZ daemon providing ZYX
  33. ### BEGIN INIT INFO
  34. # Provides:          FOO
  35. # Required-Start:    $syslog $remote_fs
  36. # Should-Start: $time ypbind sendmail
  37. # Required-Stop:     $syslog $remote_fs
  38. # Should-Stop: $time ypbind sendmail
  39. # Default-Start:     3 4 5
  40. # Default-Stop:      0 1 2 6
  41. # Short-Description: FOO XYZ daemon providing ZYX
  42. # Description:       Start FOO to allow XY and provide YZ
  43. #    continued on second line by '#<TAB>'
  44. #    should contain enough info for the runlevel editor
  45. #    to give admin some idea what this service does and
  46. #    what it's needed for ...
  47. #    (The Short-Description should already be a good hint.)
  48. ### END INIT INFO
  49. # Any extensions to the keywords given above should be preceeded by 
  50. # X-VendorTag- according to LSB.
  51. # Notes on Required-Start/Should-Start:
  52. # * There are two different issues that are solved by Required-Start
  53. #    and Should-Start
  54. # (a) Hard dependencies: This is used by the runlevel editor to determine
  55. #     which services absolutely need to be started to make the start of
  56. #     this service make sense. Example: nfsserver should have
  57. #     Required-Start: $portmap
  58. #     Also, required services are started before the dependent ones.
  59. #     The runlevel editor will warn about such missing hard dependencies
  60. #     and suggest enabling. During system startup, you may expect an error,
  61. #     if the dependency is not fulfilled.
  62. # (b) Specifying the init script ordering, not real (hard) dependencies.
  63. #     This is needed by insserv to determine which service should be
  64. #     started first (and at a later stage what services can be started
  65. #     in parallel). The tag Should-Start: is used for this.
  66. #     It tells, that if a service is available, it should be started
  67. #     before. If not, never mind.
  68. # * When specifying hard dependencies or ordering requirements, you can 
  69. #   use names of services (contents of their Provides: section)
  70. #   or pseudo names starting with a $. The following ones are available
  71. #   according to LSB (1.1):
  72. #    $local_fs        all local file systems are mounted
  73. #                (most services should need this!)
  74. #    $remote_fs        all remote file systems are mounted
  75. #                (note that /usr may be remote, so
  76. #                 many services should Require this!)
  77. #    $syslog            system logging facility up
  78. #    $network        low level networking (eth card, ...)
  79. #    $named            hostname resolution available
  80. #    $netdaemons        all network daemons are running
  81. #   The $netdaemons pseudo service has been removed in LSB 1.2.
  82. #   For now, we still offer it for backward compatibility.
  83. #   These are new (LSB 1.2):
  84. #    $time            the system time has been set correctly    
  85. #    $portmap        SunRPC portmapping service available
  86. #   UnitedLinux/SUSE/Novell extensions:
  87. #    $ALL            indicates that a script should be inserted
  88. #                at the end
  89. # * The services specified in the stop tags 
  90. #   (Required-Stop/Should-Stop)
  91. #   specify which services need to be still running when this service
  92. #   is shut down. Often the entries there are just copies or a subset 
  93. #   from the respective start tag.
  94. # * Should-Start/Stop are now part of LSB as of 2.0,
  95. #   formerly SUSE/Unitedlinux used X-UnitedLinux-Should-Start/-Stop.
  96. #   insserv does support both variants.
  97. # * X-UnitedLinux-Default-Enabled: yes/no is used at installation time
  98. #   (%fillup_and_insserv macro in %post of many RPMs) to specify whether
  99. #   a startup script should default to be enabled after installation.
  100. #
  101. # Note on runlevels:
  102. # 0 - halt/poweroff             6 - reboot
  103. # 1 - single user            2 - multiuser without network exported
  104. # 3 - multiuser w/ network (text mode)  5 - multiuser w/ network and X11 (xdm)
  105. # Note on script names:
  106. # http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/scrptnames.html
  107. # A registry has been set up to manage the init script namespace.
  108. # http://www.lanana.org/
  109. # Please use the names already registered or register one or use a
  110. # vendor prefix.
  111.  
  112.  
  113. # Check for missing binaries (stale symlinks should not happen)
  114. # Note: Special treatment of stop for LSB conformance
  115. FOO_BIN=/usr/sbin/FOO
  116. test -x $FOO_BIN || { echo "$FOO_BIN not installed"; 
  117.     if [ "$1" = "stop" ]; then exit 0;
  118.     else exit 5; fi; }
  119.  
  120. # Check for existence of needed config file and read it
  121. FOO_CONFIG=/etc/sysconfig/FOO
  122. test -r $FOO_CONFIG || { echo "$FOO_CONFIG not existing";
  123.     if [ "$1" = "stop" ]; then exit 0;
  124.     else exit 6; fi; }
  125.  
  126. # Read config    
  127. . $FOO_CONFIG
  128.  
  129. # Source LSB init functions
  130. # providing start_daemon, killproc, pidofproc, 
  131. # log_success_msg, log_failure_msg and log_warning_msg.
  132. # This is currently not used by UnitedLinux based distributions and
  133. # not needed for init scripts for UnitedLinux only. If it is used,
  134. # the functions from rc.status should not be sourced or used.
  135. #. /lib/lsb/init-functions
  136.  
  137. # Shell functions sourced from /etc/rc.status:
  138. #      rc_check         check and set local and overall rc status
  139. #      rc_status        check and set local and overall rc status
  140. #      rc_status -v     be verbose in local rc status and clear it afterwards
  141. #      rc_status -v -r  ditto and clear both the local and overall rc status
  142. #      rc_status -s     display "skipped" and exit with status 3
  143. #      rc_status -u     display "unused" and exit with status 3
  144. #      rc_failed        set local and overall rc status to failed
  145. #      rc_failed <num>  set local and overall rc status to <num>
  146. #      rc_reset         clear both the local and overall rc status
  147. #      rc_exit          exit appropriate to overall rc status
  148. #      rc_active        checks whether a service is activated by symlinks
  149.  
  150. # Use the SUSE rc_ init script functions;
  151. # emulate them on LSB, RH and other systems
  152.  
  153. # Default: Assume sysvinit binaries exist
  154. start_daemon() { return /sbin/start_daemon ${1+"$@"}; }
  155. killproc()     { return /sbin/killproc     ${1+"$@"}; }
  156. pidofproc()    { return /sbin/pidofproc    ${1+"$@"}; }
  157. checkproc()    { return /sbin/checkproc    ${1+"$@"}; }
  158. if test -e /etc/rc.status; then
  159.     # SUSE rc script library
  160.     . /etc/rc.status
  161. else
  162.     export LC_ALL=POSIX
  163.     _cmd=$1
  164.     declare -a _SMSG
  165.     if test "${_cmd}" = "status"; then
  166.     _SMSG=(running dead dead unused unknown reserved)
  167.     _RC_UNUSED=3
  168.     else
  169.     _SMSG=(done failed failed missed failed skipped unused failed failed reserved)
  170.     _RC_UNUSED=6
  171.     fi
  172.     if test -e /lib/lsb/init-functions; then
  173.     # LSB    
  174.         . /lib/lsb/init-functions
  175.     echo_rc()
  176.     {
  177.         if test ${_RC_RV} = 0; then
  178.         log_success_msg "  [${_SMSG[${_RC_RV}]}] "
  179.         else
  180.         log_failure_msg "  [${_SMSG[${_RC_RV}]}] "
  181.         fi
  182.     }
  183.     # TODO: Add checking for lockfiles
  184.     checkproc() { return pidofproc ${1+"$@"} >/dev/null 2>&1; }
  185.     elif test -e /etc/init.d/functions; then
  186.     # RHAT
  187.     . /etc/init.d/functions
  188.     echo_rc()
  189.     {
  190.         #echo -n "  [${_SMSG[${_RC_RV}]}] "
  191.         if test ${_RC_RV} = 0; then
  192.         success "  [${_SMSG[${_RC_RV}]}] "
  193.         else
  194.         failure "  [${_SMSG[${_RC_RV}]}] "
  195.         fi
  196.     }
  197.     checkproc() { return status ${1+"$@"}; }
  198.     start_daemon() { return daemon ${1+"$@"}; }
  199.     else
  200.     # emulate it
  201.     echo_rc() { echo "  [${_SMSG[${_RC_RV}]}] "; }
  202.     fi
  203.     rc_reset() { _RC_RV=0; }
  204.     rc_failed()
  205.     {
  206.     if test -z "$1"; then 
  207.         _RC_RV=1;
  208.     elif test "$1" != "0"; then 
  209.         _RC_RV=$1; 
  210.         fi
  211.     return ${_RC_RV}
  212.     }
  213.     rc_check()
  214.     {
  215.     return rc_failed $?
  216.     }    
  217.     rc_status()
  218.     {
  219.     rc_failed $?
  220.     if test "$1" = "-r"; then _RC_RV=0; shift; fi
  221.     if test "$1" = "-s"; then rc_failed 5; echo_rc; rc_failed 3; shift; fi
  222.     if test "$1" = "-u"; then rc_failed ${_RC_UNUSED}; echo_rc; rc_failed 3; shift; fi
  223.     if test "$1" = "-v"; then echo_rc; shift; fi
  224.     if test "$1" = "-r"; then _RC_RV=0; shift; fi
  225.     return ${_RC_RV}
  226.     }
  227.     rc_exit() { exit ${_RC_RV}; }
  228.     rc_active() 
  229.     {
  230.     if test -z "$RUNLEVEL"; then read RUNLEVEL REST < <(/sbin/runlevel); fi
  231.     if test -e /etc/init.d/S[0-9][0-9]${1}; then return 0; fi
  232.     return 1
  233.     }
  234. fi
  235.  
  236. # Reset status of this service
  237. rc_reset
  238.  
  239. # Return values acc. to LSB for all commands but status:
  240. # 0      - success
  241. # 1       - generic or unspecified error
  242. # 2       - invalid or excess argument(s)
  243. # 3       - unimplemented feature (e.g. "reload")
  244. # 4       - user had insufficient privileges
  245. # 5       - program is not installed
  246. # 6       - program is not configured
  247. # 7       - program is not running
  248. # 8--199  - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
  249. # Note that starting an already running service, stopping
  250. # or restarting a not-running service as well as the restart
  251. # with force-reload (in case signaling is not supported) are
  252. # considered a success.
  253.  
  254. case "$1" in
  255.     start)
  256.     echo -n "Starting FOO "
  257.     ## Start daemon with startproc(8). If this fails
  258.     ## the return value is set appropriately by startproc.
  259.     start_daemon $FOO_BIN
  260.  
  261.     # Remember status and be verbose
  262.     rc_status -v
  263.     ;;
  264.     stop)
  265.     echo -n "Shutting down FOO "
  266.     ## Stop daemon with killproc(8) and if this fails
  267.     ## killproc sets the return value according to LSB.
  268.  
  269.     killproc -TERM $FOO_BIN
  270.  
  271.     # Remember status and be verbose
  272.     rc_status -v
  273.     ;;
  274.     try-restart|condrestart)
  275.     ## Do a restart only if the service was active before.
  276.     ## Note: try-restart is now part of LSB (as of 1.9).
  277.     ## RH has a similar command named condrestart.
  278.     if test "$1" = "condrestart"; then
  279.         echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
  280.     fi
  281.     $0 status
  282.     if test $? = 0; then
  283.         $0 restart
  284.     else
  285.         rc_reset    # Not running is not a failure.
  286.     fi
  287.     # Remember status and be quiet
  288.     rc_status
  289.     ;;
  290.     restart)
  291.     ## Stop the service and regardless of whether it was
  292.     ## running or not, start it again.
  293.     $0 stop
  294.     $0 start
  295.  
  296.     # Remember status and be quiet
  297.     rc_status
  298.     ;;
  299.     force-reload)
  300.     ## Signal the daemon to reload its config. Most daemons
  301.     ## do this on signal 1 (SIGHUP).
  302.     ## If it does not support it, restart the service if it
  303.     ## is running.
  304.  
  305.     echo -n "Reload service FOO "
  306.     ## if it supports it:
  307.     killproc -HUP $FOO_BIN
  308.     #touch /var/run/FOO.pid
  309.     rc_status -v
  310.  
  311.     ## Otherwise:
  312.     #$0 try-restart
  313.     #rc_status
  314.     ;;
  315.     reload)
  316.     ## Like force-reload, but if daemon does not support
  317.     ## signaling, do nothing (!)
  318.  
  319.     # If it supports signaling:
  320.     echo -n "Reload service FOO "
  321.     killproc -HUP $FOO_BIN
  322.     #touch /var/run/FOO.pid
  323.     rc_status -v
  324.     
  325.     ## Otherwise if it does not support reload:
  326.     #rc_failed 3
  327.     #rc_status -v
  328.     ;;
  329.     status)
  330.     echo -n "Checking for service FOO "
  331.     ## Check status with checkproc(8), if process is running
  332.     ## checkproc will return with exit status 0.
  333.  
  334.     # Return value is slightly different for the status command:
  335.     # 0 - service up and running
  336.     # 1 - service dead, but /var/run/  pid  file exists
  337.     # 2 - service dead, but /var/lock/ lock file exists
  338.     # 3 - service not running (unused)
  339.     # 4 - service status unknown :-(
  340.     # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
  341.     
  342.     # NOTE: checkproc returns LSB compliant status values.
  343.     checkproc $FOO_BIN
  344.     # NOTE: rc_status knows that we called this init script with
  345.     # "status" option and adapts its messages accordingly.
  346.     rc_status -v
  347.     ;;
  348.     probe)
  349.     ## Optional: Probe for the necessity of a reload, print out the
  350.     ## argument to this init script which is required for a reload.
  351.     ## Note: probe is not (yet) part of LSB (as of 1.9)
  352.  
  353.     test /etc/FOO/FOO.conf -nt /var/run/FOO.pid && echo reload
  354.     ;;
  355.     *)
  356.     echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
  357.     exit 1
  358.     ;;
  359. esac
  360. rc_exit
  361.