tmpfiles.dのファイル破砕

tmpfiles.dのファイル破砕

tmpfiles.dを検索した後、ファイル/ディレクトリの削除オプションが制限されているようです。 shredなどのコマンドを使用して一時ディレクトリを完全に削除したいと思います。 tmpfiles.d設定でスクリプトをトリガーする方法、またはtmpクリーンアップ中にshredを使用する隠しメカニズムはありますか?

ベストアンサー1

はい!systemd-tmpfiles --removeまたは、で構成されたディレクトリのすべての内容、またはDR構成されたすべてのファイルまたはディレクトリを削除するために呼び出されます。rR

からman systemd-tmpfiles

   --remove
       If this option is passed, the contents of directories marked with D or R,
       and files or directories themselves marked with r or R are removed.

わずかに侵害が少ないため、プレフィックスで始まるディレクトリでのみフィルタリングできます。

   --prefix=path
       Only apply rules with paths that start with the specified prefix. This option
       can be specified multiple times.

   --exclude-prefix=path
       Ignore rules with paths that start with the specified prefix. This option
       can be specified multiple times.

または、より頻繁に清掃することもできます。 --clean有効期限が切れた(使用期間が過ぎた)一時ファイルのみが削除されます。次の例で実行すると、前のすべての項目がsystemd-tmpfiles --clean削除されます。/run/screens10d

# /usr/lib/tmpfiles.d/screen.conf
# Type  Path           Mode   User   Group    Age    Argument
  d     /run/screens   1777   root   screen   10d    -

これはすでに次のように毎日確認されていますsystemd-tmpfiles-clean.timer

$ systemctl cat systemd-tmpfiles-clean.{timer,service}
[Unit]
Description=Daily Cleanup of Temporary Directories
Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)

[Timer]
OnBootSec=15min
OnUnitActiveSec=1d

# /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=local-fs.target time-set.target
Before=shutdown.target

[Service]
Type=oneshot
ExecStart=systemd-tmpfiles --clean
SuccessExitStatus=DATAERR
IOSchedulingClass=idle

それが十分に根本的でない場合は、次のことができます。

d /my/path 0755 user group  1h -

OnUnitActiveSec=1hそして、タイマー挿入を作成します。

または、サービスを実行している場合は、サンドボックスオプションを確認してくださいman systemd.execPrivateTmp=RemoveIPC=などの項目DynamicUser=は、必要なくなったら削除できます。

おすすめ記事