FAQs: Creating an Automatic Server Halt and Run Script for UNIX Systems
The script auto_haltrun allows you to halt, initialize, and run SirsiDynix Symphony and SirsiDynix product agent services from the UNIX command line, or automatically via the UNIX cron facility. The auto_haltrun script may also be used to provide basic system status information.
Use of the auto_haltrun script should be restricted to very experienced system administrators who are familiar with the UNIX operating system. This script is only for UNIX systems. (For information about the Windows auto_haltrun script, see FAQs: Creating an Automatic Server Halt and Run Script for Windows Servers.)
Command Line Usage
The auto_haltrun script is run from the UNIX command line. The structure of the command is as follows, where only one of these operations is used with any of the flags.
auto_haltrun {cycle|halt|init|run|status} [ignore_users] [ignore_reports] [exclude_agents | force_agents] [warn] [force]
auto_haltrun Operations
The operations specify what will be done in the system. Only one operation can be run at a time and can be run with one or more flags.
cycle
When cycle is specified, auto_haltrun attempts to halt, initialize, run, and provide status, in that sequence. It does this using standard administration tools which have been altered to operate without requiring user intervention.
halt
When halt is specified, or during the halt phase of a cycle, auto_haltrun checks the state of the system for the following conditions.
• | Users logged in |
• | Running reports |
If either of these conditions is found to be true, the system is not halted.
init
When init is specified, or during the init phase of a cycle, auto_haltrun checks the state of the system for the following conditions.
• | Servers running |
• | Users logged in |
• | Running reports |
If any of these conditions is found to be true, initialization is not performed.
run
When run is specified, or during the run phase of a cycle, auto_haltrun checks the state of the system to see if there are any servers running. If any servers are running, auto_haltrun prints an informational message and continues, running any halted servers.
status
A status phase is always performed by auto_haltrun to report the final state of the system after all other phases have been attempted. The status argument only reports, and never changes the state of the running system.
Note: The auto_haltrun script cannot be run as the root user, and should always be run from the sirsi user account.
auto_haltrun Flags
The administrator can include certain flags to designate how auto_haltrun behaves when users are logged in or reports are running. Other flags can indicate how auto_haltrun should affect SirsiDynix agent processes running on the server if they have been configured to halt and run along with the SirsiDynix Symphony processes.
ignore_users
If the ignore_users flag is specified, auto_haltrun performs the halt, initialize, run, and cycle operations regardless of whether users are logged in, but does not perform the operations if reports are running.
ignore_reports
If the ignore_reports flag is specified, the halt, initialize, run, and cycle operations will be performed regardless of whether reports are being run, but will not be performed if users are logged in.
exclude_agents
If the exclude_agents flag is specified, auto_haltrun performs any specified halt, initialize, run, and cycle operations except for those involving agents for other SirsiDynix products (if you have configured any product agents to halt and run along with the auto_haltrun script).
For example, the following command halts all SirsiDynix Symphony operations but does not halt any SirsiDynix product agents that are running on the server (such as the BLUEcloud Harvester):
auto_haltrun halt exclude_agents
Note: If you run the auto_haltrun command with only the exclude_agents flag specified, auto_haltrun does not halt services if reports are running or users are logged in. If you want the auto_haltrun command to ignore reports that are running or users that are logged in, you need to specify the appropriate flag or flags in the auto_haltrun command in addition to the exclude_agents flag.
Note: This flag can only have effect if there is a configured agents.cfg file on your SirsiDynix Symphony server and the file's allowhalt value is set to Y. For information on how to configure this file, see Configuring SirsiDynix agent processes to halt and run using the auto_haltrun script.
force_agents
If the force_agents flag is specified, auto_haltrun performs any specified halt, initialize, run, and cycle operations, including those for SirsiDynix product agents also running on the server, even if the allowhalt value in the agents.cfg file is set to N.
Note: If you run the auto_haltrun command with only the force_agents flag specified, auto_haltrun does not halt services if reports are running or users are logged in. If you want the auto_haltrun command to ignore reports that are running or users that are logged in, you need to specify the appropriate flag or flags in the auto_haltrun command in addition to the force_agents flag.
Note: This flag can only have effect if there is a configured agents.cfg file on your SirsiDynix Symphony server. For information on how to configure this file, see Configuring SirsiDynix agent processes to halt and run using the auto_haltrun script.
warn
If the warn flag is specified, auto_haltrun will prompt you to terminate any running reports and to close any user connections before proceeding with the script before performing the designated halt, initialize, run, or cycle operation.
force
If the force flag is specified, the halt, initialize, run, and cycle operations will be performed regardless of whether users are logged in or whether reports are running.
Execution Restrictions
Like many system utilities, only one instance of auto_haltrun may be running at a time. If a second copy of auto_haltrun is invoked from another station or by another system user, auto_haltrun displays the following message and terminates.
**ERROR--auto_haltrun is currently running.
The auto_haltrun script will also check whether there is a backup in progress or if log files are being copied to tape. If so, auto_haltrun terminates with an error message. For sites that do not use SirsiDynix backup utilities, a custom halt/run script may be used to detect the existence of any running non-SirsiDynix backup facilities. You should have SirsiDynix API training before attempting to use a custom halt/run script.
Automatic Operation through the Cron Facility
The auto_haltrun script may be automated to run through the UNIX cron facility.
Before setting up any jobs with the cron facility, it may be necessary to ask your UNIX system administrator to give you access to it. This mechanism differs from system to system, and so will not be detailed here.
Since administration of the crontab file entries differs depending on the particular UNIX implementation you are running, implementation-independent examples will be presented here. Please consult the system administration documentation pertinent to the implementation of UNIX at your site for more specific details.
When setting up auto_haltrun to be executed automatically via cron, it is necessary to use a wrapper script to set up the proper environment, and then run the auto_haltrun facility itself. This wrapper script must be placed in the /Unicorn/Bincustom directory.
It is recommended that the auto_haltrun script be scheduled using SirsiDynix crontab. If not, you must use the following command to change to the Sirsi user when the auto_haltrun script is called. Typically, only a super user (normally the Root user) has permission to make this change. This command assumes your SirsiDynix Symphony system is in /s/sirsi.
su – sirsi –c ”/s/sirsi/Unicorn/Bincustom/haltrun_wrap 2>&1”
A very simple example of an auto_haltrun wrapper script that would be placed in Bincustom follows.
:
# Copyright (c) 2005, SirsiDynix
#
# sample auto_haltrun wrapper script
hr_command=”$1”
hr_force=”$2”
#
# Change the location of this output file as needed.
#
# Leave the ”.$$” so that a unique file is created
#with the extension of its process id.
#
outputfile=/tmp/haltrun.$$
#
# Note that the line below dots in the environ file
#from a specific path. This is necessary because at
#this point in processing, the PATH env
#variable has not been set up yet, therefore it is
#not possible to run `getpathname` in order to get
#the location of the Config directory.
# Dotting in the environ file and exporting the
#variables sets up enough of a SirsiDynix Symphony environment
#to use the tools and to have access to UPATH
#entries and SirsiDynix Symphony tools.
#
# Be sure to alter this fixed path to point to the
#environ file on your system.
#
. /s/sirsi/Unicorn/Config/environ # <==change this
#as needed for your site
export PATH BRSConfig UPATH WINDIR TERMINFO TERMCAP TZ
customdir=`getpathname custom
`distlist=”${customdir}/haltrun_dist”
auto_haltrun ”${hr_command}” ”${hr_force}” 2>&1 > ${outputfile}
if [ -s ${distlist} ]
then
mail `cat ${distlist}` < ${outputfile}
else
mail sirsi < ${outputfile}
fi
rm -f ${outputfile}
This script sets up the necessary environment by dotting in the /Unicorn/Config/environ file and exporting critical environment variables, runs the specified auto_haltrun command, and redirects the output to a file. The output file is then mailed to all users found in the list file /Unicorn/Custom/haltrun_dist.
A sample haltrun_dist file containing e-mail addresses, one per line, might resemble the following.
sirsi
john@unc.edu
webmaster@bigsite.com
A crontab entry may be created to cycle the system at 1:00 every morning. Check your UNIX documentation for the exact format of crontab entries as they differ from system to system.
Note that a fixed path must be used to invoke the haltrun_wrap script, as the command `getpathname bincustom` cannot be used here since the SirsiDynix Symphony environment has not been properly set up at this point.
# mins hrs day month weekday commands ...
0 1 * * * /s/sirsi/Unicorn/Bincustom/haltrun_wrap cycle
2>&1
Cron works in such a way that the user account that set up the entry will receive an email containing the stdout output of the job, and another email of the stderr output of the job. In the scheme outlined above, the haltrun_wrap script does a direct mailing to the user accounts contained in the /Unicorn/Custom/haltrun_dist file. There will also be another e-mail produced by cron which will contain any errors encountered while trying to run the /Unicorn/Bincustom/haltrun_wrap script itself. This may be suppressed, if desired, by directing all output to /dev/null. It is recommended that this change be delayed until after a lengthy period of successful automatic halt/init/runs by the auto_haltrun facility to insure that all potential problems have been resolved with timing of jobs at your site.
A sample crontab entry that ignores its output completely follows.
# mins hrs day month weekday commands ...
0 1 * * * /s/sirsi/Unicorn/Bincustom/haltrun_wrap cycle
2>&1 >/dev/null
Special care should be used when setting up an automatic halt, initialize, and run, since this must happen in harmony with scheduled reports, system backups, and other periodic system events.
Sample Output
Sample output from the auto_haltrun script follows.
Some servers only exist on the system if your site has certain features configured.
For example, the auto_haltrun script has been run with the status option.
auto_haltrun status
The script returns the following output.
UNICORN Auto Halt/Run Utility started on Mon Jan 26 14:20:06 CST 2009 running as user ”SIRSI” on machine ”libserver”
Parameters given: status
======================= STATUS MESSAGES =======================
UNICORN Netserver XXXX.X.X.X is RUNNING.
UNICORN Report Server XXXX.X.X.X is RUNNING.
There are 0 report(s) running.
No NAMED/PORT stations are in use.
No apiserver stations are in use.
No webserver stations are in use.
No users are logged in.
No utilities are in use.
UNICORN Workstation server XXXX.X.X.X is RUNNING.
UNICORN Workstation socket server XXXX.X.X.X is RUNNING.
UNICORN Webcat server XXXX.X.X.X is RUNNING.
UNICORN Z39.50 server is RUNNING.
UNICORN SIP 2 server is RUNNING.
UNICORN MARC Listener server is RUNNING.
UNICORN Auto Halt/Run Utility finished on Mon Jan 26 14:20:06 CST 2009
In the following example the auto_haltrun script has been run with the cycle option.
auto_haltrun cycle
The script returns the following output.
UNICORN Auto Halt/Run Utility started on Mon Jan 26 14:17:53 CST 2009 running as user ”SIRSI” on machine ”libserver”
Parameters given: cycle
======================== HALT MESSAGES =========================
UNICORN Netserver is now HALTED.
UNICORN Report Server is now HALTED.
UNICORN Webcat server is now HALTED.
UNICORN Z39.50 server is now HALTED.
UNICORN SIP 2 server is now HALTED.
UNICORN MARC Listener server is now HALTED.
UNICORN Workstation server is now HALTED.
UNICORN Workstation socket server is now HALTED.
UNICORN Webcat server is already HALTED.
=================== INITIALIZATION MESSAGES ====================
UNICORN Netserver initialized.
UNICORN Report Server initialized.
All apiserver stations initialized.
All bserver stations initialized.
No UNICORN NAMED/PORT stations are in use.
No users are logged in.
No utilities are in use.
UNICORN Workstation server initialized.
UNICORN Webcat server initialized.
UNICORN Z39.50 server initialized.
UNICORN SIP 2 server initialized.
UNICORN MARC Listener server initialized.
======================== RUN MESSAGES =========================
UNICORN Workstation server is now RUNNING.
UNICORN Workstation socket server is now RUNNING.
UNICORN Netserver is now RUNNING.
UNICORN Report Server is now RUNNING.
UNICORN Webcat server is now RUNNING.
UNICORN Z39.50 server is now RUNNING.
UNICORN SIP 2 server is now RUNNING.
UNICORN MARC Listener server is now RUNNING.
======================= STATUS MESSAGES =======================
UNICORN Netserver XXXX.X.X.X is RUNNING.
UNICORN Report Server XXXX.X.X.X is RUNNING.
There are 0 report(s) running.
No NAMED/PORT stations are in use.
No apiserver stations are in use.
No bserver stations are in use.
No users are logged in.
No utilities are in use.
UNICORN Workstation server XXXX.X.X.X is RUNNING
UNICORN Workstation socket server XXXX.X.X.X is RUNNING.
UNICORN Webcat server XXXX.X.X.X is RUNNING.
UNICORN Z39.50 server is RUNNING.
UNICORN SIP 2 server is RUNNING.
UNICORN MARC Listener server is RUNNING.
UNICORN Auto Halt/Run Utility finished on Mon Jan 26 14:18:03 CST 2009
Troubleshooting
If the first output line is missing the SIRSI user name, like in the following example, this indicates that the environment for your auto_haltrun script was not set up properly.
UNICORN Auto Halt/Run Utility started on Mon Jan 26 14:20:06 CST 2009
running as user ” ” on machine ”libserver”
To correct this, add the following lines to the environment file, typically /Unicorn/Config/environ.
HALTRUN_USER=sirsi
export HALTRUN_user
serveradmin Log File
A log file, serveradmin, tracks automated halt, initialize, and run activities. This log may be viewed via the Logs utility.
For example:
20180126125723 UNICORN Workstation server -- STATUS requested(interactive)
20180126125730 UNICORN Z39.50 server -- STATUS requested(interactive)
20180126130411 UNICORN gatewayrpt -- STATUS requested (automated)
20180126130411 UNICORN Netserver -- STATUS requested (automated)
20180126130412 UNICORN Report Server -- STATUS requested (automated)
20180126130412 UNICORN stationlock -- STATUS requested (automated)
20180126130413 UNICORN userlock -- STATUS requested (automated)
20180126130414 UNICORN utilitylock -- STATUS requested (automated)
20180126130415 UNICORN Workstation server -- STATUS requested (automated)
20180126130416 UNICORN Webcat server -- STATUS requested (automated)
20180126130416 UNICORN Z39.50 server -- STATUS requested (automated)
20180126130416 UNICORN SIP 2 server -- STATUS requested (automated)
20180126130416 UNICORN MARC Listener server -- STATUS requested (automated)