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.20120305.etc.tar.gz / bradford.20120305.etc.tar / etc / init.d / skeleton < prev    next >
Text File  |  2005-10-18  |  11KB  |  284 lines

  1. #!/bin/sh
  2. #
  3. #     Template SUSE 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. #   and its symbolic link
  23. # /(usr/)sbin/rcFOO
  24. #
  25. # Template system startup script for some example service/daemon FOO
  26. #
  27. # LSB compatible service control script; see http://www.linuxbase.org/spec/
  28. # Note: This template uses functions rc_XXX defined in /etc/rc.status on
  29. # UnitedLinux/SUSE/Novell based Linux distributions. If you want to base your
  30. # script on this template and ensure that it works on non UL based LSB 
  31. # compliant Linux distributions, you either have to provide the rc.status
  32. # functions from UL or change the script to work without them.
  33. # See skeleton.compat for a template that works with other distros as well.
  34. #
  35. ### BEGIN INIT INFO
  36. # Provides:          FOO
  37. # Required-Start:    $syslog $remote_fs
  38. # Should-Start: $time ypbind sendmail
  39. # Required-Stop:     $syslog $remote_fs
  40. # Should-Stop: $time ypbind sendmail
  41. # Default-Start:     3 5
  42. # Default-Stop:      0 1 2 6
  43. # Short-Description: FOO XYZ daemon providing ZYX
  44. # Description:       Start FOO to allow XY and provide YZ
  45. #    continued on second line by '#<TAB>'
  46. #    should contain enough info for the runlevel editor
  47. #    to give admin some idea what this service does and
  48. #    what it's needed for ...
  49. #    (The Short-Description should already be a good hint.)
  50. ### END INIT INFO
  51. # Any extensions to the keywords given above should be preceeded by 
  52. # X-VendorTag- (X-UnitedLinux- X-SuSE- for us) according to LSB.
  53. # Notes on Required-Start/Should-Start:
  54. # * There are two different issues that are solved by Required-Start
  55. #    and Should-Start
  56. # (a) Hard dependencies: This is used by the runlevel editor to determine
  57. #     which services absolutely need to be started to make the start of
  58. #     this service make sense. Example: nfsserver should have
  59. #     Required-Start: $portmap
  60. #     Also, required services are started before the dependent ones.
  61. #     The runlevel editor will warn about such missing hard dependencies
  62. #     and suggest enabling. During system startup, you may expect an error,
  63. #     if the dependency is not fulfilled.
  64. # (b) Specifying the init script ordering, not real (hard) dependencies.
  65. #     This is needed by insserv to determine which service should be
  66. #     started first (and at a later stage what services can be started
  67. #     in parallel). The tag Should-Start: is used for this.
  68. #     It tells, that if a service is available, it should be started
  69. #     before. If not, never mind.
  70. # * When specifying hard dependencies or ordering requirements, you can 
  71. #   use names of services (contents of their Provides: section)
  72. #   or pseudo names starting with a $. The following ones are available
  73. #   according to LSB (1.1):
  74. #    $local_fs        all local file systems are mounted
  75. #                (most services should need this!)
  76. #    $remote_fs        all remote file systems are mounted
  77. #                (note that /usr may be remote, so
  78. #                 many services should Require this!)
  79. #    $syslog            system logging facility up
  80. #    $network        low level networking (eth card, ...)
  81. #    $named            hostname resolution available
  82. #    $netdaemons        all network daemons are running
  83. #   The $netdaemons pseudo service has been removed in LSB 1.2.
  84. #   For now, we still offer it for backward compatibility.
  85. #   These are new (LSB 1.2):
  86. #    $time            the system time has been set correctly    
  87. #    $portmap        SunRPC portmapping service available
  88. #   UnitedLinux extensions:
  89. #    $ALL            indicates that a script should be inserted
  90. #                at the end
  91. # * The services specified in the stop tags 
  92. #   (Required-Stop/Should-Stop)
  93. #   specify which services need to be still running when this service
  94. #   is shut down. Often the entries there are just copies or a subset 
  95. #   from the respective start tag.
  96. # * Should-Start/Stop are now part of LSB as of 2.0,
  97. #   formerly SUSE/Unitedlinux used X-UnitedLinux-Should-Start/-Stop.
  98. #   insserv does support both variants.
  99. # * X-UnitedLinux-Default-Enabled: yes/no is used at installation time
  100. #   (%fillup_and_insserv macro in %post of many RPMs) to specify whether
  101. #   a startup script should default to be enabled after installation.
  102. #   It's not used by insserv.
  103. #
  104. # Note on runlevels:
  105. # 0 - halt/poweroff             6 - reboot
  106. # 1 - single user            2 - multiuser without network exported
  107. # 3 - multiuser w/ network (text mode)  5 - multiuser w/ network and X11 (xdm)
  108. # Note on script names:
  109. # http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/scrptnames.html
  110. # A registry has been set up to manage the init script namespace.
  111. # http://www.lanana.org/
  112. # Please use the names already registered or register one or use a
  113. # vendor prefix.
  114.  
  115.  
  116. # Check for missing binaries (stale symlinks should not happen)
  117. # Note: Special treatment of stop for LSB conformance
  118. FOO_BIN=/usr/sbin/FOO
  119. test -x $FOO_BIN || { echo "$FOO_BIN not installed"; 
  120.     if [ "$1" = "stop" ]; then exit 0;
  121.     else exit 5; fi; }
  122.  
  123. # Check for existence of needed config file and read it
  124. FOO_CONFIG=/etc/sysconfig/FOO
  125. test -r $FOO_CONFIG || { echo "$FOO_CONFIG not existing";
  126.     if [ "$1" = "stop" ]; then exit 0;
  127.     else exit 6; fi; }
  128.  
  129. # Read config    
  130. . $FOO_CONFIG
  131.  
  132. # Source LSB init functions
  133. # providing start_daemon, killproc, pidofproc, 
  134. # log_success_msg, log_failure_msg and log_warning_msg.
  135. # This is currently not used by UnitedLinux based distributions and
  136. # not needed for init scripts for UnitedLinux only. If it is used,
  137. # the functions from rc.status should not be sourced or used.
  138. #. /lib/lsb/init-functions
  139.  
  140. # Shell functions sourced from /etc/rc.status:
  141. #      rc_check         check and set local and overall rc status
  142. #      rc_status        check and set local and overall rc status
  143. #      rc_status -v     be verbose in local rc status and clear it afterwards
  144. #      rc_status -v -r  ditto and clear both the local and overall rc status
  145. #      rc_status -s     display "skipped" and exit with status 3
  146. #      rc_status -u     display "unused" and exit with status 3
  147. #      rc_failed        set local and overall rc status to failed
  148. #      rc_failed <num>  set local and overall rc status to <num>
  149. #      rc_reset         clear both the local and overall rc status
  150. #      rc_exit          exit appropriate to overall rc status
  151. #      rc_active        checks whether a service is activated by symlinks
  152. . /etc/rc.status
  153.  
  154. # Reset status of this service
  155. rc_reset
  156.  
  157. # Return values acc. to LSB for all commands but status:
  158. # 0      - success
  159. # 1       - generic or unspecified error
  160. # 2       - invalid or excess argument(s)
  161. # 3       - unimplemented feature (e.g. "reload")
  162. # 4       - user had insufficient privileges
  163. # 5       - program is not installed
  164. # 6       - program is not configured
  165. # 7       - program is not running
  166. # 8--199  - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
  167. # Note that starting an already running service, stopping
  168. # or restarting a not-running service as well as the restart
  169. # with force-reload (in case signaling is not supported) are
  170. # considered a success.
  171.  
  172. case "$1" in
  173.     start)
  174.     echo -n "Starting FOO "
  175.     ## Start daemon with startproc(8). If this fails
  176.     ## the return value is set appropriately by startproc.
  177.     /sbin/startproc $FOO_BIN
  178.  
  179.     # Remember status and be verbose
  180.     rc_status -v
  181.     ;;
  182.     stop)
  183.     echo -n "Shutting down FOO "
  184.     ## Stop daemon with killproc(8) and if this fails
  185.     ## killproc sets the return value according to LSB.
  186.  
  187.     /sbin/killproc -TERM $FOO_BIN
  188.  
  189.     # Remember status and be verbose
  190.     rc_status -v
  191.     ;;
  192.     try-restart|condrestart)
  193.     ## Do a restart only if the service was active before.
  194.     ## Note: try-restart is now part of LSB (as of 1.9).
  195.     ## RH has a similar command named condrestart.
  196.     if test "$1" = "condrestart"; then
  197.         echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
  198.     fi
  199.     $0 status
  200.     if test $? = 0; then
  201.         $0 restart
  202.     else
  203.         rc_reset    # Not running is not a failure.
  204.     fi
  205.     # Remember status and be quiet
  206.     rc_status
  207.     ;;
  208.     restart)
  209.     ## Stop the service and regardless of whether it was
  210.     ## running or not, start it again.
  211.     $0 stop
  212.     $0 start
  213.  
  214.     # Remember status and be quiet
  215.     rc_status
  216.     ;;
  217.     force-reload)
  218.     ## Signal the daemon to reload its config. Most daemons
  219.     ## do this on signal 1 (SIGHUP).
  220.     ## If it does not support it, restart the service if it
  221.     ## is running.
  222.  
  223.     echo -n "Reload service FOO "
  224.     ## if it supports it:
  225.     /sbin/killproc -HUP $FOO_BIN
  226.     #touch /var/run/FOO.pid
  227.     rc_status -v
  228.  
  229.     ## Otherwise:
  230.     #$0 try-restart
  231.     #rc_status
  232.     ;;
  233.     reload)
  234.     ## Like force-reload, but if daemon does not support
  235.     ## signaling, do nothing (!)
  236.  
  237.     # If it supports signaling:
  238.     echo -n "Reload service FOO "
  239.     /sbin/killproc -HUP $FOO_BIN
  240.     #touch /var/run/FOO.pid
  241.     rc_status -v
  242.     
  243.     ## Otherwise if it does not support reload:
  244.     #rc_failed 3
  245.     #rc_status -v
  246.     ;;
  247.     status)
  248.     echo -n "Checking for service FOO "
  249.     ## Check status with checkproc(8), if process is running
  250.     ## checkproc will return with exit status 0.
  251.  
  252.     # Return value is slightly different for the status command:
  253.     # 0 - service up and running
  254.     # 1 - service dead, but /var/run/  pid  file exists
  255.     # 2 - service dead, but /var/lock/ lock file exists
  256.     # 3 - service not running (unused)
  257.     # 4 - service status unknown :-(
  258.     # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
  259.     
  260.     # NOTE: checkproc returns LSB compliant status values.
  261.     /sbin/checkproc $FOO_BIN
  262.     # NOTE: rc_status knows that we called this init script with
  263.     # "status" option and adapts its messages accordingly.
  264.     rc_status -v
  265.     ;;
  266.     probe)
  267.     ## Optional: Probe for the necessity of a reload, print out the
  268.     ## argument to this init script which is required for a reload.
  269.     ## Note: probe is not (yet) part of LSB (as of 1.9)
  270.  
  271.     test /etc/FOO/FOO.conf -nt /var/run/FOO.pid && echo reload
  272.     ;;
  273.     *)
  274.     echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
  275.     exit 1
  276.     ;;
  277. esac
  278. rc_exit
  279.