Linux-admin-systemd-services-start-and-stop
Systemdサービスの開始と停止
initシステムとしての_systemd_は、Linuxカーネルの起動後にステータスの変更が必要なサービスとデーモンの両方を管理するために使用されます。 ステータスの変更により、サービス状態の開始、停止、リロード、および調整が適用されます。
まず、サーバーで現在実行されているsystemdのバージョンを確認しましょう。
CentOSバージョン7では、この執筆時点で完全に更新されたsystemdバージョン219が現在の安定バージョンです。
_systemd-analyze_を使用して、最後のサーバーの起動時間を分析することもできます
システムの起動時間が遅い場合は、_systemd-analyze blame_コマンドを使用できます。
_systemd_を使用する場合、_units_の概念を理解することが重要です。 *ユニット*は、_systemd_が解釈方法を知っているリソースです。 ユニットは次のように12種類に分類されます-
- 。サービス
- 。ソケット
- 。デバイス
- 。マウント
- .automount
- 。スワップ
- 。ターゲット
- 。パス
- 。タイマー
- .snapshot
- 。スライス
- 。範囲
ほとんどの場合、ユニットサービスとして.serviceを使用します。 他のタイプについてさらに調査することをお勧めします。 systemd_サービスの開始と停止には.service_ユニットのみが適用されるため。
各_unit_は、次のいずれかにあるファイルで定義されます-
- /lib/systemd/system -ベースユニットファイル
- /etc/systemd/system -実行時に変更されたユニットファイル
systemctlを使用してサービスを管理する
_systemd_を使用するには、_systemctl_コマンドに精通する必要があります。 以下は、_systemctl_の最も一般的なコマンドラインスイッチです。
Switch | Action |
---|---|
-t | Comma separated value of unit types such as service or socket |
-a | Shows all loaded units |
--state | Shows all units in a defined state, either: load, sub, active, inactive, etc.. |
-H | Executes operation remotely. Specify Host name or host and user separated by @. |
基本的なsystemctlの使用法
ボックスで実行されているすべてのサービスを簡単に確認します。
サービスを停止する
最初に、bluetoothサービスを停止します。
ご覧のとおり、bluetoothサービスは非アクティブになっています。
Bluetoothサービスを再度開始するには。
注-.service_が暗示されているため、bluetooth.serviceを指定しませんでした。 処理しているサービスに_unit type_を追加することを考えるのは良い習慣です。 したがって、ここからは、。service_拡張子を使用して、サービスユニットの操作に取り組んでいることを明確にします。
サービスで実行できる主なアクションは次のとおりです-
Start | Starts the service |
Stop | Stops a service |
Reload | Reloads the active configuration of a service w/o stopping it (like kill -HUP in system v init) |
Restart | Starts, then stops a service |
Enable | Starts a service at boot time |
Disable | Stops a service from automatically starting at run time |
上記のアクションは、主に次のシナリオで使用されます-
Start | To bring a service up that has been put in the stopped state. |
Stop | To temporarily shut down a service (for example when a service must be stopped to access files locked by the service, as when upgrading the service) |
Reload | When a configuration file has been edited and we want to apply the new changes while not stopping the service. |
Restart | In the same scenario as reload, but the service does not support reload. |
Enable | When we want a disabled service to run at boot time. |
Disable | Used primarily when there is a need to stop a service, but it starts on boot. |
サービスのステータスを確認するには-
_networking_サービスの現在のステータスを表示します。 私たちはネットワーキングに関連するすべてのサービスを見たい場合は、使用することができます-
サービスを管理する sysinit メソッドに精通している人にとっては、_systemd_に移行することが重要です。 _systemd_は、Linuxでデーモンサービスを開始および停止する新しい方法です。