项目中遇到一个问题,代码中文件被存放在/tmp/xxxx文件夹下。
但是在/tmp/xxx目录下却找不到这个文件。最后通过find 命令,发现文件实际却是被放在了/tmp/systemd-private-xxx-dmspy.service-xxx/tmp/xxx文件夹下了。
为什么会出现这种情况?
原因是我的项目是以systemd管理的守护进程方式启动的,服务名为dmspy,dmspy.service文件中配置了PrivateTmp=true。
PrivateTmp用于设置是否使用私有的tmp目录,为true表示,会使用私有的tmp目录。
PrivateTmp用于设置是否使用私有的tmp目录,为true表示,会使用私有的tmp目录。该目录会在服务启动时创建该目录,并且在关闭服务时删除该目录。
--PrivateTmp
Takes a boolean argument. If true, sets up a new file system namespace for the executed processes and mounts private /tmp/ and /var/tmp/ directories inside it that are not shared by processes outside of the namespace.This is useful to secure access to temporary files of the process, but makes sharing between processes via /tmp/ or /var/tmp/ impossible. If true, all temporary files created by a service in these directories will be removed after the service is stopped.