首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >/tmp下的Linux +文件和文件夹清理

/tmp下的Linux +文件和文件夹清理
EN

Unix & Linux用户
提问于 2018-12-19 15:04:08
回答 2查看 4K关注 0票数 4

在我所有的Red机器上,7.2版我们看到了systemd-tmpfiles-lean.service是不活动的:

代码语言:javascript
复制
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) since Wed 2018-12-19 14:47:14 UTC; 12min ago
     Docs: man:tmpfiles.d(5)
           man:systemd-tmpfiles(8)
  Process: 34231 ExecStart=/usr/bin/systemd-tmpfiles --clean (code=exited, status=0/SUCCESS)
 Main PID: 34231 (code=exited, status=0/SUCCESS)

Dec 19 14:47:14 master02.uridns.com systemd[1]: Starting Cleanup of Temporary Directories...
Dec 19 14:47:14 master02.uridns.com systemd[1]: Started Cleanup of Temporary Directories.

奇怪的是,我们在/tmp下看到了文件和文件夹,似乎每隔一段时间就会执行一次清理。

我搜索crontab或cronjob,但没有找到其他清理工作。

我是不是漏掉了什么?

是否有可能,尽管服务是不活动的,清理工作每隔几周进行一次?

代码语言:javascript
复制
  systemctl enable  systemd-tmpfiles-clean.service

The unit files have no [Install] section. They are not meant to be enabled
using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
   .wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
   a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
   D-Bus, udev, scripted systemctl call, ...).

我们还看到了一些非常旧的文件夹,如

代码语言:javascript
复制
ls -ltr
total 137452
drwxr-xr-x 3 root      root         33 Jun 13  2017 Tools
drwx--x--x 3 root      root         16 Oct 12 09:33 systemd-private-74982d8a24254a1d8b8ec3b5c0d80a9b-httpd.service-QZqGLA
drwx--x--x 3 root      root         16 Oct 12 10:02 systemd-private-74982d8a24254a1d8b8ec3b5c0d80a9b-rtkit-daemon.service-BTcGY1
drwx--x--x 3 root      root         16 Oct 12 10:02 systemd-private-74982d8a24254a1d8b8ec3b5c0d80a9b-vmtoolsd.service-mQ1SXc
drwxr-xr-x 2 ambari    ambari       18 Oct 12 12:02 hsperfdata_ambari
drwx--x--x 3 root      root         16 Oct 12 12:17 systemd-private-74982d8a24254a1d8b8ec3b5c0d80a9b-cups.service-PnKaq8
drwx--x--x 3 root      root         16 Oct 12 12:17 systemd-private-74982d8a24254a1d8b8ec3b5c0d80a9b-colord.service-DNn470
-rwxr-xr-x 1 root      root      83044 Nov 18 17:27 Spark_Thrift.log
drwxr-xr-x 2 zookeeper hadoop       18 Nov 18 17:28 hsperfdata_zookeeper
-rwxr-xr-x 1 root      root        379 Nov 18 17:37 requests.txt
-rwxr-xr-x 1 root      root     137348 Nov 22 14:50 pp
-rwxr-xr-x 1 root      root        344 Nov 26 15:24 yy
prwx--x--x 1 root      root          0 Nov 29 21:26 hogsuspend
-rwxr-xr-x 1 root      root       1032 Dec  3 10:55 aa

从我的机器上:

代码语言:javascript
复制
more /lib/systemd/system/systemd-tmpfiles-clean.timer
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Daily Cleanup of Temporary Directories
Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)

[Timer]
OnBootSec=15min
OnUnitActiveSec=1d

规则是:

代码语言:javascript
复制
more /usr/lib/tmpfiles.d/tmp.conf
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# See tmpfiles.d(5) for details

# Clear tmp directories separately, to make them easier to override
v /tmp 1777 root root 10d
v /var/tmp 1777 root root 30d

# Exclude namespace mountpoints created with PrivateTmp=yes
x /tmp/systemd-private-%b-*
X /tmp/systemd-private-%b-*/tmp
x /var/tmp/systemd-private-%b-*
X /var/tmp/systemd-private-%b-*/tmp
EN

回答 2

Unix & Linux用户

回答已采纳

发布于 2018-12-19 15:24:28

您可以问systemd一个单元的触发器是什么:

代码语言:javascript
复制
systemctl show -p TriggeredBy systemd-tmpfiles-clean

这将显示systemd-tmpfiles-clean服务是由systemd-tmpfiles-clean.timer计时器触发的。定义为

代码语言:javascript
复制
#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Daily Cleanup of Temporary Directories
Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)

[Timer]
OnBootSec=15min
OnUnitActiveSec=1d

因此,该服务每天运行,并根据tmpfiles.d配置清理目录。有关详细信息,请参阅相关的手册页。

票数 13
EN

Unix & Linux用户

发布于 2018-12-19 15:24:28

systemd-tmpfiles-clean.service是由systemd-tmpfiles-clean.timer发起的。您可以使用systemctl list-timers检查计时器。

至少在Ubuntu16.04上,systemd-tmpfiles-clean.timer被定义为

代码语言:javascript
复制
# Use `systemctl cat systemd-tmpfiles-clean.timer` to get your corresponding file
#
# /lib/systemd/system/systemd-tmpfiles-clean.timer
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
[Unit]
Description=Daily Cleanup of Temporary Directories
Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)

[Timer]
OnBootSec=15min
OnUnitActiveSec=1d

因此,计时器将在启动后15分钟启动systemd-tmpfiles-clean.service,之后每24小时启动一次。

有关更多信息,请参见systemd.timer(5)systemd.service(5)systemd.unit(5)

票数 6
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/489940

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档