Directory for PHP 5 FPM socket files is deleted after reboot on Ubuntu Server

Current version of Ubuntu is using so-called up-start configs to run services. More info about this can be found here.

All up-start scripts are located in the /etc/init directory. Do not confuse it with old init scripts in /etc/init.d directory.

As @Rhim stated in his answer, /var/run is a temporary mounted filesystem, that is re-created after each reboot, so changes are not persisted in it. So in order to have a custom directory for socket files you will have to create it every time. The best place to add such functionality is an upstart config for PHP FPM located in: /etc/init/php5-fpm.conf.

Here's the modified version of this config:

# php5-fpm - The PHP FastCGI Process Manager

description "The PHP FastCGI Process Manager"
author "Ondřej Surý <[email protected]>"

start on runlevel [2345]
stop on runlevel [016]

# Precise upstart does not support reload signal, and thus rejects the
# job. We'd rather start the daemon, instead of forcing users to
# reboot https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1272788
#
# reload signal USR2

pre-start script
    mkdir -p /var/run/php-fpm
    /usr/lib/php5/php5-fpm-checkconf
end script

respawn
exec /usr/sbin/php5-fpm --nodaemonize --fpm-config /etc/php5/fpm/php-fpm.conf

pre-start stanza was already used to check PHP FPM configuration file so I've converted it to a script section and added my own command for creating the direcotry for socket files before calling the checkconf.

With this script it should work fine. In order to control state of the service use the service command like this: service php5-fpm start, service php5-fpm restart etc.

I hope it will help someone. Cheers!


I think that in Ubuntu also!

cat /etc/redhat-release 
Fedora release 20 (Heisenbug)

df -h /run
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           3.9G  904K  3.9G   1% /run

ls -la /var | grep run 
lrwxrwxrwx.   1 root root      6 Dec 28  2013 run -> ../run

This directory is mounted as tmpfs.

Add to a startup script, create a directory or change the directory for pid files.
But I am surprised that it is not created automatically after reboot.