Using Start and Stop Scripts

You can supply start and stop scripts to take additional actions before or after starting or stopping an enterprise server. You must include the casstart command in your start script, and the casstop command in your stop script. If you omit them the server will not actually be started or stopped.

The Directory Server sets some environment variables in the scripts' environment, which you can use in your scripts:

ES_MFDS_ADDRESS Specifies the server address which is used by casstart if the /m parameter is not provided.
ES_HOME Server work directory (location of log files); this comes from the System Directory field on the Add Server or Edit Server > Properties > General page.
ES_SERVER Server name (note that Enterprise Server will use this as the server name if no -r switch is specified on casstart or casstop).
MFDS_PORT The port on which the Directory Server listens (usually 86).

If you specified a location for the server work directory, rather than taking the default, during the installation process or when you ran the casperm command, that location overrides the location specified in the System Directory field in the server configuration. The result is that ES_HOME will not be set correctly for startup and shutdown scripts. We recommend using the System Directory field rather than specifying a non-default location during installation or with the casperm command for this reason.

For example, the start script could be used to set environment variables for the server, as follows;
set MY_VARIABLE=value
rem start the enterprise server
echo Enterprise Server %ES_SERVER% is starting
casstart   
#! /bin/ksh
export MY_VARIABLE=value
# start the enterprise server
echo Enterprise Server $ES_SERVER is starting
casstart

where value is the value of the environment variable.

If your stop script contains commands that should only be executed after the server has stopped completely, it should pause after executing casstop until thecascd process for that server has exited. This is because the casstop command returns before the server has actually finished shutting down. You would need third-party tools to do this on Windows.You can do this by querying the status of the cascd process, the enterprise server console daemon. For example:

#! /bin/ksh
 # Get the PID of the cascd process
 Cascd=$(ps -ef | awk '$8~/cascd/ && $9~/.rESDEMO/ {print $2}')
 
 # Begin shutdown
 casstop

 # Wait for the cascd process to exit
 while ps -p $Cascd > /dev/null; do sleep 1; done

Then you could back up the log files or perform other tasks that should only be started after the server finishes shutting down.

When you click the server's Start or Stop button, the commands that you specify are used to generate a Windows batch fileUNIX shell script, which is then executed.

You can also create an "On server not responding" script. This script will be executed when all of the running communications processes for a server have entered the "Not Responding" state. That might indicate that the server is hung or has crashed, or it might result from network connectivity problems between the Directory Server and the enterprise server. You can use this script to notify a system administrator of the problem.

You specify start, stop and "On server not responding" scripts on the Edit Server > Properties > Scripts page.