Skip to content

Instantly share code, notes, and snippets.

@pinglamb
Last active June 21, 2016 10:00
Show Gist options
  • Select an option

  • Save pinglamb/fc535ac839e9017848243c810179a361 to your computer and use it in GitHub Desktop.

Select an option

Save pinglamb/fc535ac839e9017848243c810179a361 to your computer and use it in GitHub Desktop.
Control remote app like a charm
#!/usr/bin/env bash
# Dependencies:
# - inotify-tools
MY_PIDFILE=tmp/pids/my.pid
PUMA_PIDFILE=tmp/pids/puma.pid
nohup inotifywait -m tmp/restart.txt -e attrib -q | while read event; do
test -e "$PUMA_PIDFILE" && pumactl --pidfile $PUMA_PIDFILE status
if [ $? -ne 0 ]
then
puma config.ru -d --pidfile $PUMA_PIDFILE --redirect-stdout log/puma.log --redirect-stderr log/puma.log
else
pumactl --pidfile $PUMA_PIDFILE restart
fi
done > log/puma.log 2>&1&
echo $! > $MY_PIDFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment