LiveReload is super useful, especially in combination with grunt-contrib-watch as it enables me to quickly see my code reflected in the browser.
However, I am often working on more than one project and that can mean constantly having to shut down the running LiveReload server so that I can run grunt watch
in another project’s directory.
To save the hassle of finding the process ID so that I can kill the server, I wrote a quick bash function to find whatever is running on the standard LR port of 35729
and kill it.
Thus… lrkill
I simply put this in my ~/.bash_profile
and ran source ~/.bash_profile
to update the current shell.
lrkill() {
LRPID=`lsof -n -i4TCP:35729 | grep LISTEN | awk '{print $2}'`
if [ $LRPID ]
then
echo 'Killing LiveReload server (PID: '$LRPID')'
kill $LRPID
fi
}
Now all I need to do is call lrkill
and then grunt watch
and my new LiveReload server is up an running.
This works in OSX, but other OS users may need to find an equivalent of lsof
to achieve the same thing.
Thanks very much for this. Works like a charm!
Great snippet, thank you very much! Instead of adding it to my bash_profile, I’ve create a separate .sh file and added it to my local scripts folder which is included in the PATH variable.