unx40.htm

来自「Unix Unleashed, Third Edition is written」· HTM 代码 · 共 1,873 行 · 第 1/5 页

HTM
1,873
字号
<BR></P>

<H4 ALIGN="CENTER">

<CENTER><A ID="I14" NAME="I14">

<FONT SIZE=3><B>Port Monitor Administration and Management</B>

<BR></FONT></A></CENTER></H4>

<P>As explained earlier in this chapter, for an administrator to offer port services, be it across the network or local to the system, he or she must first create the port monitor supporting it. Only then can port services be created and released to the 
user community. There are also troubleshooting instances when the administrator may need to check on the status of suspect port monitors or even temporarily disable them. 

<BR></P>

<H5 ALIGN="CENTER">

<CENTER><A ID="I15" NAME="I15">

<FONT SIZE=3><B>Creating a Port Monitor</B>

<BR></FONT></A></CENTER></H5>

<P>Port monitors are administered and managed using the sacadm administrative command. In addition to sacadm, each port monitor type provides for an administrative command that is commonly used with sacadm in &quot;command substitution mode.&quot; ttyadm 
is ttymon's command, whereas nlsadmin is listen's. To create a port monitor, sacadm must be entered along with the following options:

<BR></P>

<PRE>#sacadm -a -p&lt;pmtag&gt; -t&lt;type&gt; -c&quot;&lt;pm_cmd&gt;&quot; -v ver [-fd|x] \

[-n &lt;count&gt;] [-y&quot;comment&quot;]</PRE>

<P>where:

<BR></P>

<PRE>

<BR>-a stands for add or create a port monitor.



<BR>-p &lt;<I>pmtag</I>&gt; assigns the port monitor being created a name, which can be conveniently used to distinguish it from other port monitors. Although the name can be anything you choose, it should be descriptive of the type of service with which 
it is associated.



<BR>-t &lt;<I>type</I>&gt; specifies the type of monitor to create (that is, ttymon versus listen).



<BR>-c &quot;<I>&lt;pm_cmd&gt;</I>&quot; specifies the command to invoke when the port monitor is later spawned by sac: /usr/lib/saf/ttymon to invoke a ttymon port monitor, or /usr/lib/saf/listen to invoke a listen port monitor.



<BR>-v<I> ver</I> specifies the version of the port monitor. The version may more conveniently be provided by invoking the port monitor's specific administrative command (ttyadm or nlsadmin) with the -V option in command substitution form (that is, as an 
argument to -v). In this case, the -V option would be typed as follows:



<BR># sacadm -a ... -v'ttyadm -V' ...



<BR>-f [d|x] specifies the status of the port monitor upon invocation, with d meaning to start the port monitor in disabled state and x meaning not to start it. If flagged x, the port monitor can only be started by the system administrator. There onward, 
sac takes over in controlling the port monitor.



<BR>-n&lt;count&gt; specifies the retry count used by the port monitor in restarting a failing port monitor. If not included, the default that applies is zero.



<BR>-y &quot;<I>comment</I>&quot; can be any comment that you may want to include in the /etc/saf/_sactab file. For your convenience, you may want to include a comment describing what this port monitor is for.</PRE>

<P>When a port monitor is created, the following happens: 1) An entry in sac's administrative file /etc/saf/_sactab is added pertaining to the port monitor, including all of the arguments provided on the command line. 2) The port monitor's supporting 
directory /etc/saf/&lt;<I>pmtag</I>&gt; is also created. As a matter of fact, another directory, /var/saf/&lt;<I>pmtag</I>&gt;, will also be created where a port monitor log file is maintained. The filename is /var/saf/&lt;<I>pmtag</I>/log. It is used by 
sac to log all messages pertaining to the port monitor.

<BR></P>

<P>For a better feel for what has been said so far, take a look at an example of creating a port monitor. This example will be carried over to upcoming sections to demonstrate aspects of managing the port monitor. In this example it is assumed that the 
system administrator wants to allow users local logins to the system, using serial communications. Hence, the first task is to create the port monitor in preparation for creating the necessary associated port services.

<BR></P>

<P>Due to the nature of the service (that is, serial communication), the port monitor has to be of a ttymon type. The system administrator has chosen to assign the port monitor the tag ttyserv, start it in the disabled state, and include a comment saying 
&quot;only two logins.&quot; Upon failure, sac should attempt restarting the monitor twice. The sacadm command should therefore look like this:

<BR></P>

<PRE>#sacadm -a -p serial -t ttymon -v 'ttyadm -V' \

 -c&quot;/usr/lib/saf/ttymon&quot; -fd -n 2 -y &quot;only two logins&quot;</PRE>

