I'm trying to start statsD on ubuntu but I'm running into problems.
If I start it, it works but blocks chef from continuing but it works and shows up in graphite.
If however I start it like this (or using other methods to get it start in the background):
(/usr/bin/node /opt/statsd/stats.js /opt/statsd/localConfig.js) &
it doesn't block chef but nothing shows up in graphite, however I know it's still running because
ps aux | grep stat
shows the command as running (not including the grep command).
I've tried to do it using forever.js but npm just reports as having failed to fetch from registry: forever
Edit:
Ok, well I managed to get it to start using
nohup /usr/bin/node /opt/statsd/stats.js /opt/statsd/localConfig.js
This starts statsD (good) and it doesn't block chef (also good) but it now refuses to stop running when I try
sudo killall -r stat
In hindsight it's becuase nohup stops it from receiving the kill signal.
So the question becomes how can I get it to run in the background using nohup (or somthing like it) but still be able to stop statsD so it can be restarted (for any potential change in config).
EDIT:
Ok, by changing the start command to:
nohup /usr/bin/node /opt/statsd/stats.js /opt/statsd/localConfig.js >> /var/log/statsd.log 2>&1& \n echo $! /opt/statsd/statds.pid
I was able to store the pid and then using
kill -9 `/opt/statsd/statsd.pid`
I was able to kill the process however it still leaves rcp.statd -L
running which has a separate pid
Ok, well I managed to create a bash command that will find and kill any process with the word stat
in it; which for me works fine as only statd related process has stat
in it.
So, the command to start statD is:
nohup /usr/bin/node /opt/statsd/stats.js /opt/statsd/localConfig.js >> /var/log/statsd.log 2>&1&
A bit long winded but I'm using absolute paths.
The command to stop is:
ps aux | awk '/stat/ {print $2}' | xargs kill -9
Pretty simple and even better I don't need to do the whole "store the pid in a txt file" to kill statsd when I need to restart.