Linux System Startup and Shutdown Scripts

 < Day Day Up > 

Startup and shutdown scripts for Linux are organized in three parts: sequencer script; execution scripts; and subdirectories and link files. These scripts work together to facilitate startup execution and are described shortly.

Startup and shutdown are going to become increasingly more important to you as your system administration work to become more sophisticated. As you load and customize more applications, you will need to know more about startup and shutdown. In this section, you get an overview of startup and shutdown and the commands that you can use to control your system.

The following descriptions are for the three components that are in the startup and shutdown model of Linux that is based on the UNIX System V model:

Execution Scripts

 

Read variables from configuration variable files and run through the startup or shutdown sequence. These scripts are located in /etc/rc.d/init.d, such as /etc/rc.d/init.d/smb to start and stop Samba.

Sequencer Script

 

Calls all other scripts is /etc/rc.d/rc. This script calls all of the other scripts in the correct order for each run level. The scripts it calls are in a run level subdirectory.

Subdirectories and Link Files

 

There is subdirectory for each run level in /etc/rc.d such as /etc/rc.d/rc2.d for run level two, /etc/rc.d/rc3.d for run level three, and so on. These subdirectories contain symbolic links to the execution scripts in /etc/rc.d/init.d. The links start with either an S for start or a K for kill. An S script would start a service and a K script would kill, or stop, a service. Lower number scripts are executed before higher number scripts.


Figure 6-1 shows the directory structure for startup and shutdown scripts.

Figure 6-1. Organization of Linux Startup and Shutdown Files


Execution scripts perform startup and shutdown tasks. /sbin/rc invokes the execution script with the appropriate start or stop arguments, and you can view the appropriate start or stop messages on the console. You'll see an [ OK ] that indicates that the execution script started successfully.

Let's take a look at an example startup and shutdown file for Samba. This will help us later when we perform extensive Samba-related work in another chapter.

As mentioned earlier, the script used as part of the startup and shutdown process is in /etc/init.d. The following example is from the IA-32 system used in the Samba chapter, but is the same for Integrity servers. For the Samba example, the name of the program is /etc/init.d/smb. Take a minute and use your favorite editor to open and view the script. If you're logged on as root, remember not to make any changes to the script without backing up the original.

The startup and shutdown scripts in /etc/init.d generally perform both startup and shutdown functions. These startup and shutdown scripts recognize many arguments, including the following:

  • start

  • stop

  • restart

  • status

  • condrestart

See if you can find these in /etc/init.d/smb. If you do, see if you can understand what they do. Now, test some of these arguments. We'll start smb, obtain its status, stop smb, and re-obtain its status. Remember, to do these things, you must be logged on as root:

 # ./smb start Starting SMB services: [ OK ] Starting NMB services: [ OK ] # ./smb status smbd (pid 11165) is running... nmbd (pid 11170) is running... # ./smb stop Shutting down SMB services: [ OK ] Shutting down NMB services: [ OK ] # ./smb status smbd is stopped nmbd is stopped # 

As you can see, the script obviously works great, but does not start automatically at system boot. Make sure that you're in /etc/rc.d, then search for all files in /etc/rc.d that contain smb. If you do, you get the following:

 # pwd /etc/rc.d # find . -name *smb* -print ./init.d/smb ./rc0.d/K35smb ./rc1.d/K35smb ./rc2.d/K35smb ./rc3.d/K35smb ./rc4.d/K35smb ./rc5.d/K35smb ./rc6.d/K35smb # 

All the files found begin with K, which indicates that these are kill files, and no start files beginning with S were found. We can start smb a variety of ways, including the following:

  • Manually change a K file to an S file at the appropriate run level so that when we pass through the run level smb will start.

  • Edit /etc/rc.d/rc.local to include the following line:/etc/init.d/smb start

  • Run ksysv to display and edit System V startup information although at the time of this writing, it doesn't appear that this will be supported in RHEL 3.

We'll use the third technique because the ksysv interface is easy to use and informative. Although this chapter discusses /etc/inittab soon, you need to know our default run level. You can obtain the current run level and the default run level because you haven't changed it in this case, by issuing the runlevel command:

 # runlevel N 5 # 

You now know that you're at run level 5. Figure 6-2 shows the top level ksysv interface.

Figure 6-2. ksysv Interface


smb appears at run level 5 under Stop but not under Start. All that we have to do to place it under Start is to select it in the Available Services window on the left and Copy and Paste it into Runlevel 5 to have it start when the system reaches run level 5. Figure 6-3 shows smb under Runlevel 5.

Figure 6-3. ksysv with smb Under Runlevel 5


After the system is rebooted, smb did come up as a running service as verified with the command in the following output:

 # /sbin/service smb status smbd (pid 933) is running... nmbd (pid 938) is running... # 

The /sbin/service command starts services. It calls the startup script, such as smb in this case, and performs the desired function, such as producing status in this case. There is no manual page for service, but you will see it issued in examples often.

Now re-issue the search command and see if there is indeed an S file for smb to start it automatically:

 # pwd /etc/rc.d # find . -name *smb* -print ./init.d/smb ./rc0.d/K35smb ./rc1.d/K35smb ./rc2.d/K35smb ./rc3.d/K35smb ./rc4.d/K35smb ./rc5.d/S90smb ./rc5.d/K35smb ./rc6.d/K35smb # 

The startup script for out default run level 5 is /etc/rc.d/rc5.d/S90smb. This was added for us automatically by ksysv with our copy and paste operation. The following shows the anatomy of the file:

 /etc/rc.d/rc5.d/S90smb             |   | | |             |   | | v             |   | | script name - smb in example             |   | v             |   | sequence number - 90 in example             |   v             |  "S" for startup, "K" for kill or shutdown             v             run level number - 5 in example 

Now that you know the way in which startup and shutdown scripts work, it's time to investigate /etc/inittab.

     < Day Day Up > 


    Linux on HP Integrity Servers. A System Administrator's Guide
    Linux on HP Integrity Servers: A System Administrators Guide
    ISBN: 0131400002
    EAN: 2147483647
    Year: 2004
    Pages: 100

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net