Chapter 11: Working from the Command-Line

Significantly enhanced in IIS 6 specifically (and Windows Server 2003 in general) is the ability to manage a server from the command line. By including many new Windows commands and administration scripts, Microsoft has made it easier for administrators to remotely manage their servers, perform batch operations, and schedule tasks to occur during off-peak hours.

This chapter focuses on the tools and methods for administering IIS 6 machines from the command line. No background in programming or scripting is assumed because as you’ll see, Microsoft has included a number of useful scripts with IIS 6that can be used to perform common administrative tasks.

Methods for Command-line Administration

There are four types of commands that can be used to administer IIS from the command line:

  • IISReset A command-line utility for starting and stopping IIS.

  • Windows Management Instrumentation (WMI) A scripting interface for managing virtually any aspect of Windows Server 2003.

  • Active Directory Services Interface (ADSI) An API for scripted management of Active Directory that can be used to manage certain aspects of IIS.

  • Miscellaneous commands These include standard Windows commands and Support Tools utilities, some of which are applicable to administering IIS.

Let’s look at each of these in a bit more detail.

IISReset

Near the top of an administrator’s list of useful IIS command-line utilities is IISReset, a tool that has been around since IIS 5 and can be used to stop and restart IIS or reboot the server from the command line. Alternatively, you can restart IIS using IIS Manager, as discussed earlier in Chapter 5, “Administering Standard/Enterprise Edition,” or using the Web Interface for Server Administration (WISA) tool, as discussed in Chapter 6, “Administering Web Server Edition.” In fact, both these GUI methods actually use the IISReset.exe command-line utility for stopping and starting IIS, so if this utility is missing or permissions prevent it from being used, the GUI methods of restarting IIS won’t work either!

A typical reason for restarting IIS is dealing with application instability in ASP or ASP.NET applications running on your IIS machines. Particularly during the development stage, such applications often have bugs that generate resource leaks or other nasty conditions, and restarting IIS periodically is an easy way of ensuring these leaks don’t get out of hand or of recovering IIS when an application suddenly fails. Another name for this kind of condition is “accumulated instability,” that is, when the application runs long enough it becomes sufficiently stable to start affecting the overall stability of the underlying operating system, eventually causing the system to become unresponsive (hang) or even crash (blue screen of death). In such an environment, IISReset can be a lifesaver and can be used to nightly stop and start IIS or even reboot the server.

Of course, with IIS 6 part of this instability issue for buggy ASP applications is solved by using application pool recycling, which is enabled by default. But this doesn’t always solve all such instability problems, and restarting IIS or rebooting the server is sometimes the only way to ensure a buggy application will keep working or to quickly recover when it fails. And with the rapid pace of development these days, when applications are developed, tested, and released in weeks instead of months or years, the occurrence of bugs causing instabilities is much more prevalent than in the good old mainframe days. As you’ll see in the later section “Using IISReset,” in which we discuss the syntax of this command, you can even use the Windows Task Scheduler to run IISReset periodically; for example, each night at midnight, when terminating user connections is likely to have the least impact.

Note 

It would be nice if Microsoft had included a separate command-line tool that could be used to manually recycle a specific application pool on IIS, but unfortunately this is not the case. If enough admins ask for it however, you can probably expect such a utility to be included with IIS 7!

Another reason for restarting IIS is that certain configuration changes you make on IIS don’t take effect until you restart IIS. Examples of such configuration changes include:

  • Changing the IIS isolation mode (IIS restarts automatically).

  • Modifying a Registry entry relating to global IIS configuration (these are found under HKLM\Software\Microsoft\InetMgr\Parameters).

  • Manually restoring the metabase from a metabase history file. This may be necessary if the metabase is corrupt and cannot be enumerated by IIS Manager and as a result you can’t use IIS Manager to restore the metabase directly.

  • Manually enabling metabase edit-while-running from the command line by modifying the EnableEditWhileRunning property in the metabase instead of using the properties sheet for the server node in IIS Manager. Enabling edit-while-running (also called direct metabase edit) allows you to make changes later to the metabase without having to stop IIS first.

