27

I keep my sphinx pid in /var/run/sphinx/searchd.pid but every time I hard reboot the directory /var/run/sphinx disappears and sphinx fails to start. Is there a way to make that directory stick or have it automatically created? How do people usually handle this situation? I use Ubuntu Hardy

4 Answers4

24

That directory is ephemeral by design. If its contents stuck around across boots, all sorts of ugly effects could occur, as control scripts of various sorts look in there to see what processes they should be signaling. On recent system, this temporary nature is enforced by mounting /var/run as tmpfs, while older systems just deleted everything in the directory at startup.

Therefore, you need to configure Sphinx or its startup script to create that directory, or just write the PID file in /var/run directly.

Phil Miller
  • 1,725
  • 1
  • 11
  • 17
  • 4
    +1 for description of /var/run. But note that he doesn't want the PID file to be persistent across a reboot; just the sphinx directory. – Steve Folly Oct 15 '09 at 15:30
  • I came across this thread looking for a solution for centos 7. I am using Systemd to run a program which needs a folder in `/var/run`, but when I manually created it, it got deleted after a reboot. Systemd (I think) has a tool to help create temporary folders in `/var/run` with a conf file like so: `/run/tmpfiles.d/my_temp_folder.conf`. I am not sure if tmpfiles.d is just for Systemd or not, but I thought this comment might be helpful for someone stumbling onto this thread like I did. – Shmack Jun 27 '22 at 17:43
15

You have two chances at least:

  • change your init script to do a mkdir -p /var/run/sphinx/

or

  • set pid_file = /var/run/sphinx-searchd.pid in /etc/sphinx.conf

I'm for the second one.

drAlberT
  • 10,871
  • 7
  • 38
  • 52
  • 2
    And of course this means the startup script must run as root to be able to write directly to or create a directory in /var/run. Which is annoying... – Eloff Oct 26 '12 at 17:40
  • I chose the second solution as well. It looks like there is precedence for this (cron, ssh, atd, syslog). – BillMan May 30 '13 at 13:39
12

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 your case create a file /usr/lib/tmpfiles.d/sphinx.conf.
the content of the file would be:
d /var/run/sphinx 0755 root root

here d stands for directory, next to it is the path, permission, owner and group.
This will create the /var/run/sphnix directory on reboot.

Checkout the full documentation tmpfiles.d

Aakash Singhal
  • 121
  • 1
  • 5
2

If using systemd, there is a configuration item explicitly for this.

http://manpages.ubuntu.com/manpages/xenial/en/man5/systemd.exec.5.html

[Service]
RuntimeDirectory=sphinx

If set, one or more directories by the specified names will be created below /run, and will be owned by the user and group specified in User= and Group=

s01ipsist
  • 121
  • 2