64
51

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

systemdでサービスの状態、設定、ログを見る方法を調べてみたのでメモ

Last updated at Posted at 2014-04-13

Vagrant上のCoreOSでetcdを動かして別の3台でクラスタリングしてみた - Qiitaでハマったのでサービスの状態を見てみようと思ったら、systemdについて何も知らない事に気づいたので少しだけ調べました。

状態の確認

systemctlというコマンドでサービスの確認などを行うらしいです。systemd (日本語) - ArchWikiが詳しくて良さそうです。

systemctl status サービス名 -lで状態を確認します。-lなしだと下半分ぐらいのログの行が...で省略されて、フルで見るには-lを付けるように言われました。

core@core-00 ~ $ systemctl status etcd -l
etcd.service - etcd
   Loaded: loaded (/usr/lib64/systemd/system/etcd.service; disabled)
  Drop-In: /run/systemd/system/etcd.service.d
           └─20-cloudinit.conf
   Active: active (running) since Sun 2014-04-13 05:55:20 UTC; 29min ago
 Main PID: 3051 (etcd)
   CGroup: /system.slice/etcd.service
           └─3051 /usr/bin/etcd

Apr 13 05:55:20 core-00 systemd[1]: Starting etcd...
Apr 13 05:55:20 core-00 systemd[1]: Started etcd.
Apr 13 05:55:20 core-00 etcd[3051]: [etcd] Apr 13 05:55:20.821 INFO      | e91e07624f254be3835aa6b221f4e176: state changed from 'stopped' to 'follower'.
Apr 13 05:55:20 core-00 etcd[3051]: [etcd] Apr 13 05:55:20.821 INFO      | e91e07624f254be3835aa6b221f4e176: state changed from 'follower' to 'leader'.
Apr 13 05:55:20 core-00 etcd[3051]: [etcd] Apr 13 05:55:20.822 INFO      | e91e07624f254be3835aa6b221f4e176: leader changed from '' to 'e91e07624f254be3835aa6b221f4e176'.
Apr 13 05:55:20 core-00 etcd[3051]: [etcd] Apr 13 05:55:20.823 INFO      | etcd server [name e91e07624f254be3835aa6b221f4e176, listen on [::]:4001, advertised url http://172.12.8.100:4001]
Apr 13 05:55:20 core-00 etcd[3051]: [etcd] Apr 13 05:55:20.824 INFO      | peer server [name e91e07624f254be3835aa6b221f4e176, listen on [::]:7001, advertised url http://172.12.8.100:7001]

設定の確認

systemctl statusの出力結果で設定ファイルがわかるので、それを見ます。

core@core-01 ~ $ cat /run/systemd/system/etcd.service.d/20-cloudinit.conf
[Service]
Environment="ETCD_DISCOVERY=http://172.17.8.100:4001/v2/keys/machines"
Environment="ETCD_ADDR=172.17.8.101:4001"
Environment="ETCD_PEER_ADDR=172.17.8.101:7001"
Environment="ETCD_NAME=3e15b02dcddc4a079c04d7fa9c91b621"

ログの確認

φ(.. )メモシテオコウ systemdのjournalによるログの確認方法 - φ(・・*)ゞ ウーン カーネルとか弄ったりのメモによるとsystemdでは/var/log/messagesは作られず、ログの確認にはjournalctlコマンドを使うそうです。-bをつければブート以後のログのみが見られるとのこと。

実行例

journalctl -b | less

出力抜粋

Apr 13 05:56:43 core-01 etcd[3055]: [etcd] Apr 13 05:56:43.514 INFO      | Discovery via http://172.17.8.100:4001 using prefix machines.
Apr 13 05:56:44 core-01 tlsdated[2891]: wait for child attempt 1
Apr 13 05:56:44 core-01 tlsdated[2891]: child exited with 0
Apr 13 05:56:44 core-01 tlsdated[2891]: tlsdate succeeded
Apr 13 05:56:44 core-01 tlsdated[2891]: synced rtc to sysclock
Apr 13 05:56:44 core-01 tlsdated[2891]: open failed: No such file or directory
Apr 13 05:56:44 core-01 tlsdated[2891]: wait for child attempt 1
Apr 13 05:56:44 core-01 tlsdated[2891]: child exited with 0
Apr 13 05:56:44 core-01 tlsdated[2891]: tlsdate succeeded
Apr 13 05:56:44 core-01 tlsdated[2891]: synced rtc to sysclock
Apr 13 05:56:44 core-01 tlsdated[2891]: open failed: No such file or directory
Apr 13 05:56:44 core-01 tlsdated[2891]: Failed to obtain UID for `tlsdate-dbus'
Apr 13 05:56:45 core-01 etcd[3055]: [etcd] Apr 13 05:56:45.924 CRITICAL  | Discovery failed and a backup peer list wasn't provided: 501: All the given peers are not reachable (Tried to connect to each peer twice and failed) [0]
Apr 13 05:56:45 core-01 systemd[1]: etcd.service: main process exited, code=exited, status=1/FAILURE
Apr 13 05:56:45 core-01 systemd[1]: Unit etcd.service entered failed state.
64
51
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
64
51

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?