systemdの使用

1.必要なコマンド

  1. systemctl status nginx.service、ユニットのステータスを表示します。
  2. systemctl start nginx.service、ユニットを開始します。
  3. systemctl restart nginx.service、ユニットを再起動します。
  4. systemctl stop nginx.service、ユニットを停止します。
  5. systemctl enable nginx.service、ブートから開始するように設定。
  6. systemctlはnginx.serviceを無効にし、オフにして自動的に起動します。

第二に、一般的に使用されるコマンド

  1. systemctl --version、バージョンを確認してください。
  2. whereis systemctl、場所を確認してください。
  3. systemctl list-unit-files、利用可能なすべてのユニット(サービス)をリストします。
  4. systemctl list-units、実行中のすべてのユニットをリストします。
  5. systemctl --failed、失敗したすべてのユニットをリストします。
  6. systemctl list-unit-files | grep enable、自動起動ソフトウェアを表示します。
  7. systemctl is-enabled nginx.service、ユニットの電源がオンになっているかどうかを確認します。
  8. systemctl daemon-reloadは、ユニットの構成ファイルを変更した後、構成ファイルを再ロードします。
  9. systemctl reload nginx.service、ユニットをリロードします。
  10. systemctl kill nginx、ユニットを強制終了します。

3. * .serviceファイルの構成:

 centos7はファイルディレクトリを作成します:/ etc / systemd / system /

例:nginx.serviceを作成する

vi /etc/systemd/system/nginx.service

コンテンツを編集する

[単位]

Description = nginx

After = network.target

[サービス]

Type = forking

ExecStart = / usr / local / nginx / sbin / nginx

ExecReload = / usr / local / nginx / sbin / nginx -s reload

ExecStop = / usr / local / nginx / sbin / nginx -s stop

Privatetmp = true

[インストール]

WantedBy = multi-user.target

 

  • [Unit]:サービスの説明
  • 説明:サービスについて説明します
  • 後:サービスカテゴリの説明
  • 【サービス】サービス運用パラメーターの設定
  • Type = forkingは、バックグラウンドで実行される形式です
  • ExecStartは、サービスの特定の操作コマンドです
  • ExecReloadは再起動コマンドです
  • ExecStopは停止コマンドです
  • PrivateTmp = Trueは、サービスに独立した一時スペースを割り当てることを意味します
  • 注:[Service]の起動、再起動、停止コマンドはすべて絶対パスを使用する必要があります
  • [インストール]実行レベルでのサービスインストールの関連設定をマルチユーザーに設定できます。つまり、システムの実行レベルは3です。

 

おすすめ

転載: www.cnblogs.com/corexy/p/12750490.html