在 15.04 中使用 systemd 保留 /tmp 中的文件

在 15.04 中使用 systemd 保留 /tmp 中的文件

如果可能的话,我希望在启动时保留 /tmp/foo/*。我尝试配置 tmpfiles.d,但没有成功。我以 root 身份创建了以下/etc/tmpfiles.d/foo.conf内容:

x /tmp/foo/*

异或

X /tmp/foo - - - - -

异或

x /tmp/foo - - - - -

这些编辑均不起作用。

根据man tmpfiles.dx 代表“在清理过程中忽略路径”,这正是我想要做的。在该手册页中甚至有一个关于如何实现这一点的示例 (#2)。

但是,重启后,/tmp/foo 总是丢失。我做错了什么?在 15.04 中,tmpfiles.d 是实现此目的的方法吗?

答案1

你需要这个:

x /tmp/foo - - - - -

但请注意:

Note that lines of this type do not influence the effect of r or R lines. 

手册页:

r

Remove a file or directory if it exists. This may not be used to 
remove non-empty directories, use R for that. Lines of this type 
accept shell-style globs in place of normal path names. Does not 
follow symlinks.

R

Recursively remove a path and all its subdirectories (if it is a 
directory). Lines of this type accept shell-style globs in place of 
normal path names. Does not follow symlinks.



x

Ignore a path during cleaning. Use this type to exclude paths from 
clean-up as controlled with the Age parameter. Note that lines of this 
type do not influence the effect of r or R lines. Lines of this type 
accept shell-style globs in place of normal path names.

The configuration format is one line per path containing type, path, 
mode, ownership, age, and argument fields:

     #Type Path        Mode UID  GID  Age Argument
     d    /run/user   0755 root root 10d -
     L    /tmp/foobar -    -    -    -   /dev/null

Fields may be enclosed within quotes and contain C-style escapes.

来源

相关内容