Unix Init Process: Systemd


Init precess. サービス管理システムは、カーネルの起動が完了した後、最初のpidプロセスから順次実行されます.サービスとは、オペレーティングシステムで起動し、バックグラウンドで実行を継続するプログラム(プロセス)です.システムに必要なサービスは、起動完了後に実行する必要がないため、initプロセスではpid 1 initプログラムから順次実行されます.
各OSにどのようなシステムがあるかについては、Wikipediaのマニュアルを参照してください.
https://en.wikipedia.org/wiki/Operating_system_service_management
  • カーネルパニックブログ:文章の専門性は非常に高い.推奨
    https://www.kernelpanic.kr/18
  • Service Control Manager - Used by Microsoft Windows
    launchd - Used by Apple macOS
    systemd - Used by many Linux distributions
    Upstart - Used by Google Chrome OS
    Service Management Facility - Used by illumos distributions and Oracle Solaris
    Android init - Used by Google Android
    sysvinit - Used by older Unix-like operating systems
    rc.d or rcorder-based init - Used by BSD operating systems
    cygserver - Used by Cygwin
    runit - Used by Void
    OpenRC - Used by Gentoo
    The GNU Shepherd - Used by the Guix System Distribution and GNU Hurd but designed to work on every POSIX-like system where Guile is available

    systemd


    System V initシステムでは、initが過去にpid 1であった場合.最新リリースsystemdはpid 1です.
    Systemdは起動時にプログラムを並列に実行させ、起動を速める.多様なサービスを提供する.
    systemctrlの使用

  • サービスファイルとディレクトリ構造:
    /etc/systemd/: configure
    /lib/systemd/:バイナリ実行可能ファイルが存在する
    /lib/systemd/system/:Service、宛先

  • 実行方法
  • systemctl start | stop | restart [unit name] 

    その他のオプション

  • 起動時間確認
  • $ systemd-analyze 
    Startup finished in 3.503s (kernel) + 43.131s (userspace) = 46.635s
    $ systemd-analyze blame
             31.977s apt-daily.service
              9.106s NetworkManager-wait-online.service
              3.172s apt-daily-upgrade.service
              1.974s docker.service
    
    

    System V init


    何十年も経った古いUNIXブートシステム.そのため、最近はシステムdに取って代わられていることが多い.

  • ディレクトリ構造
    /etc/rc.d/{name}

  • 実行方法
  •  $ service {name} status
    ソースのダウンロード:http://download.savannah.gnu.org/releases/sysvinit/

    upstart


    過去に友情奮闘で使われたシステム.UNIX上のSystem Vinitと互換性があります.開発は行わず、メンテナンスのみを行います.

  • サービスファイル:
    /etc/init.d/{name},
    /etc/rc{runlevel}.d/[S|K]{seq}{name}
    rcはリンクファイルであり、runlevel[2,3,4,5]はSで始まる.[0,1,6]Kで始まるseqが優先される

  • 実行方法:
  • $ status {name}
    $ service {name} status (sys V호환)

    リファレンス

  • system v init:
    http://soopsaram.com/lfs/markdowns/7_System_Configuration_and_Bootscripts.html#76-system-v-bootscript-usage-and-configuration
  • https://github.com/systemd/systemd
  • https://stackframe.tistory.com/12
  • https://62che.com/blog/cloud-server/systemd-Upstart-sysV-init.html#%E1%84%8C%E1%85%A9%E1%84%89%E1%85%A1%E1%84%92%E1%85%A1%E1%84%80%E1%85%B5