📄 unx34.htm
字号:
<LI>/etc/rc3.d—Contains startup scripts related to the file-sharing (3) run state.
<BR>
<BR></LI>
<LI>/etc/shutdown—Included for backward compatibility for preSystem V, Release 3 systems to include scripts that are run when the system is shut down. This directory is empty unless an application adds a script there.
<BR>
<BR></LI>
<LI>/etc/rc.d—Included for backward compatibility for preSystem V, Release 3 systems to include scripts that are run when the system is started. This directory is empty unless an application adds a script there.
<BR>
<BR></LI>
<LI>/etc/init.d—Acts as a holding place for all startup scripts. Scripts are not actually run from this directory, but are linked to their appropriate rc<I>?</I>.d directories. This concept is a bit strange. Read the section "Understanding
Startup Scripts" for information on how startup scripts are set up and run.
<BR>
<BR></LI></UL>
<H3 ALIGN="CENTER">
<CENTER><A ID="I10" NAME="I10">
<FONT SIZE=4><B>Understanding Startup Scripts</B>
<BR></FONT></A></CENTER></H3>
<P>A startup script is a command that is run when you start the system, shut down the system, or change to a different run state. If you list a startup script, using cat or pg, you will see that it is a series of shell commands that are run when the script
is executed with either a start or stop option.
<BR></P>
<P>When an application adds a startup script to UNIX, it adds that script to the /etc/init.d directory. It then links that script to one or more directories to filenames that begin with either the letter S (for start) or the letter K (for kill).
<BR></P>
<P>Startup scripts are run when you go into a new run state. When you enter a run state relating to one of the directories described in the section "Run State Directories," the rc<I>?</I> command runs all startup scripts in that directory that
begin with the letters S and K. It runs the S scripts with the start option and K scripts with the stop option, in the ASCII order.
<BR></P>
<P>Now that you are completely confused, look at the example in the next section. It steps you through how a particular startup script, for the mouse manager, is installed, started, and stopped.
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I11" NAME="I11">
<FONT SIZE=4><B>Example The Mouse Startup Script</B>
<BR></FONT></A></CENTER></H3>
<P>When you install the UnixWare version of UNIX, a shell script for starting and stopping the process that manages your mouse on the graphical user interface is installed as the /etc/init.d/mse file. Also, this file is linked to two other files:
/etc/rc2.d/S02mse and /etc/rc0.d/K02mse.
<BR></P>
<P>That script contains the following:
<BR></P>
<PRE>case "$1" in
'start')
/usr/lib/mousemgr &
;;
'stop')
pid='/usr/bin/ps e | /usr/bin/grep mousemgr |\
[cc]/usr/bin/sed e 's/^ *//' e 's/ .*//''
if [ "${pid}" != "" ]
then
/usr/bin/kill ${pid}
fi
;;
*)
echo "Usage: /etc/init.d/mse { start | stop }"
;;
esac</PRE>
<P>When you boot your system, the init process checks the /etc/inittab file for entries that match the default run state (initdefault), which is usually run state 3. It finds the r2 entry, among others, which runs the /sbin/rc2 command and which checks all
scripts in the /etc/rc2.d directory. Next, it runs all files that begin with K with the stop option and all that begin with S with the start option. So, for example, the S02mse script is run as this:
<BR></P>
<PRE>S02mse start</PRE>
<P>Notice from the listing of the script that the start option causes the /usr/lib/mousemgr command to be run. From this point on, the mousemgr runs continuously until you change system states again.
<BR></P>
<P>When you shut down the system (that is, change to a shutdown state), init goes through the same process for state 0 as it did for state 3. This time it runs the r0 entry, which runs the /etc/rc0 command, which check scripts in the /etc/rc0.d directory.
All the scripts in this directory begin with K, to kill processes that were started in other states. The mouse script, K02mse, is run, but this time with the stop option, as follows:
<BR></P>
<PRE>K02mse stop</PRE>
<P>As you can see from the script shown above, the stop option finds the running mouse process, determines its process ID, and kills it. After all other startup processes are stopped, the system can shut down.
<BR></P>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> The convention for naming these startup scripts is a letter (K or S), followed by a number (00 through 99), followed by the name of the script as it exists in the /etc/init.d directory. The number
determines the order in which the script is run.
<BR></NOTE>
<HR ALIGN=CENTER>
<H3 ALIGN="CENTER">
<CENTER><A ID="I12" NAME="I12">
<FONT SIZE=4><B>Changing States with </B><B><I>init</I></B><B> or </B><B><I>telinit</I></B>
<BR></FONT></A></CENTER></H3>
<P>While your UNIX system is running, you can change the system state or the level of activity using the init or the telinit commands. If you are shutting down the system or moving to a lower state (especially one that will kick users off your system) you
can use the shutdown command.
<BR></P>
<P>The init command is the easiest way of changing system states. To use init, you simply type init followed by a system state letter or number (from a shell in which you have root permission). For example, the command
<BR></P>
<PRE>init 2</PRE>
<P>could be used to change your system from state 3 to state 2, effectively turning off file-sharing features. You could also change to user configurable states, such as state 4, a, b, or c. Or you can change to q or Q to simply reread the /etc/inittab
file.
<BR></P>
<P>The telinit command is simply a link to the init command. The telinit command was created for users who might be afraid to use a command as potentially drastic as the init command to simply reread the /etc/inittab file. So telinit was recommended for
rechecking the /etc/inittab file and running any new commands (telinit Q). In reality, however, you can use init and telinit interchangeably.
<BR></P>
<P>Instead of using the init or telinit commands, UnixWare offers more friendly ways to shut down your system.
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I13" NAME="I13">
<FONT SIZE=4><B>Shutting Down the System</B>
<BR></FONT></A></CENTER></H3>
<P>There are several ways to shut down your UnixWare system: double-clicking the Shutdown icon from the graphical user interface, using shutdown from the command line, or by simply turning off your computer. The merits of each are discussed in the
following sections.
<BR></P>
<H4 ALIGN="CENTER">
<CENTER><A ID="I14" NAME="I14">
<FONT SIZE=3><B>Using the Shutdown Icon</B>
<BR></FONT></A></CENTER></H4>
<P>If you are using the GUI and you have ownership permissions to do system shutdown, you can stop your system using the Shutdown icon. To use the Shutdown icon, simply doubleclick on the Shutdown icon in the UnixWare Desktop window. When you see a
Shutdown confirmation window, click on Shutdown. The graphical interface closes and the system shuts down.
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I15" NAME="I15">
<FONT SIZE=4><B>Using the </B><B><I>shutdown</I></B><B> Command</B>
<BR></FONT></A></CENTER></H3>
<P>The shutdown command can be used instead of the init command to move to lower system states, in particular shutdown (0) and reboot (6) states. The init command can be a bit abrupt if you are working with a multiuser system. When you enter init 0, the
system simply goes down. The shutdown command lets you warn users and give them a grace period to log off.
<BR></P>
<P>The following is an example of the shutdown command (used as the root user from a shell):
<BR></P>
<PRE># cd /
# shutdown y g60 i0</PRE>
<P>The y option lets you skip the shutdown confirmation question. The g60 assigns a 60 second grace period to users in which they can log off before the system comes down. The i0 assigns the init state to state 0 (shutdown state).
<BR></P>
<P>Once you run the command, all users logged in to the system are warned about the impending system shutdown. They have the length of the grace period to close whatever work they are doing before the system comes down.
<BR></P>
<H4 ALIGN="CENTER">
<CENTER><A ID="I16" NAME="I16">
<FONT SIZE=3><B>Turning Off the Computer</B>
<BR></FONT></A></CENTER></H4>
<P>Because UnixWare uses a hardened file system, vfxs from Veritas, you can turn off your computer without losing data. As a rule, however, it is safer to do an orderly shutdown with either the shutdown command or the Shutdown icon.
<BR></P>
<P>Those who have used UNIX systems for years often feel uncomfortable simply turning off their computers with UNIX running. In the old days, the next time you booted your UNIX system after turning it off you would have to wait for a massive file system
check to take place. This would often take a half hour or more, occasionally resulting in some data loss.
<BR></P>
<P>Even though this author has never lost any data when turning off UnixWare, it does take a little longer the next time the system is booted. On the whole, it is best to close your applications and do an orderly shutdown.
<BR></P>
<H4 ALIGN="CENTER">
<CENTER><A ID="I17" NAME="I17">
<FONT SIZE=3><B>Miscellaneous Start</B><B>up and Shutdown Notes</B>
<BR></FONT></A></CENTER></H4>
<P>Here are a few tips relating to starting and shutting down your system:
<BR></P>
<UL>
<LI>When you start your Intel-based computer, the computer checks your floppy disk drive before it checks your hard disk to find the operating system. If you have mistakenly left in a floppy disk that is not a bootable floppy, your computer won't boot. If
your hard disk is corrupted or damaged, booting from a bootable floppy disk is one way you might be able to salvage your system. Call your UNIX support representative for help.
<BR>
<BR></LI>
<LI>Some administrators like to run the sync command before running the init command to shut down their computers. This takes information that is stored in memory waiting to be written to hard disk and writes it to hard disk.
<BR>
<BR></LI>
<LI>If you are ever curious about what your current system state is, run the who r command. This tells you the current and previous run levels.
<BR>
<BR></LI>
<LI>You can modify startup scripts to change their behavior. The most common thing you might do is add a debugging option to a networking startup script to try to find more information about why a particular feature isn't starting. Be sure, however, that
you make a copy of the script before changing it. If you make an error, you could break an entire system feature.
<BR>
<BR></LI></UL>
<H3 ALIGN="CENTER">
<CENTER><A ID="I18" NAME="I18">
<FONT SIZE=4><B>Summary</B>
<BR></FONT></A></CENTER></H3>
<P>When you start up UNIX, a complex set of processes is run. These processes initialize the system, connect system resources, and allow access by multiple users and networks.
<BR></P>
<P>As a UNIX system administrator, you can change the state of your system to do administrative tasks or to limit access to the system. You can also modify the processes that are run when you change system states.
<BR></P>
<P>When you are done using your UNIX system for the moment, UNIX can be shut down in several ways. With the latest releases of UNIX, an orderly shutdown (with the shutdown or init commands) is no longer necessary. Hardened file systems let you just turn
off your computer with little risk of losing data.
<BR></P>
<P><A HREF="unx33.htm"><IMG SRC="bluprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>
<A HREF="index.htm"><IMG SRC="blutoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>
<A HREF="unx35.htm"><IMG SRC="blunext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>
<A HREF="index.htm"><IMG SRC="bluprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Home"></A>
</P></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -