Common startup and shutdown subroutines used by scripts