<P>Next, you'll be learning how to check on the status of the port monitor. For the time being, however, we can carry a check using cat to look up the contents of sac's /etc/saf/_sactab file. cat /etc/saf/_sactab should reveal the following entry:

<BR></P>

<PRE>ttyserv:ttymon:d:2:/usr/lib/saf/ttymon          #only two logins</PRE>

<P>and if you enter ls -l /etc/saf, you will be able to verify that the subdirectory is ttyserv. ttyserv (the subdirectory) is created among others existing at /etc/saf level. Reflecting back on the _sactab entry shown previously, you should have guessed 
how each field in /etc/saf/_sactab file maps to arguments you enter on the command line. The first field refers to the pmtag, the second to the port monitor type, the third to the state in which the port monitor is started (disable state, in this example). 

The fourth mandates that two restarts be attempted should the port monitor fail, and the fifth specifies the complete path- name of the command to invoke. Note also that the comment is included as well.

<BR></P>

<H5 ALIGN="CENTER">

<CENTER><A ID="I16" NAME="I16">

<FONT SIZE=3><B>Checking the Status of the Port Monitor</B>

<BR></FONT></A></CENTER></H5>

<P>To check on the status of the port monitor, use the sacadm command with -l option among the others as follows:

<BR></P>

<OL>

<LI># sacadm -t&lt;<I>type</I>&gt; -l to obtain a listing of all port monitors of same type, or

<BR>

<BR></LI>

<LI># sacadm -p&lt;<I>pmtag</I>&gt; -l to obtain information about a specific port monitor.

<BR>

<BR></LI></OL>

<P>If you enter sacadm -pttyserv -l to check on the port monitor just created in the preceding example, you get the following output:

<BR></P>

<PRE>PMTAG     PMTYPE    FLGS RCNT STATUS    COMMAND

ttyserv   ttymon    d    2    DISABLED  /usr/lib/saf/ttymon #only two logins</PRE>

<P>Note that the status field indicates that the port monitor is in a disabled state. If you check the status immediately after the port monitor is created, the status field may indicate that it is STARTING.

<BR></P>

<P>The port monitor can be in one of the following states:

<BR></P>

<TABLE BORDER>

<TR>

<TD>

<P>STARTING:</P>

<TD>

<P>sac is in the process of starting it. This is a transitional state between NOTRUNNING and ENABLED or DISABLED.</P>

<TR>

<TD>

<P>ENABLED:</P>

<TD>

<P>The port monitor is running and is accepting connection requests.</P>

<TR>

<TD>

<P>DISABLED:</P>

<TD>

<P>The port monitor is running but refusing connection service requests.</P>

<TR>

<TD>

<P>STOPPED:</P>

<TD>

<P>The port monitor is undergoing the shutdown process. This state is transitional from ENABLED or DISABLED and NOTRUNNING.</P>

<TR>

<TD>

<P>NOTRUNNING:</P>

<TD>

<P>The port monitor is not running. None of the port services associated with it is currently accessible.</P></TABLE>

<H5 ALIGN="CENTER">

<CENTER><A ID="I17" NAME="I17">

<FONT SIZE=3><B>Enabling, Disabling, and Removing a Port Monitor</B>

<BR></FONT></A></CENTER></H5>

<P>To enable, disable, or remove a port monitor, use sacadm -e, sacadm -d, or sacadm -r, respectively. To enable the ttyserv port monitor, enter

<BR></P>

<PRE># sacadm -pttyserv -e</PRE>

<P>whereas to disable it, enter

<BR></P>

<PRE># sacadm -pttyserv -d</PRE>

<P>and to remove it, enter

<BR></P>

<PRE># sacadm -pttyserv -r</PRE>

<HR ALIGN=CENTER>

<NOTE>

<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> When a port monitor is removed, its associated directories are not cleaned up and deleted. To avoid confusion in the future, you may have to take care of that yourself.

<BR></NOTE>

<HR ALIGN=CENTER>

<H4 ALIGN="CENTER">

<CENTER><A ID="I18" NAME="I18">

<FONT SIZE=3><B>Port Service Administration and Management</B>

<BR></FONT></A></CENTER></H4>

<P>Only after the port monitor is created is the system administrator in a position to create and manage the associated port services. Port creation and administration is achievable via the pmadm command. 

<BR></P>

<H5 ALIGN="CENTER">

<CENTER><A ID="I19" NAME="I19">

<FONT SIZE=3><B>Creating a Port Service</B>

