Executing your script on startup

This recipe is not limited to running only applications or services at startup, but to also start scripts on bootup (power on) of a system. For example, if your system boots up and you would like to apply several tweaks to the OS such as performance enhancements or battery tweaks, you can do this on startup via the systemd or init.d script. Another example could be to run a never ending script that creates logging events, like an electronic version of a pulse monitor.

In short, Linux or most *NIX systems use either the venerable rc.d system or the newer and more controversial systemd system to manage the starting and stopping of system resources. Without diving into the entire boot sequence of Linux, here is how it works:

  1. The Linux kernel is loaded and mounts the root filesystem.
  2. The rootfile system contains a shell at a particular path (the init level).
  3. Then, the systemd works its way through a series of services to start (the run level).

If a service or script is added, it will likely be added at the run level. It can also be started, stopped, reloaded, and restarted from the command line at any time as well. When the system is booting, it merely uses the start functionality provided by the init.d or system.d script. However, even though the semantics of either the rc.d or systemd system differ, they still require the following:

  • Scripts or services need to be enabled for specific system startup levels.
  • Scripts to be started and/or stopped can be configured to be started in a specific order.
  • Directives for starting (at a minimum), stopping, restarting and/or reloading are executed based on a parameter when executing one of these actions (or blocks). Any number of commands can also be executed when calling start, for example.
You may notice when scouring the web when looking for resources that a number of init systems exist: upstart, SysVinit, rc.d, procd, and the list goes on. You can refer to your distribution documentation for a current explanation on the startup system in use.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.15.170