Skip to content

Instantly share code, notes, and snippets.

@rjswenson
Last active August 29, 2015 14:15
Show Gist options
  • Save rjswenson/8897a0eb86803dd28c06 to your computer and use it in GitHub Desktop.
Save rjswenson/8897a0eb86803dd28c06 to your computer and use it in GitHub Desktop.
restart_sidekiqs.sh
#!/bin/bash
set -f
echo 'Iterating through all Sidekiq screens' >&2
for i in $( screen -ls sidekiq| grep -o [0-9]*.sidekiq\-[a-z]*); do
SCREEN_ID=$(echo $i | grep -oE "(^[0-9]+)")
CLIENT=$(echo $i | grep -oE "([a-z]+)$")
echo "starting screen: ${i}"
read -p "Do you wish to restart <<${i}>>? [ y/n ]" prompt
printf "\n"
if [[ $prompt =~ [yY](es)* ]]
then
screen -X -S $SCREEN_ID stuff "$(printf \\003)"
sleep 3
screen -X -S $SCREEN_ID stuff 'cd ..
'
screen -X -S $SCREEN_ID stuff 'cd current/
'
screen -X -S $SCREEN_ID stuff "bundle exec sidekiq -q $CLIENT-staging -c 1
"
echo "backing out of <<${CLIENT}>>"
printf "\n"
else
continue
fi
done
echo "FINISHED RESTARTING SIDEKIQ" >&2
@rjswenson
Copy link
Author

for pid in $( ps aux |grep ^deploy.*sidekiq |grep -v SCREEN |grep -v grep | awk '{print $2}' ); do 
  kill -s TERM $pid
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment