LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   systemd-tmpfiles --clean (https://www.linuxquestions.org/questions/linux-newbie-8/systemd-tmpfiles-clean-4175580237/)

scryptkiddy 05-20-2016 02:41 AM

systemd-tmpfiles --clean
 
I'm having difficulty understanding, even after reading the man pages about the systemd-tmpfiles cleanup portion of the service.
I basically want to delete all files that are in my /data/analyst directory when they are older than a certain amount of time (I haven't decided yet, but let's say 2 minutes).

Here is what I know:
I came across some good reading on the manpage for tmpfiles.d which said it would read conf files from /etc/tmpfiles.d /run/tmpfiles.d and /usr/lib/tmpfiles.d

So I figured I'd put a conf file in /etc/tmpfiles.d

Code:

#touch /etc/tmpfiles.d/new_tmpfile.conf
Based on the reading and the format I added this:
Code:

# vim /etc/tmpfiles.d/new_tmpfile.conf

D  /data/analyst - - - 2m

I waited for 2 minutes, nothing happened.
I used D because man page said that "D Create or empty a directory". I'm looking to empty a directory...

Anyway...what am I missing, and / or do I need to restart a service?

Thanks

SK

dab1414 05-20-2016 06:50 AM

Quote:

Originally Posted by scryptkiddy (Post 5548086)
I basically want to delete all files that are in my /data/analyst directory when they are older than a certain amount of time (I haven't decided yet, but let's say 2 minutes).

So why not just write a cron job to do this for you.

This one delete files older than 5 days
Code:

find /data/analyst/ -mindepth 1 -mtime +5 -delete
This one delete files older than 2 minutes
Code:

find /data/analyst/ -mindepth 1 -mmin +2 -delete
Both of those will also check sub-directories, if you want to automatically delete empty directories you can also do
Code:

find /path/to -type d -empty -delete
So in terminal
Code:

crontab -e
then editor, where your command is one of the ones i listed above.
Code:

#min hour day month weekday command
*/1  *    *    *    *    <your command>


scryptkiddy 05-20-2016 01:58 PM

Hey dab,

That's an awesome and great cron solution for sure. But I was reading on the benefits of systemd timers, and the main benefits come from each job having its own systemd service.

Here is what I found in my reading up on them:

◾ Jobs can be easily started independently of their timers. This simplifies debugging.
◾ Each job can be configured to run in a specific environment (see the systemd.exec(5) man page).
◾ Jobs can be attached to cgroups.
◾ Jobs can be set up to depend on other systemd units.
◾ Jobs are logged in the systemd journal for easy debugging.

The problem is, I just don't know how to set it up. I can't find a clear procedure from start to finish with examples and explanations. I'd really like to dive into this since its something I've never used, and learn it so I can have another 'tool in the toolbox' for my UNIX skillset =)

Any ideas?

SK

dab1414 05-20-2016 02:55 PM

Well I haven't used systemd in awhile, however lets try this post

Code:

grep -v '^#' /usr/lib/systemd/system/systemd-tmpfiles-clean.timer
Code:

grep -v '^#' /usr/lib/systemd/system/systemd-tmpfiles-clean.service
If I remember correctly it does the cleanup after boot and daily, and the first commands result should show that


EDIT: also if everything is set up right you should be able to do below to start the cleanup of tmpfiles
Code:

systemd-tmpfiles --clean

jpollard 05-21-2016 09:01 AM

Your problem is that systemd isn't quite ready for that.

The cron specification should work for you at this time. It is both simpler, and easier to control.

scryptkiddy 05-23-2016 08:06 PM

Appreciate the feedback dab and jpollard, I'll look into it more. I do agree that cron would work. However, I'm trying to develop a new skill using systemd that Red Hat has implemented.

jpollard 05-23-2016 10:03 PM

Quote:

Originally Posted by scryptkiddy (Post 5549918)
Appreciate the feedback dab and jpollard, I'll look into it more. I do agree that cron would work. However, I'm trying to develop a new skill using systemd that Red Hat has implemented.

Right now it is designed to be the init system.

In theory, it can be a session manager and I think that is what they will turn it into...

When they successfully do that, it would be the program started instead of using the startup shell script, and will respawn various Gnome services if/when they die (control panels, window managers, the auto start scripts).

Personally, I think it a waste of time, memory and system resources (systemd right now takes almost 30MB just doing that) adding yet more instances is much bigger than a shortlived shell process that turns into the window manager.

Systemd right now can handle a laptop fairly well (a relatively simple startup), but I'm not yet convinced it can actually handle really large servers --- It still seems to have trouble mounting complex filesystems, getting things done properly with network startup, has forced daemon services to use non-standard coding for them to even work (each daemon has to tell systemd when it has really started... which wasn't necessary before, and cannot monitor standard daemons). It also still has trouble getting site specific startup procedures going (it gets tricky... and if you don't get it right it can randomly not work... or not shutdown properly).

scryptkiddy 05-25-2016 01:04 PM

Good points, I'll wait until possibly RH8 when the systemd is a bit more usable / stable for things like this. Thanks for the feedback, much appreciated.

szboardstretcher 05-25-2016 01:09 PM

If you want to stay on the bleeding edge of the systemd tech then grab fedora or arch for your laptop/home system. Its fun to see where it is going and keeping up with all the changes which will eventually end up in the enterprise distros.

MadeInGermany 05-25-2016 02:51 PM

Don't wait too long! In RH8 systemd might be replaced by monsterd that consumes 500 megabytes RAM and has the desktop integrated.
Just kidding.

jpollard 05-25-2016 03:39 PM

Quote:

Originally Posted by MadeInGermany (Post 5550813)
Don't wait too long! In RH8 systemd might be replaced by monsterd that consumes 500 megabytes RAM and has the desktop integrated.
Just kidding.

;) What it will be is a single container - with systemd+gnome+utilities... and consume 2GB just to start.

szboardstretcher 05-25-2016 07:32 PM

Coming Soon: RHEL 8.0 kernelD


All times are GMT -5. The time now is 10:41 AM.