systemctlコマンドはサービスを管理するコマンドです。
やすひら
systemctlコマンドの概要と使用方法を紹介します
この記事でわかること
- systemctlコマンドの概要
- systemctlコマンドの使い方
目次
コマンド概要
systemctlコマンドは、サービスを管理するためのコマンドです。
systemctlを使用することで、サービスの開始、停止、再起動、ステータス確認等の設定などを行うことができます。
コマンドオプション
コマンドオプションを紹介します。
コマンドオプション | 意味 |
---|---|
start | サービス開始 |
stop | サービス停止 |
restart | サービス再起動 |
status | サービス状態を表示 |
enable | サービスを自動起動する |
disable | サービスを自動起動しない |
reload | サービスの設定ファイルを再読み込み |
list-units | サービス一覧を表示 |
コマンドの使い方
systemctlコマンドの使い方を紹介します。
サービスを開始
サービスを開始します
コマンド形式
systemctl start [サービス名]
コマンド実行例
$ sudo systemctl start bluetooth.service
[sudo] password for user:
$ systemctl status bluetooth.service
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2024-06-17 22:56:41 JST; 15h ago
Docs: man:bluetoothd(8)
Main PID: 1125 (bluetoothd)
Status: "Running"
Tasks: 1 (limit: 4061)
Memory: 1.9M
CPU: 262ms
CGroup: /system.slice/bluetooth.service
└─1125 /usr/lib/bluetooth/bluetoothd
Jun 18 12:36:46 machine000 bluetoothd[1125]: Endpoint unregistered: sender=:1.36 path=/MediaEndpoint/A2DPSink/sbc_xq_552
Jun 18 12:36:46 machine000 bluetoothd[1125]: Endpoint unregistered: sender=:1.36 path=/MediaEndpoint/A2DPSource/sbc_xq_552
Jun 18 12:36:47 machine000 bluetoothd[1125]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc
Jun 18 12:36:47 machine000 bluetoothd[1125]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc
Jun 18 12:36:47 machine000 bluetoothd[1125]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_453
Jun 18 12:36:47 machine000 bluetoothd[1125]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_453
Jun 18 12:36:47 machine000 bluetoothd[1125]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_512
Jun 18 12:36:47 machine000 bluetoothd[1125]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_512
Jun 18 12:36:47 machine000 bluetoothd[1125]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_552
Jun 18 12:36:47 machine000 bluetoothd[1125]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_552
指定したサービスを開始しました。
サービスを停止
サービスを停止します
コマンド形式
systemctl stop [サービス名]
コマンド実行例
$ sudo systemctl stop bluetooth.service
[sudo] password for user:
$ systemctl status bluetooth.service
○ bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Tue 2024-06-18 14:57:23 JST; 3s ago
Docs: man:bluetoothd(8)
Process: 1125 ExecStart=/usr/lib/bluetooth/bluetoothd (code=exited, status=0/SUCCESS)
Main PID: 1125 (code=exited, status=0/SUCCESS)
Status: "Powering down"
CPU: 271ms
Jun 18 14:57:23 machine000 bluetoothd[1125]: Endpoint unregistered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_453
Jun 18 14:57:23 machine000 bluetoothd[1125]: Endpoint unregistered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_453
Jun 18 14:57:23 machine000 bluetoothd[1125]: Endpoint unregistered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_512
Jun 18 14:57:23 machine000 bluetoothd[1125]: Endpoint unregistered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_512
Jun 18 14:57:23 machine000 bluetoothd[1125]: Endpoint unregistered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_552
Jun 18 14:57:23 machine000 bluetoothd[1125]: Endpoint unregistered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_552
Jun 18 14:57:23 machine000 bluetoothd[1125]: Stopping SDP server
Jun 18 14:57:23 machine000 bluetoothd[1125]: Exit
Jun 18 14:57:23 machine000 systemd[1]: bluetooth.service: Deactivated successfully.
Jun 18 14:57:23 machine000 systemd[1]: Stopped Bluetooth service.
サービスを再起動
サービスを再起動します
コマンド形式
systemctl restart [サービス名]
コマンド実行例
$ sudo systemctl restart bluetooth.service
[sudo] password for user:
$ systemctl status bluetooth.service
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-06-18 14:58:43 JST; 1s ago
Docs: man:bluetoothd(8)
Main PID: 9126 (bluetoothd)
Status: "Running"
Tasks: 1 (limit: 4061)
Memory: 776.0K
CPU: 374ms
CGroup: /system.slice/bluetooth.service
└─9126 /usr/lib/bluetooth/bluetoothd
Jun 18 14:58:43 machine000 bluetoothd[9126]: Bluetooth management interface 1.21 initialized
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_453
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_453
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_512
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_512
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_552
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_552
Jun 18 14:58:44 machine000 bluetoothd[9126]: src/adv_monitor.c:btd_adv_monitor_power_down() Unexpected NULL btd_adv_monitor_manager object upon power down
サービス状態を表示
サービス状態を表示します。
コマンド形式
systemctl status [サービス名]
コマンド実行例
$ systemctl status bluetooth.service
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2024-06-17 22:56:41 JST; 15h ago
Docs: man:bluetoothd(8)
Main PID: 1125 (bluetoothd)
Status: "Running"
Tasks: 1 (limit: 4061)
Memory: 1.9M
CPU: 262ms
CGroup: /system.slice/bluetooth.service
└─1125 /usr/lib/bluetooth/bluetoothd
Jun 18 12:36:46 machine000 bluetoothd[1125]: Endpoint unregistered: sender=:1.36 path=/MediaEndpoint/A2DPSink/sbc_xq_552
Jun 18 12:36:46 machine000 bluetoothd[1125]: Endpoint unregistered: sender=:1.36 path=/MediaEndpoint/A2DPSource/sbc_xq_552
Jun 18 12:36:47 machine000 bluetoothd[1125]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc
Jun 18 12:36:47 machine000 bluetoothd[1125]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc
Jun 18 12:36:47 machine000 bluetoothd[1125]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_453
Jun 18 12:36:47 machine000 bluetoothd[1125]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_453
Jun 18 12:36:47 machine000 bluetoothd[1125]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_512
Jun 18 12:36:47 machine000 bluetoothd[1125]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_512
Jun 18 12:36:47 machine000 bluetoothd[1125]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_552
Jun 18 12:36:47 machine000 bluetoothd[1125]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_552
サービスを自動起動ありに設定
サービスを自動起動ありに設定します。
コマンド形式
systemctl enable [サービス名]
コマンド実行例
$ sudo systemctl enable bluetooth.service
[sudo] password for user:
Synchronizing state of bluetooth.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable bluetooth
$ systemctl status bluetooth.service
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-06-18 14:58:43 JST; 1min 19s ago
Docs: man:bluetoothd(8)
Main PID: 9126 (bluetoothd)
Status: "Running"
Tasks: 1 (limit: 4061)
Memory: 776.0K
CPU: 376ms
CGroup: /system.slice/bluetooth.service
└─9126 /usr/lib/bluetooth/bluetoothd
Jun 18 14:58:43 machine000 bluetoothd[9126]: Bluetooth management interface 1.21 initialized
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_453
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_453
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_512
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_512
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_552
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_552
Jun 18 14:58:44 machine000 bluetoothd[9126]: src/adv_monitor.c:btd_adv_monitor_power_down() Unexpected NULL btd_adv_monitor_manager object upon power down
サービスを自動起動なしに設定
サービスを自動起動なしに設定します。
コマンド形式
systemctl disable [サービス名]
コマンド実行例
$ sudo systemctl disable bluetooth.service
[sudo] password for user:
Synchronizing state of bluetooth.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable bluetooth
Removed /etc/systemd/system/dbus-org.bluez.service.
Removed /etc/systemd/system/bluetooth.target.wants/bluetooth.service.
$ systemctl status bluetooth.service
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2024-06-18 14:58:43 JST; 2min 20s ago
Docs: man:bluetoothd(8)
Main PID: 9126 (bluetoothd)
Status: "Running"
Tasks: 1 (limit: 4061)
Memory: 776.0K
CPU: 376ms
CGroup: /system.slice/bluetooth.service
└─9126 /usr/lib/bluetooth/bluetoothd
Jun 18 14:58:43 machine000 bluetoothd[9126]: Bluetooth management interface 1.21 initialized
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_453
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_453
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_512
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_512
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_552
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_552
Jun 18 14:58:44 machine000 bluetoothd[9126]: src/adv_monitor.c:btd_adv_monitor_power_down() Unexpected NULL btd_adv_monitor_manager object upon power down
サービスの設定ファイルを再読み込み
サービスの設定ファイルを再読み込みします。
コマンド形式
systemctl reload [サービス名]
コマンド実行例
$ sudo systemctl reload bluetooth.service
[sudo] password for user:
Failed to reload bluetooth.service: Job type reload is not applicable for unit bluetooth.service.
$ systemctl status bluetooth.service
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-06-18 14:58:43 JST; 3min 42s ago
Docs: man:bluetoothd(8)
Main PID: 9126 (bluetoothd)
Status: "Running"
Tasks: 1 (limit: 4061)
Memory: 776.0K
CPU: 376ms
CGroup: /system.slice/bluetooth.service
└─9126 /usr/lib/bluetooth/bluetoothd
Jun 18 14:58:43 machine000 bluetoothd[9126]: Bluetooth management interface 1.21 initialized
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_453
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_453
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_512
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_512
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSink/sbc_xq_552
Jun 18 14:58:43 machine000 bluetoothd[9126]: Endpoint registered: sender=:1.71 path=/MediaEndpoint/A2DPSource/sbc_xq_552
Jun 18 14:58:44 machine000 bluetoothd[9126]: src/adv_monitor.c:btd_adv_monitor_power_down() Unexpected NULL btd_adv_monitor_manager object upon power down
サービス一覧を表示
サービス一覧を表示します。
コマンド形式
systemctl list-units
コマンド実行例
$ systemctl list-units
UNIT LOAD ACTIVE SUB DESCRIPTION
proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Formats File System Automount Point
sys-devices-platform-emmc2bus-fe340000.mmc-mmc_host-mmc0-mmc0:aaaa-block-mmcblk0-mmcblk0p1.device loaded active plugged /sys/devices/platform/emmc2bus/fe340000.mmc/mmc_host/mmc0/mmc0:aaaa/block/mmcblk0/mmcblk0p1
sys-devices-platform-emmc2bus-fe340000.mmc-mmc_host-mmc0-mmc0:aaaa-block-mmcblk0-mmcblk0p2.device loaded active plugged /sys/devices/platform/emmc2bus/fe340000.mmc/mmc_host/mmc0/mmc0:aaaa/block/mmcblk0/mmcblk0p2
sys-devices-platform-emmc2bus-fe340000.mmc-mmc_host-mmc0-mmc0:aaaa-block-mmcblk0.device loaded active plugged /sys/devices/platform/emmc2bus/fe340000.mmc/mmc_host/mmc0/mmc0:aaaa/block/mmcblk0
sys-devices-platform-scb-fd580000.ethernet-net-eth0.device loaded active plugged /sys/devices/platform/scb/fd580000.ethernet/net/eth0
sys-devices-platform-soc-fe00b840.mailbox-bcm2835_audio-sound-card0-controlC0.device loaded active plugged /sys/devices/platform/soc/fe00b840.mailbox/bcm2835_audio/sound/card0/controlC0
sys-devices-platform-soc-fe201000.serial-tty-ttyAMA0-hci0.device loaded active plugged /sys/devices/platform/soc/fe201000.serial/tty/ttyAMA0/hci0
sys-devices-platform-soc-fe201000.serial-tty-ttyAMA0.device loaded active plugged /sys/devices/platform/soc/fe201000.serial/tty/ttyAMA0
sys-devices-platform-soc-fe300000.mmcnr-mmc_host-mmc1-mmc1:0001-mmc1:0001:1-net-wlan0.device loaded active plugged /sys/devices/platform/soc/fe300000.mmcnr/mmc_host/mmc1/mmc1:0001/mmc1:0001:1/net/wlan0
sys-devices-platform-soc-fe980000.usb-udc-fe980000.usb.device loaded active plugged /sys/devices/platform/soc/fe980000.usb/udc/fe980000.usb
sys-devices-platform-soc-fef00700.hdmi-sound-card1-controlC1.device loaded active plugged /sys/devices/platform/soc/fef00700.hdmi/sound/card1/controlC1
sys-devices-platform-soc-fef05700.hdmi-sound-card2-controlC2.device loaded active plugged /sys/devices/platform/soc/fef05700.hdmi/sound/card2/controlC2
sys-devices-virtual-block-loop0.device loaded active plugged /sys/devices/virtual/block/loop0
sys-devices-virtual-block-loop1.device loaded active plugged /sys/devices/virtual/block/loop1
sys-devices-virtual-block-loop10.device loaded active plugged /sys/devices/virtual/block/loop10
sys-devices-virtual-block-loop11.device loaded active plugged /sys/devices/virtual/block/loop11
sys-devices-virtual-block-loop12.device loaded active plugged /sys/devices/virtual/block/loop12
sys-devices-virtual-block-loop13.device loaded active plugged /sys/devices/virtual/block/loop13
sys-devices-virtual-block-loop14.device loaded active plugged /sys/devices/virtual/block/loop14
sys-devices-virtual-block-loop15.device loaded active plugged /sys/devices/virtual/block/loop15
sys-devices-virtual-block-loop16.device loaded active plugged /sys/devices/virtual/block/loop16
sys-devices-virtual-block-loop17.device loaded active plugged /sys/devices/virtual/block/loop17
-- 以下省略 --
まとめ
systemctlコマンドの概要と使い方を紹介しました。
systemctlコマンドは
- サービスを開始できる
- サービスを停止できる
- サービスを再起動できる
- サービスの状態確認できる
- サービスを自動起動できる
- サービスを自動起動なしにできる
- サービスの設定ファイルを再読み込みできる
- サービス一覧を確認できる
systemctlコマンドは、サービスの管理をする際に必要なコマンドです。
かなり多用するコマンドですので、覚えて実践していきましょう。