memo

CentOS 7

Table of Contents

CentOS 7 で変わったコマンド

ネットワーク系

firewall系

サービス系

サービスを作成

  1. サービス定義ファイルを作成
    vim /etc/systemd/system/hoge.service
    [Unit]
    Description = Hoge!
    # xxx が動いてからこのサービスを起動する
    After = xxx.service xxx.target
    # xxx より前にこのサービスを起動する
    Before = xxx.service
       
    [Service]
    ExecStart = /usr/local/bin/hoge.sh
    ExecStop = /usr/bin/kill $MAINPID
    Restart = [no|always]
    Type = [simple|forking]
       
    [Install]
    WantedBy = multi-user.target
    
  2. systemctl に認識されたか確認
    systemctl list-unit-files --type=service | grep hoge
  3. 有効化
    systemctl enable hoge.service
  4. /etc/systemd/system/hoge.service を編集した場合は再読み込み
    systemctl daemon-reload
    • サービス実行状態を表示
      systemctl status hoge.service
    • サービス実行状態全体を表示
      systemctl -l status hoge.service
    • ログ表示
      journalctl -xe
    • 依存しているサービスを表示
      systemctl list-dependencies –after hoge.service
    • 依存されているサービスを表示
      systemctl list-dependencies –before hoge.service

その他設定