You are not logged in.
Pages: 1
dear arch experts---I have an elf64 mypgm program that I would like to have run by systemd immediately after /var is mounted. (mypgm needs to write to a file on /var/log/....)
I tried many config variations of /usr/lib/systemd/system/mypgm.service, followed by systemctl enable mygm, but none worked or gave me errors I could understand. I think this used to be easy---just put this with a low number into the low run-level.
could someone please point me to a tiny working example for such a tiny "daemon-ette" under systemd?
/iaw
Offline
Does the program have to run immediately after /var mounts? Would it be fine just to run at some point after the system has started up in general? That might be easier.
Offline
yes it does have to ran asap. the program is a file-access logger on a ro root running in RAM. I want to find out what files are accessed when. my machine is a server. I will probably want to delete files that are never accessed, both to save RAM and to remove potential places for rootkits to hide.
Offline
See 'man systemd.unit'. This directive in particular looks promising:
RequiresMountsFor=
Takes a space-separated list of absolute paths. Automatically adds dependencies of
type Requires= and After= for all mount units required to access the specified path.
Mount points marked with noauto are not mounted automatically and will be ignored for
the purposes of this option. If such a mount should be a requirement for this unit,
direct dependencies on the mount units may be added (Requires= and After= or some
other combination).
If not, I'm sure some other combination of directives will achieve what you want.
EDIT: You should put your service file in '/etc/...', not '/usr/lib/...'.
Last edited by WorMzy (2014-12-24 10:34:31)
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Offline
I would like to have run by systemd immediately after /var is mounted
You could try to create a link to your mypgm.service file in a /usr/lib/systemd/system/var.mount.wants/ directory.
I have not tested this, but you could try if it works.
Before doing this, don't forget to undo this:
I tried many config variations of /usr/lib/systemd/system/mypgm.service, followed by systemctl enable mygm
You could also post the content of the mypgm.service file.
Offline
this is how far I have come.
## tck-filelogger uses the fanotify framework to print all file-opens to /var/log/tck-filelogger.log
##
## this service file lives in /usr/lib/systemd/system/tck-filelogger.service
## to enable at next reboot: systemctl enable tck-filelogger
## to start immediately: systemctl start tck-filelogger
[Unit]
Description=tck-filelogger
After=local-fs.target
[Service]
Type=simple
ExecStart=/usr/bin/tck-filelogger
[Install]
WantedBy=basic.target
## local-fs-preset.target
this seems to work, except I need to tell the script somehow that it is not just any basic.target, but should be the first target immediately after the root-mount and the /var-mount. I think the two suggestions earlier would mean it would execute just before the /var/ mount. that's also not what I want. I hope that the After=local-fs.target does the job. It is not as specific as After=local-fs.target /,/var but these are my only two local filesystems, anyway.
is it correct that the numbers in systemctl status give me an idea of what ran when? if so, this seems to do the job. I see journald at 122, udevd at 149, my logger at 215, then dbus at 216. of course, this is guessing---it could be that on the next setup it is different if I got this wrong. or did I get this right?
/iaw
Offline
Pages: 1