-This page describes a configuration useful primarily for virtual machines which should be shut down when they stop being useful (doing work).
+Known to work with HTCondor version: 8.5.4 (see below if you have an earlier version)
 
-We start by configuring the startd to shut down if it hasn't been claimed for five minutes:
 
-{verbatim}
-STARTD_NOCLAIM_SHUTDOWN = 300.
-{endverbatim}
+This page describes a configuration useful primarily for virtual machines serving as an HTCondor execute node, and the admin wants the machine to be shut down when it is no longer being scheduled to run jobs.  This setup is handy for running execute nodes in public clouds when you don't want to keep paying to run execute nodes that aren't doing anything (ie prefer these nodes simply shutdown when they become idle).
 
-We then configure the master to shut down when the startd shuts down.  Note that we give the startd sixty seconds to start up the first time; this time-out would be unnecessary if STARTD_StartTime were guaranteed to be unset rather than zero before the startd starts up.
+Add the following to your condor_config file(s) :
 
-{verbatim}
-MASTER.DAEMON_SHUTDOWN_FAST = ( STARTD_StartTime == 0 ) && ((CurrentTime - DaemonStartTime) > 60)
-{endverbatim}
+{code}
+# Tell HTCondor to daemons to gracefully exit if the condor_startd observes
+# that it has had no active claims for more than five consecutive minutes.
+STARTD_NOCLAIM_SHUTDOWN = 300
 
-Then, when the master shuts down, we want to run a script to shut down the machine.  All that this configuration knob does is define the "SHUTDOWN" name; you can pick another.
+# Next, tell the condor_master to run a script as root upon exit.
+# In our case, this script will shut down the node.
+DEFAULT_MASTER_SHUTDOWN_SCRIPT = /etc/condor/shutdown
 
-{verbatim}
-MASTER_SHUTDOWN_SHUTDOWN = /etc/condor/shutdown
-{endverbatim}
-
-To activate the shutdown script named "SHUTDOWN", use the =condor_set_shutdown= command with the -exec option.  This command must be run each time the master is (re)started by a user with sufficient privilege.  Since start-up times are somewhat variable, you may want to use a retry loop like the one below; make sure that service and condor_set_shutdown are in the PATH.  (If you've automated the start-up of HTCondor, you need to automate running condor_set_shutdown to make this work; if the HTCondor in your VM starts on boot, you could put this in rc.local, for instance.)
+# This final config knob is for the paranoid, and covers
+# the case that perhaps the condor_startd crashes.  It tells the
+# condor_master to exit if it notices for any reason that the
+# condor_startd is not running within 1 minute of startup.
+MASTER.DAEMON_SHUTDOWN_FAST = ( STARTD_StartTime == 0 ) && ((CurrentTime - DaemonStartTime) > 60)
+{endcode}
 
-{verbatim}
-while ! condor_set_shutdown -exec shutdown; do sleep 1; done
-{endverbatim}
 
 The script (=/etc/condor/shutdown= in this example) must of course be executable (and have the #! line), and is run by the master as root when the master shuts down.  The following script may be useful as an example to work from.
 
-{verbatim}
+{code}
 #!/bin/sh
 
 # We start out trying to determine if this shutdown was voluntary or not.
@@ -52,4 +50,19 @@
 # Shut the machine down.  Comment this line out if you're just testing,
 # of course. :)
 /sbin/shutdown -h now
+{endcode}
+
+
+{subsection: Versions of HTCondor older than v8.5.4}
+
+Versions of HTCondor before v8.5.4 do not have the =DEFAULT_MASTER_SHUTDOWN_SCRIPT= knob, which makes things more clumsy. However, you can  make do with the =condor_set_shutdown= command-line utility (see the man page) to pick a script to run upon system shut down.  For example, place the following into your condor_config:
+
+{verbatim}
+MASTER_SHUTDOWN_MYSHUTDOWN = /etc/condor/shutdown
+{endverbatim}
+
+Then to activate the shutdown script defined by "MYSHUTDOWN", use the =condor_set_shutdown= command with the -exec option.  This command must be run each time the master is (re)started by a user with sufficient (administrator) privilege.  Since start-up times are somewhat variable, you may want to use a retry loop like the one below; make sure that service and condor_set_shutdown are in the PATH.  (If you've automated the start-up of HTCondor, you need to automate running condor_set_shutdown to make this work; if the HTCondor in your VM starts on boot, you could put this in rc.local, for instance.)
+
+{verbatim}
+while ! condor_set_shutdown -exec myshutdown; do sleep 1; done
 {endverbatim}