Start service at Linux startup

Basic premise:

  • /etc/inittab is a configuration file which describes which processes are started at bootup
    • The important config for startup programs launched is the run level:
      # The default runlevel is defined here
      id:3:initdefault:.d/
    • Here Runlevel 3 is configured.
    • This means that services which Runlevel 3 is defined will be launched on startup.
    • All services that are enabled to run at startup for this level can be found in /etc/init.d/rc3.dSimilarly, for other levels:
      rc0.d:
      S20halt
      
      rc1.d:
      K02single  K09splash  K10fbset  K21coldplug  S01coldplug  S12fbset  S13kbd  S13splash  S20single
      
      rc2.d:
      K02gpm          K07cups    K10rpmconfigcheck  K14splash_early  K16syslog    S01stqdaemon  S07snmpd         S09hprsm           S13splash  S17ivr
      K04plweb        K08hwscan  K10running-kernel  K15fazzt         K17network   S05network    S07weblogic      S12fbset           S14hwscan  S17splash_late
      K05ivr          K08xntpd   K13cmanic          K15informix      K21coldplug  S06syslog     S08hpasm         S12raw             S14xntpd   S18plweb
      K05splash_late  K09splash  K13hprsm           K15mms           K21random    S07fazzt      S08resmgr        S12rpmconfigcheck  S15cups    S20gpm
      K06atd          K10fbset   K14hpasm           K15snmpd         S01coldplug  S07informix   S08splash_early  S12running-kernel  S16atd
      K06cron         K10raw     K14resmgr          K15weblogic      S01random    S07mms        S09cmanic        S13kbd             S16cron
      
      rc3.d:
      K02gpm          K06smb        K09xinetd          K12nfsboot       K15informix  S01random     S08hpasm         S12autofs          S13splash     S16cron
      K04plweb        K06squid      K10autofs          K13cmanic        K15mms       S01stqdaemon  S08portmap       S12fbset           S13xinetd     S16dhcpd
      K05ivr          K07cups       K10fbset           K13hprsm         K15nmb       S05network    S08resmgr        S12named           S14hwscan     S16hpsmhd
      K05smbfs        K07postfix    K10named           K13hpvca         K15snmpd     S06syslog     S08splash_early  S12orbacus         S14nfsserver  S16smb
      K05splash_late  K07rsyncd     K10orbacus         K13nfslock       K15weblogic  S07fazzt      S09cmanic        S12raw             S14xntpd      S16squid
      K06atd          K08hwscan     K10raw             K14hpasm         K16syslog    S07informix   S09hprsm         S12rpmconfigcheck  S15cups       S17ivr
      K06autoyast     K08nfsserver  K10rpmconfigcheck  K14portmap       K17network   S07mms        S09hpvca         S12running-kernel  S15postfix    S17smbfs
      K06cron         K08xntpd      K10running-kernel  K14resmgr        K21coldplug  S07nmb        S09nfslock       S12sshd            S15rsyncd     S17splash_late
      K06dhcpd        K09ct_intel   K10sshd            K14splash_early  K21random    S07snmpd      S10nfs           S13ct_intel        S16atd        S18plweb
      K06hpsmhd       K09splash     K12nfs             K15fazzt         S01coldplug  S07weblogic   S10nfsboot       S13kbd             S16autoyast   S20gpm
      
      rc4.d:
      K06hpsmhd  K13cmanic  K13hprsm  K13hpvca  K14hpasm  S08hpasm  S09cmanic  S09hprsm  S09hpvca  S16hpsmhd
      
      rc5.d:
      K04plweb        K06squid      K09xinetd          K12nfsboot       K15informix  S01random     S08hpasm         S12autofs          S13splash     S16autoyast
      K05ivr          K07cups       K10autofs          K13cmanic        K15mms       S01stqdaemon  S08portmap       S12fbset           S13xinetd     S16cron
      K05smbfs        K07postfix    K10fbset           K13hprsm         K15nmb       S05network    S08resmgr        S12named           S14hwscan     S16dhcpd
      K05splash_late  K07rsyncd     K10named           K13hpvca         K15snmpd     S06syslog     S08splash_early  S12orbacus         S14nfsserver  S16hpsmhd
      K06atd          K07xdm        K10orbacus         K13nfslock       K15weblogic  S07fazzt      S09cmanic        S12raw             S14xntpd      S16smb
      K06autoyast     K08hwscan     K10raw             K14hpasm         K16syslog    S07informix   S09hprsm         S12rpmconfigcheck  S15cups       S16squid
      K06cron         K08nfsserver  K10rpmconfigcheck  K14portmap       K17network   S07mms        S09hpvca         S12running-kernel  S15postfix    S17ivr
      K06dhcpd        K08xntpd      K10running-kernel  K14resmgr        K21coldplug  S07nmb        S09nfslock       S12sshd            S15rsyncd     S17smbfs
      K06hpsmhd       K09ct_intel   K10sshd            K14splash_early  K21random    S07snmpd      S10nfs           S13ct_intel        S15xdm        S17splash_late
      K06smb          K09splash     K12nfs             K15fazzt         S01coldplug  S07weblogic   S10nfsboot       S13kbd             S16atd        S18plweb
      
      rc6.d:
      S20reboot
      
      rcS.d:
      S10boot.clock  S13kbd  S13splash  S20single
  • All files that start with the letter K are kill services (they call the service script with stop as an argument)
  • All files that start with the letter S are start services (they call the service script with start as an argument)
  • All Kill scripts are run first then all the Start scripts.
  • Both the Kill and Start scripts are run in numerical order (ie. S01… is run before S02…)
  • In the Runlevel 3 directory /etc/init.d/rc3.d you’ll notice that all the services listed are symbolic links to a script in the /etc/init.d dir:
    lrwxrwxrwx  1 root root 11 2006-11-09 10:48 S07weblogic -> ../weblogic
    lrwxrwxrwx  1 root root  8 2006-11-09 10:48 S07snmpd -> ../snmpd
    lrwxrwxrwx  1 root root  6 2006-11-09 10:48 S07nmb -> ../nmb
    lrwxrwxrwx  1 root root  6 2006-11-09 10:48 S07mms -> ../mms
    lrwxrwxrwx  1 root root 11 2006-11-09 10:48 S07informix -> ../informix
    lrwxrwxrwx  1 root root  8 2006-11-09 10:48 S07fazzt -> ../fazzt
  • Let’s take a closer look at one of these services scheduled to launch on startup S07weblogic -> ../weblogic
    • The chkconfig command allows you to manage services for startup.
    • To check the configuration of a service script found in /etc/init.d run the following command:
      chkconfig --list weblogic
      weblogic                  0:off  1:off  2:on   3:on   4:off  5:on   6:off
    • This means the weblogic service is enabled for Runlevel 2,3, and 5 (ie. found in rc2.d, rc3.d and rc5.d directories
    • The weblogic script starts weblogic up at boot time when the system starts up under the above runlevels
    • The script looks like the following:
      #!/bin/sh
      #
      # weblogic start and shutdown
      #
      # Copyright (c) Shoppers Drug Mart 2005
      #
      # Bootup and shutdown script
      #
      # /etc/init.d/weblogic
      #
      ### BEGIN INIT INFO
      # Provides:       weblogic
      # Required-Start: $network $nfs $informix
      # Required-Stop:
      # Default-Start:  2 3 5
      # Default-Stop:
      # Description:    Start weblogic server
      ### END INIT INFO
      
      trap "exit 255" 1 2 3           # ignore signals
      
      ADMIN_HOME=/apps/appserver/prod/asAdmin
      case $1 in
      'start')
              echo "Starting weblogic..."
              #
              # have the system run out of /appserver/prod/asAdmin/
              #
              # start weblogic as asuser
              #
              su asuser -c "cd ${ADMIN_HOME}/utils; ./startServer.ksh ALL >${ADMIN_HOME}/logs/boot.log 2>&1" &
          ;;
      'stop')
              echo "Stopping weblogic..."
              su asuser -c "cd ${ADMIN_HOME}/utils; ./stopServer.ksh ALL >${ADMIN_HOME}/logs/stop.log 2>&1"
          ;;
      *)
              echo "Usage: $0 {start|stop}"
          ;;
      esac

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply