2

I've got a tmpfs mounted to /var/something/else and I'd like to copy files to the location immediately after it's mounted. So if I run (or action executed after server reboot):

mount /var/something/else
  1. mounted
  2. files synced from hdd to tmpfs
  3. a daemon started

and it would be great if I run

umount /var/something/else
  1. daemon stopped
  2. files synced from tmpfs to hdd
  3. unmounted

Yes, it's possible to modify init/systemd script of the daemon to do all the required (mount/umount/sync). But is there another option?

The rules in /etc/udev/rules.d/ does not seem to work here...if I get it right.

Regards, Alex.

Alex
  • 75
  • 6
  • 3
    Use a standard systemd unit (service), if you have systemd. There are plenty of examples online. No can do with udev, it works much before a mount occurs. – kubanczyk Nov 16 '16 at 18:10
  • While searching in internet I've came across an idea that you can write custom rules in `/etc/udev/rules.d/` for USB drive, so that a system will detect attached drive and start a custom script if it's written so in such a rule. That's why I mentioned `udev` here. – Alex Nov 17 '16 at 02:38
  • You're probably best writing a shell script to do the mount+sync+daemon start, and a separate script to handle the unmount, then writing an initscript/systemd unit file to call the scripts at boot and shutdown. You'd control the mount via that initscript. – Joshua Boniface Feb 08 '17 at 02:57

0 Answers0