Run a Script on Startup or Shutdown

From TheBeard Science Project Wiki
Jump to: navigation, search

Unfinished page...

This page describes how to set up a script to run on system startup or shutdown on a Linux system. I will not describe how to configure "Startup Applications" through the user preferences menu, as those settings are user-specific and only run on user login. This tutorial is more for advanced users and will allow you to run a script before, during, or after the startup/shutdown process. This is useful when you need to run things in a particular order or when you need the startup/shutdown process to wait for your script to finish.

The setup will differ depending on if your system uses classic System V Init (SysV), Upstart, or Systemd.

How do I know what my system uses?

Try this:

sudo stat /proc/1/exe | head -1
File: '/proc/1/exe' -> '/lib/systemd/systemd'

The /proc directory contains process information, and /proc/1 is the process running with PID 1. Init always runs with PID 1. The exe file is a symlink to the executable that is running. This indicates what init your system uses. In this example, my system uses systemd. If the result shows '/sbin/init' you may still need to investigate what that file is linked to, because it may not be the true SysV init :

sudo stat /sbin/init | head -1
File: '/sbin/init' -> '/lib/systemd/systemd'

System V

Upstart

Systemd