Skip to main content

Start Up and Shut Down Scripts

Scripts provide a consistent method to start up and shut down services on Linux.

This article applies to: Managed Servers


Use this procedure as a consistent method of starting services on Unix. A side benefit of this procedure is that it keeps user-space applications out of the system startup/shutdown process so they do not hinder a system during boot or shutdown.

The system directory tree "/usr/app/" exists to provide this startup/shutdown capability. Each service will have its own subdirectory containing the scripts required to start, stop and perform daily cleanup tasks. Services are registered in the file "/usr/app/services.node" so the system knows which ones to start/stop.

Basic "cleanup" functionality is provided if you create a script "rc.cleanup"; this script will be run daily at 4:15am. Typical uses include cleaning up log files and/or temporary files.

Do not install other application-specific files in "/usr/app/." That directory should contain only the three scripts for startup (rc.local), shutdown (rc.shutdown) and the optional cleanup script (rc.cleanup).

Services are shut down in reverse order of how they were started. This means that "services.node" is parsed top to bottom to initiate startup and bottom to top to perform shutdown. Cleanup is unaffected and will be processed in the order the services appear in the file, just like startup.

To use start up and shut down scripts

  1. Create subdirectory of /usr/app for your service: sudo mkdir /usr/app/SERVICENAME
  2. Create "etc" subdirectory to hold your scripts: sudo mkdir /usr/app/SERVICENAME/etc
  3. Create startup script "rc.local": sudo vi /usr/app/SERVICENAME/etc/rc.local
  4. Create shutdown script "rc.shutdown": sudo vi /usr/app/SERVICENAME/etc/rc.shutdown
  5. OPTIONAL: Create daily cleanup script "rc.cleanup":
    sudo vi /usr/app/SERVICENAME/etc/rc.cleanup
  6. Test your scripts manually to make sure they actually start, shut down, and clean up after your application.
  7. Add the name of your directory to "services.node": sudo vi /usr/app/services.node
    The directory name is relative to "/usr/app/" and should not contain slashes.
    Continuing with the example, add SERVICENAME to the file on a line by itself.

Was this page helpful?

Your feedback helps improve the site.

Comments?