You are not logged in.

#1 2014-02-13 01:29:34

HalJordan
Member
Registered: 2010-11-17
Posts: 64

How do I tell systemd to monitor for a directory being removed?

I can find plenty of documentation on making it watch for the creation of a directory, but for what I intend to write I need it to watch for a certain directory being removed.

Namely, I want to watch for /usr/lib/modules/`uname -r` to be removed, and if so, move the backup copy I have created on each boot back into place. This way I can update the kernel without having to reboot, and won't have to remember to move the backup back into position each time on my own.

Barring that, is there a way to have systemd watch for a specific package to be installed? That way I can just have it run a script to take care of this any time it sees that linux-ck has been updated?

I've run search after search, but it's not giving me anything remotely relevant, aside from the documentation that tells how to do the exact opposite of what I want.

Offline

#2 2014-02-13 01:38:55

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: How do I tell systemd to monitor for a directory being removed?

Why do you want systemd to do this? How about inotify?

Offline

#3 2014-02-13 02:31:03

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: How do I tell systemd to monitor for a directory being removed?

I don't think path units are capable of doing what you want.

Instead, I suggest you do the following: edit /etc/pacman.conf. Add "IgnorePkg = linux".

Offline

#4 2014-02-13 03:29:40

YCH
Member
Registered: 2014-01-28
Posts: 53

Re: How do I tell systemd to monitor for a directory being removed?

#!/bin/sh

while true; do
    inotifywait -e modify -e create -e delete \
        /etc/nginx/sites-enabled
    nginx -s reload
done

You could write script using notify-tools and launch via systemd.


YCH

Offline

#5 2014-02-13 06:51:18

HalJordan
Member
Registered: 2010-11-17
Posts: 64

Re: How do I tell systemd to monitor for a directory being removed?

@Karol, doesn't have to be systemd, just knew it could do similar actions, and I already know how easy it is to write service files for it.

@Falconidy I'm trying to fix it so that I don't have to manually update the linux packages, and those that depend on specific versions of it every time I run updates. This is the first distro I've run across that removes kernel modules necessary for the current running kernel to function. In fact, it's the first one I've seen that doesn't keep the last working kernel on upgrades. So far that's the only real beef I have with arch, and I've been pondering ways of remedying that situation. So far without futzing with pacman, the simplest solution I've seen is to (on each boot) create a copy of the current kernel's modules as /usr/local/lib/`uname -r`-bak, then if I notice linux gets updated run 'cp /usr/local/lib/`uname -r`{-bak,}'. As far as I recon, this also needs to be done with the extramodules directory, and the kernel sources installed from linux-headers. Otherwise, a reboot is required for adding new hw(ie thumb drives) or if kde needs to be restarted.

@YCH That looks promising, but wouldn't it drive my system load and/or io up constantly? Looking at it, my original idea would to though. Guess it's back to the drawing board.

Offline

#6 2014-02-13 07:01:18

HalJordan
Member
Registered: 2010-11-17
Posts: 64

Re: How do I tell systemd to monitor for a directory being removed?

okay .. got more coffee in me, and did some digging into inotify. Since I know this should only happen once, I don't need to do a loop. Just watch for it to be deleted that first time, and execute the move command. As long as something doesn't cause the need for me to re-install the current running kernel. Can do the same thing for extramodues, and /usr/src/linux-`uname -r` ...

Now I'm just wondering if that sounds utterly mad to anyone before I actually implement it...

Offline

#7 2014-02-13 08:18:01

Awebb
Member
Registered: 2010-05-06
Posts: 6,631

Re: How do I tell systemd to monitor for a directory being removed?

If you need more than one event, you might want to look into the -m switch of inotifywait.

Offline

#8 2014-02-13 11:49:28

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 13,031

Re: How do I tell systemd to monitor for a directory being removed?

Halljordan,

make sure you write something to regularly remove older copies of the modules you put back, else the partition that holds /usr/lib may fill up very fast.

Last edited by Lone_Wolf (2014-02-13 11:50:01)


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#9 2014-02-13 16:05:33

YCH
Member
Registered: 2014-01-28
Posts: 53

Re: How do I tell systemd to monitor for a directory being removed?

inotifywait is just waiting till the event. There is no overhead during wait event. If you should monitor filesystem changes in linux, libnotify is the right way. while loop is just do that monitoring again when the event occur.

Just watch for it to be deleted that first time, and execute the move command.

That is exactly the job of inotify.


YCH

Offline

#10 2014-02-13 16:24:20

Awebb
Member
Registered: 2010-05-06
Posts: 6,631

Re: How do I tell systemd to monitor for a directory being removed?

Offline

#11 2014-02-13 16:31:03

YCH
Member
Registered: 2014-01-28
Posts: 53

Re: How do I tell systemd to monitor for a directory being removed?


YCH

Offline

#12 2014-02-13 20:02:09

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: How do I tell systemd to monitor for a directory being removed?

HalJordan wrote:

okay .. got more coffee in me, and did some digging into inotify. Since I know this should only happen once, I don't need to do a loop. Just watch for it to be deleted that first time, and execute the move command. As long as something doesn't cause the need for me to re-install the current running kernel. Can do the same thing for extramodues, and /usr/src/linux-`uname -r` ...

Now I'm just wondering if that sounds utterly mad to anyone before I actually implement it...

Yes, it sounds mad. Don't update the kernel if you don't want to reboot. Hacking around it by creating untracked files rather than changing your behavior seems insane.

Offline

Board footer

Powered by FluxBB