An important thing to consider here regarding restarting IIS is that when changes are made to the metabase they occur in memory and are not immediately written to disk. Instead, the in-memory metabase is copied to disk every five minutes, or once 50 metabase edits have accumulated. So if you restart IIS while metabase edits are pending in memory, these edits will be lost. The same problem can also occur when you modify the metabase indirectly using the IIS Manager, that is, changes are written to memory first and later written to disk, and if you restart IIS before the changes have been written to disk, they may be lost. Because of this, it’s a good idea to flush the IIS memory cache (which contains the in-memory metabase) to disk before stopping or restarting IIS. This can be done either from the command line using the iiscnfg.vbs /save command, as described in Chapter 13, “Maintenance and Troubleshooting,” or by right-clicking the server node in IIS Manager and selecting All Tasks | Backup/Restore Configuration, as described earlier in Chapter 5. An alternative approach after making configuration changes to IIS is to simply wait at least five minutes before restarting IIS to ensure that all in-memory metabase changes have been written to disk first.

WMI

Windows Management Instrumentation (WMI) is Microsoft’s implementation of Web- Based Enterprise Management (WBEM), an industry initiative to establish standard methods for accessing and manipulating management information for systems and network devices. WBEM (and hence WMI) is based on the Common Information Model (CIM), a set of schema for describing management information for systems and network devices that was developed by the Distributed Management Task Force (DMTF), the same group that developed WBEM.

The implementation of WMI on Windows Server 2003 includes a new IIS WMI Provider. Using VBScript or JScript, you can use this provider to write WMI scripts to perform common IIS administration tasks such as creating websites and virtual directories, enabling and disabling web service extensions, exporting and importing portions of the metabase, or just about anything else you want to do—WMI goes way beyond just IIS and allows you to manage virtually any aspect of Windows computers.

To make life easy for the busy IIS admin, Microsoft has included a number of sample admin scripts for you that use WMI right out of the box. These are found in the \Windows\System32 directory and include:

  • iisapp.vbs Lists web applications running on an IIS machine

  • iisback.vbs Backs up, restores, lists, and deletes IIS configurations

  • iisCnfg.vbs Exports and imports IIS configurations as XML files, copies configurations, and saves configurations to disk

  • iisext.vbs Enables and lists applications; adds and removes application dependencies; enables, disables, and lists web service extensions; and adds, removes, enables, disables, and lists web service extension files

  • iisFtp.vbs Creates, deletes, starts, stops, and lists FTP sites and configures Active Directory user isolation for FTP sites

  • iisFtpdr.vbs Creates and deletes virtual directories within FTP sites and displays the virtual directories within a given root

  • iisvdir.vbs Creates and deletes virtual directories within websites and displays the virtual directories within a given root

  • iisweb.vbs Creates, deletes, starts, stops, and lists websites

We’ll look at many of these scripts in more detail later in this chapter, starting with the section “Managing Websites.” However, I’ll defer coverage of two of them (iisback.vbs and iiscnfg.vbs) until Chapter 13 where discussion of them is more appropriate.

Note 

Anything you can do using these WMI admin scripts included with IIS 6 can of course also be done using IIS Manager. The advantage of the scripted approach is that you can schedule administrative tasks and perform bulk operations such as deleting multiple websites simultaneously, which can speed common administrative tasks on IIS machines that host large numbers of sites.

ADSI

Active Directory Services Interface (ADSI) is Microsoft’s directory service model for Windows Server 2003. ADSI is implemented as a set of COM interfaces that can be scripted to access and manipulate Active Directory objects for management purposes. Windows Server 2003 includes an IIS ADSI Provider that allows programmatic or scripted administration of IIS properties, allowing you to display and configure settings for websites, virtual directories, applications, and more.

Microsoft touted ADSI as the way to go for command-line administration in IIS 5, but with the IIS WMI Provider included in IIS 6 they are now de-emphasizing ADSI and instead recommending WMI as the preferred method due to its richer query support and standards-based implementation.

Caution 

Custom ADSI scripts designed for managing IIS 5 may not work with IIS 6 due to ADSI 2 methods included with Windows Server 2003. Be sure to test your old admin scripts carefully before using them in an IIS 6 production environment. Also, if your existing ADSI scripts have functionality relating to applications, you will need to modify them to enable them to work with application pools.

Other Commands

A number of Windows commands such as net start and net stop can be used to manage certain aspects of IIS, and there are additional commands in the Support Tools folder on the Windows Server 2003 CD-ROM that are also applicable to IIS. I’ll cover some of these later in the section “Windows Commands and Support Tools.”




IIS 6 Administration
IIS 6 Administration
ISBN: 0072194855
EAN: 2147483647
Year: 2003
Pages: 131
Authors: Mitch Tulloch

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