Creating PID files for beanstalkd on CentOS


Yep, managing servers is hard >.< I’ve been trying to set beanstalkd to be managed by monit on CentOS. Unfortunately beanstalkd doesn’t seem to create pid files on CentOS (it creates one in Ubuntu though). Pid files are needed by monit so it can check if the process is still running or not. Many grueling hours later, I settled with modifying /etc/init.d/beanstalkd and adding this to the start() function (after daemon $exec…):

echo `ps auxf | grep -v grep | grep "$exec -d $options" | awk '{print $2}'` > /var/run/beanstalkd.pid

I have no idea what all those grep and awk exactly mean. ^_^x But the effect is it creates the pid file in /var/run/beanstalkd.pid containing the correct process id of beanstalkd. You could then have monit watch that pid file.

Here’s the whole modified script. And this is my main reference: http://gist.github.com/508889. A huge thanks to him (Sam X).