Day 53: /var/run/*.pid
Most of daemons you start on a server, create a file in /var/run/
It contains the PID of the running process. (see day-18 https://iadvize.github.io/devops-tip-of-the-day/tips/day-18-ps-command).
This is usefull for 2 reasons:
- This is used as a lock to avoid running twice the same daemon (
/etc/init.d/mysqld startwill block until /var/run/mysql.pid is removed). - This is also used for sending orders to a running process. For example,
/etc/init.d/nginx reloadwill get the PID of main nginx process in/var/run/nginx.pid, then, send a SIGHUP signal to this PID, to order it to reload its configurations. (see day-21 https://iadvize.github.io/devops-tip-of-the-day/tips/day-21-unix-signals-most-used/)
:bulb: What happens if you force-remove /var/run/nginx.pid file and execute /etc/init.d/nginx stop ?
by ops for non-ops