Skip to content

Instantly share code, notes, and snippets.

@jlecour
Created May 21, 2012 08:22
Show Gist options
  • Save jlecour/2761147 to your computer and use it in GitHub Desktop.
Save jlecour/2761147 to your computer and use it in GitHub Desktop.
A script to kill Passenger processes that are not known anymore by the watchdog
#!/bin/bash
set -e
# overridable defaults
GEM_HOME=${GEM_HOME:-/usr/local/passenger}
PASSENGER_BIN_PATH=${PASSENGER_BIN_PATH:-$GEM_HOME/bin}
PASSENGER_TMPDIR=${PASSENGER_TMPDIR:-/var/tmp}
PATH=$PATH:$PASSENGER_BIN_PATH
MEMORY_STATS_BIN=`which passenger-memory-stats`
STATUS_BIN=`which passenger-status`
attached_pids() {
GEM_HOME=$GEM_HOME \
PASSENGER_TMPDIR=$PASSENGER_TMPDIR \
$STATUS_BIN |
grep '* PID' |
cut -d ' ' -f 5
}
all_pids() {
GEM_HOME=$GEM_HOME \
PASSENGER_TMPDIR=$PASSENGER_TMPDIR \
$MEMORY_STATS_BIN |
grep -E '(Rack|Rails)' |
cut -d ' ' -f 1
}
detached_pids() {
# "combine" comes from the "moreutils" package (at least on Debian)
combine <(all_pids) not <(attached_pids)
}
detached_pids_as_string() {
echo `detached_pids`
}
number_of_detached_pids() {
detached_pids | wc -l
}
main() {
if test -z detached_pids_as_string; then
echo "Detached pids found : $(detached_pids_as_string)"
kill `detached_pids_as_string`
else
echo "No detached pids found"
fi
}
main
@jlecour
Copy link
Author

jlecour commented May 22, 2012

Apparently I'm the worst at writing bash scripts. This thing is not working properly, yet. Sorry for the mess.

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