RHEL7から採用されたsystemdですが、機能が豊富すぎてよくわかっていません。
とりあえずtmpファイルを消すsystemd-tmpfiles-clean.service
を止める方法を記載します。
忙しい方向け(すぐに止めたい)
とりあえず止めたい場合は、下記のコマンドを実行してください。
# 今動いているtimerを止める
systemctl stop systemd-tmpfiles-clean.timer
# 起動時にtimerが起動しないようにする
systemctl mask systemd-tmpfiles-clean.timer
timerとか、maskとかいきなり出ていますが、興味がある方は下記へ
systemdのserviceとかtimerとか
よくわかっていません。とりあえず調べた範囲だけ書きます。
- service
- systemdで動かしたいコマンドの実態
.service
という拡張子(と言っていいのかな..)のファイル
- timer
.service
で作成したserviceを動かすタイマー
- ここに起動する時間などを記載する
- つまりserviceで定義した内容をcron的に動かしたい場合に定義する
.timer
という拡張子(と言っていいのかな..のファイル
- serviceと同じ名前で、
.timer
にすると自動で認識される
tmpfileを消すserviceの中身
service, timerをざっくりと説明しましたが、tpmfileを消すserviceの中身を見てみます。
- systemd-tmpfiles-clean.serviceの中身 (コメントは削除)
[vagrant@node1 ~]$ cat /usr/lib/systemd/system/systemd-tmpfiles-clean.service
[Unit]
Description=Cleanup of Temporary Directories
Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)
DefaultDependencies=no
Conflicts=shutdown.target
After=systemd-readahead-collect.service systemd-readahead-replay.service local-fs.target time-sync.target
Before=shutdown.target
[Service]
Type=oneshot
ExecStart=/usr/bin/systemd-tmpfiles --clean
IOSchedulingClass=idle
Unitとか、Serviceとかありますが、これはセクションと呼ばれるもので、[Service]セクションのExcecStart
に記載されている内容が、実行される内容です。
ここでは/usr/bin/systemd-tmpfiles --clean
ですね。
- systemd-tmpfiles-clean.timerの中身
[vagrant@node1 ~]$ cat /usr/lib/systemd/system/systemd-tmpfiles-clean.timer
[Unit]
Description=Daily Cleanup of Temporary Directories
Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)
[Timer]
OnBootSec=15min
OnUnitActiveSec=1d
Timerセクションに記載されているところが、Timerの実態です。OnBootSec
は、起動後15分で、OnUnitActiveSec
は、serviceの起動間隔です。
サービスを止める
まずは上記のそれぞれが、どんなstatusなのかを見てみます。
[vagrant@node1 ~]$ systemctl status systemd-tmpfiles-clean.service
● systemd-tmpfiles-clean.service - Cleanup of Temporary Directories
Loaded: loaded (/usr/lib/systemd/system/systemd-tmpfiles-clean.service; static; vendor preset: disabled)
Active: inactive (dead)
Docs: man:tmpfiles.d(5)
man:systemd-tmpfiles(8)
[vagrant@node1 ~]$ systemctl status systemd-tmpfiles-clean.timer
● systemd-tmpfiles-clean.timer - Daily Cleanup of Temporary Directories
Loaded: loaded (/usr/lib/systemd/system/systemd-tmpfiles-clean.timer; static; vendor preset: disabled)
Active: active (waiting) since 水 2016-08-24 03:54:23 BST; 7min ago
Docs: man:tmpfiles.d(5)
man:systemd-tmpfiles(8)
serviceのほうはinactive
になっていて、timerがactive
になっているので、このserviceはあくまでtimerによって起動されるものであることがわかります。
なので、timerをdisableにすれば止まる、と思いきや、systemd-tmpfiles-clean.timer
は起動時onをoffにできません。
いくつかのsystemdのコマンドを扱ったブログでは、とにかくdisable
で止めていますが、これで止まるものと止まらないものがあります。
disableで止まるもの・止まらないもの
それぞれのserviceのSTATE
を見ると、disableで起動時offができるかどうかがわかります。
[vagrant@node1 ~]$ systemctl list-unit-files -t service postfix.service
UNIT FILE STATE
postfix.service enabled
これはdisableできます。では、systemd-tmpfiles-cleanは..?
(timerはserviceに依存するので、本当はserviceだけ見ればよいですが、一応)
[vagrant@node1 ~]$ systemctl list-unit-files -t service systemd-tmpfiles-clean.service
UNIT FILE STATE
systemd-tmpfiles-clean.service static
1 unit files listed.
[vagrant@node1 ~]$ systemctl list-unit-files -t timer systemd-tmpfiles-clean.timer
UNIT FILE STATE
systemd-tmpfiles-clean.timer static
static
になっていますね。で、このstatic
とはman systemctl
で見てみると、Table 1. is-enabled output
に (systemctl is-enabled ユニット名
でも、上記のSTATE
は見れます)
Unit file is not enabled, and has no provisions for enabling in the "[Install]" section.
と記載されています。つまり、static
の場合は、enableとかの管轄外なんですね。
で、もう一度systemd-tmpfiles-clean.serviceを見てみると、あれ?[Install] sectionがありません。
[vagrant@node1 ~]$ cat /usr/lib/systemd/system/systemd-tmpfiles-clean.service
[Unit]
Description=Cleanup of Temporary Directories
Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)
DefaultDependencies=no
Conflicts=shutdown.target
After=systemd-readahead-collect.service systemd-readahead-replay.service local-fs.target time-sync.target
Before=shutdown.target
[Service]
Type=oneshot
ExecStart=/usr/bin/systemd-tmpfiles --clean
IOSchedulingClass=idle
ではどこに?
After
とあるので、このユニットはいくつかのユニットに依存しています。
で、systemd-readahead-collect.service
を見てみると
[vagrant@node1 ~]$ cat /usr/lib/systemd/system/systemd-readahead-collect.service
[Unit]
Description=Collect Read-Ahead Data
Documentation=man:systemd-readahead-replay.service(8)
DefaultDependencies=no
Wants=systemd-readahead-done.timer
Conflicts=shutdown.target
Before=sysinit.target shutdown.target
ConditionPathExists=!/run/systemd/readahead/cancel
ConditionPathExists=!/run/systemd/readahead/done
ConditionVirtualization=no
[Service]
Type=notify
ExecStart=/usr/lib/systemd/systemd-readahead collect
RemainAfterExit=yes
StandardOutput=null
OOMScoreAdjust=1000
[Install]
WantedBy=default.target
Also=systemd-readahead-drop.service
[Install]セクションがありますね。
ということで、
systemd-readahead-collect.service
は[Install]セクションで記載されたtargetのタイミングでのみ起動する
- これに依存している
systemd-tmpfiles-clean.service
もstatic扱いになる
- それのtimerもstaticになるので、disable(enableも)の管轄外
- maskでoffにする
ということになります。
参考:http://equj65.net/tech/systemd-manage/