In certain situations it can be quite useful to discern the service name and the PID (process identifier) of a Zope instance - in order to monitor the instance, to control memory usage, or to start a new service, for example. This article descripes a Python program that assists to restart the service via a batch file.
In order to start or stop a Zope service with standard Windows utilities it is first necessary to discern the name. Looking into the service properties gives us a one-glance chance to do so. The name is composed of the string Zope_ and a number that at first glance might seem rather cryptic.
Typing out the name is annoying and leads to errors. It is a lot easier to have the name generated from the hashcode of the relevant INSTANCE_HOME path. This code fragment provides the service name to the respective Zope service as shown in the screenshot above:
The following Python script generates a batch file entitled restart.bat in the \bin directory of the defined instance. This file stops and starts the Zope service with assistance of Windows' own net start/stop command.
This is the content of the generated batch file:
The PID of an operational Zope process is contained within the \\var\Z2.pid file in the INSTANCE_HOME directory.
This script provides the PID as a numerical value. If the process is not running it should return '0'.
The following script returns the current memory usage as pertains the Zope process. The path to the INSTANCE_HOME directory suffices as handoff parameter.
The functions described above, such as the start / stop function for a Zope isntance or the return of the memory usage value for a particular instance can be used, for example, to stop an instance for a nightly backup of the "Data.fs" files or to monitor the memory usage of a particular instance. It is possible, for example, to forward the value of the current memory being used as a string onto a HTML page. This could be used as a so-called "HTTP Advanced sensor" when using a server monitoring program, such as IPCheck. When surpassing a defined threshold it would thus be possible to trigger an alarm.
Furthermore, these functions can be used in order to display detailed information about the instance, as well as start/stop functions within the ZMI.