BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Operations-Friendly Windows Services

Operations-Friendly Windows Services

This item in japanese

Bookmarks

DevOps on Windows has for the last few months been running a series on how a developer can create an operations-friendly Windows Service. The series explains how to overcome the most important hurdles from an operations viewpoint: installation of the Windows Service and its start-up phase.

Some of the hurdles are due to common usage of InstallUtil, a non-native Windows tool, to install .Net based Windows Services. The start-up phase requires some care in order to provide clear error messages on the event of a failure and to support long running operations, like loading and caching data from a database.

DevOps on Windows proposes to solve those challenges with a very simple framework on which Windows Services can be built. The framework’s fundamental premise is self-containment: a Windows Service application should know how to install itself, as well as gracefully handle start-up failures. The framework revolves around three classes: BasicServiceInstaller; BasicService; and BasicServiceStarter.

BasicServiceInstaller provides the self-install and self-uninstall functionality, foregoing the application’s need to have its own Installer, a .Net class that provides a foundation to build custom installations. This self-install capability means that the operations team does not need to use any external tools, such as sc or InstallUtil.

BasicService ensures that the start-up phase follows some best practices regarding the interaction with the Service Control Manager. This Windows process manages all the registered Windows Services, including their lifecycle, where it dictates rules that all Windows Services have to follow. BasicService helps in two ways. First, it makes sure that a meaningful error code is returned to the Service Control Manager when the Windows Service cannot start. Second, it helps the developer to code long running start-up operations without having the Service Control Manager forcibly terminating the Windows Service.

Finally, BasiceServiceStarter has the responsibility of determining the mode of operation of the application: install the service; uninstall the service; run as a console; or run as a Windows Service. BasicServiceStarter also ensures that any background thread’s exception messages that might occur on the Windows Service start-up are reported to the Windows event log.

The series runs for seven articles, explaining in detail the reasoning behind this framework. The site’s philosophy is: “Instead of focusing on automation, focus on consistency and simplicity in you software.

Rate this Article

Adoption
Style

BT