Thu Sep 5 19:31:46 2019 UTC

SysVinit

Introduction

SysVinit is the init process (the process that starts other processies) of NuTyX. Inits are often called PID1 (process ID 1) since they are always the first process to start on a system. They INITialize the system. SysVinit's origins can be traced back to unix and has been frequently used in numerous distros.

Runlevels

SysVinit functions by defining what processes startup based on their runlevels. Runlevels can be found be in /etc/rc.d and are defined in /etc/initab.

Navigate to /etc/rc.d using the cd command:

cd /etc/rc.d

The output from an ls command should be:

init.d  rc0.d  rc1.d  rc2.d  rc3.d  rc4.d  rc5.d  rc6.d  rcS.d

The following directories e.g. rc0, rc1, etc are all runlevels in NuTyX.

Runlevels in NuTyX

The default configuration of the NuTyX runlevels is:

  • rc0 (runlevel 0): Halt.
  • rc1 (runlevel 1): Single user mode.
  • rc2 (runlevel 2): Multiuser Mode.
  • rc3 (runlevel 3): Full Multiuser Mode
  • rc4 (runlevel 4): Full Multiuser Mode
  • rc5 (runlevel 5): Graphical Environment Mode
  • rc6 (runlevel 6): Reboot
  • rcS (runlevel S): Tells the system what to run during initialization.

rcS is a runlevel whose main use is for the initialization of the system. Runlevel 4 is a repeat of 3 so that a user may edit it and use it for what they seem fit.

Contents of the Folders

Navigating to each runlevel, the contents can be listed out through an ls command:

ls

Example of my runlevel 2:

K46ntpd  K80network  S15dbus  S25cups  S25random  S31elogind  S70gpm

All files within this directory are not startup scripts themselves but symbolic links to startup scripts. These scripts are contained in the /etc/init.d directory. The letter beginning each link has significance. A link beginning with k means that the service is killed at this run level and needs the appropriate portion of the script to run. S means that the service must start at this runlevel. The number following the letter indicates the priority for the service to start or be killed (when starting up services, in what order to start them). The lower numbers are started first and then the higher ones are started.

Looking at a Startup Script

Open a script in /etc/init.d with your favorite text editor. The following is a portion of my cups file within init.d:

case $1 in
   start)
      log_info_msg "Starting CUPS Printserver..."
      start_daemon /usr/sbin/cupsd
      evaluate_retval
      ;;

   stop)
      log_info_msg "Stopping CUPS Printserver..."
      killproc /usr/sbin/cupsd
      evaluate_retval
      ;;

Each script is a file written in bash that contains a case statement. Case statements are used to match an arguement to several different outcomes. Through case statements, these scripts only run portions of code needed for specific tasks. For example, upon starting a service, a script will run all of the lines relating to start and then end.