Custom /var/run/directory doesn't exist after reboot

Hi,

I create a custom directory intending to use it for a particular software:


# mkdir /var/run/directory

but after reboot:


ls: cannot access '/var/run/directory': No such file or directory

Why is this happening (and how to fix it)?

“/var/run” uses “tmpfs” and is expected to be relevant only to the current run (i.e. since the last boot). So anything put there will disappear on reboot.

Usual method to create files in /run during boot is to use tmpfiles; see “man tmpfiles.d”.

Thank you!

And I hope the OP understands then that it is created fresh at boot. Thus your application may not expect to find there any data it left ther before the shutdown of the system.

Sure. I am just building a program from source and I have an option in the config to sepecify a PID directory. I thought the proper way would be to use its own subdirectory but perhaps it would be easiest to simply let it use /var/run itself (which is the default option anyway, not sure if that has any cons compared to subdirectory).

I think /var/run is fine as long as you try to make a unique file name. Thus not just pid, bit something with the name of the product/executable in it.

Thanks. Well, I don’t make the name, the program does create 3 separate files for its 3 services, each one named after the service. I suppose it should work.

I agree, IMHO the application builders choose a correct default place for it.