Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
107
rated 0 times [  107] [ 0]  / answers: 1 / hits: 88186  / 2 Years ago, sun, january 9, 2022, 6:58:17

In recent ubuntus (specifically, what interests me the most is 12.04) /var/run is tmpfs, and thus I assume it starts empty with each reboot.



Yet, I see there some folders, like /var/run/mysqld and numerous others. How those folders created on each reboot? Is there some template folder which copied to /var/run/ (and if so, which script does that), or each folder mkdir'ed separately, or what ?



EDIT:

Please, do not answer that /var/run is persistent, or that /run is persistent. Because it is NOT.



Even if it is so on your system, it is not so on a regular 12.04.


More From » boot

 Answers
2

(Thanks to @Zulakis and an answer on Serverfault for pointing out that this answer had not kept up with Ubuntu's ongoing development.)



With the adoption of systemd as of 15.04, there is now a centralized mechanism for the creation of temporary files and directories such as these. A service wishing to use this method can remove mkdir commands in its own startup script and instead place a .conf file in /etc/tmpfiles.d, /run/tmpfiles.d, or /usr/lib/tmpfiles.d, with Ubuntu services seeming to prefer the last option. For example, my system now has:



$ egrep -r /var/run /usr/lib/tmpfiles.d

/usr/lib/tmpfiles.d/var.conf:L /var/run - - - - ../run
/usr/lib/tmpfiles.d/sudo.conf:d /var/run/sudo 0711 root root
/usr/lib/tmpfiles.d/sudo.conf:D /var/run/sudo/ts 0700 root root
/usr/lib/tmpfiles.d/postgresql.conf:d /var/run/postgresql 2775 postgres postgres - -
/usr/lib/tmpfiles.d/sshd.conf:d /var/run/sshd 0755 root root
/usr/lib/tmpfiles.d/screen-cleanup.conf:d /var/run/screen 0775 root utmp


The d means to create a directory if it doesn't already exist, after that is the path, and the rest are the permissions, user, and group. These directories will be created regardless of whether the corresponding service is ever started.



For full documentation, see man tmpfiles.d.






OLD PRE-SYSTEMD ANSWER:



Looks like they're created dynamically by individual services as they start:



$ sudo egrep -r 'mkdir.*/var/run' /etc

/etc/init.d/ssh: mkdir /var/run/sshd
/etc/init.d/bind9: mkdir -p /var/run/named
/etc/init.d/timidity: mkdir -p /var/run/timidity
/etc/init.d/bzflag: mkdir -p /var/run/bzflag
/etc/init.d/dns-clean:mkdir /var/run/pppconfig >/dev/null 2>&1 || true
/etc/init/winbind.conf: mkdir -p /var/run/samba/winbindd_privileged
/etc/init/dbus.conf: mkdir -p /var/run/dbus
/etc/init/ssh.conf: mkdir -p -m0755 /var/run/sshd
/etc/init/libvirt-bin.conf: mkdir -p /var/run/libvirt
/etc/init/cups.conf: mkdir -p /var/run/cups/certs


I believe this is the one that handles mysqld:



[ -d /var/run/mysqld ] || install -m 755 -o mysql -g root -d /var/run/mysqld
/lib/init/apparmor-profile-load usr.sbin.mysqld


man install says that the -d form will "create all components of the specified directories".


[#30914] Monday, January 10, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
egantfis

Total Points: 406
Total Questions: 108
Total Answers: 108

Location: Austria
Member since Thu, Jan 7, 2021
3 Years ago
egantfis questions
Mon, Nov 1, 21, 03:37, 3 Years ago
Fri, Mar 18, 22, 23:26, 2 Years ago
Mon, Mar 6, 23, 05:03, 1 Year ago
Sun, Oct 3, 21, 23:30, 3 Years ago
Thu, Mar 10, 22, 12:28, 2 Years ago
;