unit: The $runstatedir is not being created at runtime

See the following configuration. I used a prefix of /opt/local/unit to make sure there were no previous existing directories or stuff that was left by a previous unit installation, and so that I can wipe it easily, but this could perfectly use system paths.

The issue is that the system is allowed (and will normally do so) to wipe /run (or /var/run) at [re]boot time. Since we use various files in /run (at least, the pid file and the control socket), the FHS says that we should use a directory within /run:

https://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.html#runRuntimeVariableData

Programs may have a subdirectory of /run; this is encouraged for programs that use more than one run-time file.

alx@asus5775:~/src/nginx/unit$ ./configure --prefix=/opt/local/unit \
                                           --modules=/opt/local/unit/lib/unit/modules \
                                           --state=/opt/local/unit/var/lib/unit \
                                           --pid=/opt/local/unit/var/run/unit/unit.pid \
                                           --log=/opt/local/unit/var/log/unit/unit.log \
                                           --control=unix:/opt/local/unit/var/run/unit/control.unit.sock \
                               | tail -n 27
Unit configuration summary:

  bin directory: ............. "/opt/local/unit/bin"
  sbin directory: ............ "/opt/local/unit/sbin"
  lib directory: ............. "/opt/local/unit/lib"
  include directory: ......... "/opt/local/unit/include"
  man pages directory: ....... "/opt/local/unit/share/man"
  modules directory: ......... "/opt/local/unit/lib/unit/modules"
  state directory: ........... "/opt/local/unit/var/lib/unit"
  tmp directory: ............. "/opt/local/unit/tmp"

  pid file: .................. "/opt/local/unit/var/run/unit/unit.pid"
  log file: .................. "/opt/local/unit/var/log/unit/unit.log"

  control API socket: ........ "unix:/opt/local/unit/var/run/unit/control.unit.sock"

  non-privileged user: ....... "nobody"
  non-privileged group: ...... ""

  IPv6 support: .............. YES
  Unix domain sockets support: YES
  TLS support: ............... NO

  process isolation: ......... USER NS PID NET UTS CGROUP

  debug logging: ............. NO

alx@asus5775:~/src/nginx/unit$ make -j >/dev/null; echo $?
0
alx@asus5775:~/src/nginx/unit$ sudo make install
install -d /opt/local/unit/sbin
install -p build/unitd /opt/local/unit/sbin/
install -d /opt/local/unit/var/lib/unit
install -d /opt/local/unit/share/man/man8
install -p -m644 build/unitd.8 /opt/local/unit/share/man/man8/
alx@asus5775:~/src/nginx/unit$ sudo /opt/local/unit/sbin/unitd 
2022/08/05 20:12:22 [alert] 21613#21613 bind(6, unix:/opt/local/unit/var/run/unit/control.unit.sock.tmp) failed (2: No such file or directory)

unitd fails to create the socket (because it assumes the parent dir exists always), and exits.

unitd should create the parent directory previous to attempting to bind(2) the socket.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 18 (16 by maintainers)

Commits related to this issue

Most upvoted comments

No, I think the code is fine as proposed in your patch. I just wanted to make sure that the obvious expected behavior was indeed occuring, which it is (per your ls(1) runs). So LGTM. 😃