<BR></FONT></A></CENTER></H5>

<P>To create a port service, pmadm should be used with the -a option, among the others as follows: 

<BR></P>

<PRE># pmadm -a -p&lt;pmtag&gt; -s&lt;svctag&gt; -m&quot;pmspecific&quot; \

-v ver [-fx|u] -y&quot;comment&quot;</PRE>

<P>in which

<BR></P>

<PRE>

<BR>-a stands for create a port service.



<BR>-p&lt;pmtag&gt; specifies the tag of the port monitor to which the port service belongs.



<BR>-s&lt;svctag&gt; specifies the service tag assigned to the port service.



<BR>-m&quot;&lt;<I>pmspecific</I>&gt;&quot; specifies port-specific information to be passed as an argument to the pmadm command. Normally, this information is generated by employing either ttyadm or nlsadmin in command substitution mode, depending on the 

type of the port monitor specified with the -p option.



<BR>-v &lt;<I>ver</I>&gt; passes the version of the port monitor. Depending on the type of the port monitor, either ttymon -V or nlsadmin -V can be used in command substitution mode.



<BR>-f specifies the state with which the port service should be started, and whether a utmp entry is to be created. Both or any of the flags can be specified, where d specifies that the port should be started in disabled state, and u specifies that a utmp 

entry be created for the service.</PRE>

<P>The following example adds a ttymon port service to the ttyserv port monitor created earlier in this section:

<BR></P>

<PRE>#pmadm -a -pttyserv -s s01 -v 'ttyadm -C' -fd \

-m &quot;`ttyadm -d /dev/term/01 -l 9600 -s/usr/bin/login \

-p&quot;Welcome To UNIX, Please Login:&quot;'&quot;</PRE>

<P>The port service thus created is assigned service tag s01 and added to a port monitor called ttyserv (the one created in the earlier section). s01 port is associated with /dev/term/01 device file (that is, COM2 on an Intel 386/486 machine. -l 9600 
refers to a record in a terminal line setting database file (/etc/ttydefs), which, when used by the port, sets the line speed. The other settings are described in a subsequent section. When s01 port is invoked by the ttyserv port monitor, it is going to 
write a prompt (&quot;Welcome to UNIX, Please Login:&quot; according to the preceding example) to the terminal connected to the COM2 port. It starts monitoring the port until it receives a request to connect. Upon receiving the prompt, it invokes 
/usr/bin/login to take care of the request.

<BR></P>

<P>When a port service is created, the /etc/saf/&lt;<I>pmtag</I>&gt;/_pmtab is modified to include an entry pertaining to the service. Hence, in the preceding example, an entry pertaining to s01 must be present in the /etc/saf/ttyserv/_pmtab. You can 
display it either by using cat or the pmadm command as described in the next section.

<BR></P>

<H5 ALIGN="CENTER">

<CENTER><A ID="I20" NAME="I20">

<FONT SIZE=3><B>Listing and Checking the Status of a Port Service</B>

<BR></FONT></A></CENTER></H5>

<P>To list and check on the status of a port monitor, enter

<BR></P>

<PRE>#pmadm -l -p&lt;pmtag&gt; -s&lt;svctag&gt;</PRE>

<P>To list or check on the status of all port services associated with a specific port monitor, enter

<BR></P>

<PRE>#pmadm -l -p&lt;pmtag&gt;</PRE>

<P>whereas to list, or check, the status of all port monitor services, enter

<BR></P>

<PRE>PMTAG          PMTYPE         SVCTAG         FLGS ID       &lt;PMSPECIFIC&gt;

ttymon3        ttymon         00s            u    root      /dev/term/00s - - /usr/bin/

<BR>                                                           _login - 2400 - login:  -  #

ttymon3        ttymon         01s            u    uucp     /dev/term/01s b - /usr/bin/

<BR>                                                           _login - 2400 - login:  -  #

ttymon3        ttymon         00h            u    root      /dev/term/00h - - /usr/bin/

<BR>                                                           _login - 9600 - login:  -  #

tcp            listen         0              x    root     \x02000ACE64000001 - c - /

<BR>                                                           _usr/lib/saf/nlps_server

<BR>                                                           _#NLPS SERVER

tcp            listen         lp             -    root     - - - - /var/spool/lp/fifos/

<BR>                                                           _listenS5 #NLPS SERVER

tcp            listen         105            -    root     - - c - /usr/net/servers/rfs/

<BR>                                                           _rfsetup #RFS server</PRE>

<P>The following two examples demonstrate the first two commands.

<BR></P>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?