Created
July 11, 2013 09:33
-
-
Save spawnrider/5974021 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
################################################################# | |
# DON'T: steal without credit | |
# | |
# DO: Put this in your ~/SiriProxy directory & | |
# Run with rvmsudo sh siriproxy.sh {start|keepalive|stop} | |
# | |
# start will run SiriProxy in the background | |
# | |
# keepalive checks once an hour to see if the server | |
# is up, and if not, restarts it, then confirms it | |
# is indeed back up and running. | |
# | |
# keep alive *should* go to background as well if you run as | |
# rvmsudo nohup sh run.sh "keepalive" 2>&1> keepalive.log < /dev/null & | |
# | |
# all logs are in ~/SiriProxy, check keepalive.log for server status | |
# and proxy.out & proxy.err for SiriProxy output. | |
################################################################# | |
START="rvmsudo nohup siriproxy server > proxy.out 2> proxy.err < /dev/null &" | |
TODAY=$(date) | |
case $1 in | |
start) | |
$START | |
exit 0 | |
;; | |
stop) | |
echo "Stopping..." | |
rvmsudo killall -e "ruby $HOME/.rvm/gems/ruby-1.9.3-p0@SiriProxy/bin/siriproxy server" > /dev/null | |
rvmsudo killall sleep > /dev/null | |
echo "Done." | |
exit 0 | |
;; | |
# all code by methoddk | |
keepalive) | |
while true; do | |
if ps ax | grep -v grep | grep "$HOME/.rvm/gems/ruby-1.9.3-p0@SiriProxy/bin/" > /dev/null | |
then | |
echo $TODAY "SiriProxy is running!" | |
else | |
echo $TODAY "SiriProxy is not running. Restarting..." | |
${START} | |
sleep 5 | |
if ps ax | grep -v grep | grep "$HOME/.rvm/gems/ruby-1.9.3-p0@SiriProxy/bin/" > /dev/null | |
then | |
echo $TODAY "SiriProxy is running!" | |
else | |
echo $TODAY "Something is wrong." | |
fi | |
fi | |
sleep 3600 | |
done | |
;; | |
*) | |
echo "Usage: rvmsudo sh $0 {start|keepalive|stop}" | |
exit 0 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment