Skip to content

Instantly share code, notes, and snippets.

@bdashrad
Created May 20, 2015 15:21
Show Gist options
  • Save bdashrad/6930120b8edb8754aa0b to your computer and use it in GitHub Desktop.
Save bdashrad/6930120b8edb8754aa0b to your computer and use it in GitHub Desktop.
cron script to keep an app running
#!/usr/bin/env bash
PIDFILE="/mnt/tmp/myapp.pid"
if [ -e "${PIDFILE}" ] && (ps -u $(whoami) -opid= |
grep -P "^\s*$(cat ${PIDFILE})$" &> /dev/null); then
echo "Already running"
exit 99
fi
pushd /path/to/myapp/ > /dev/null 2>&1
myapp -a args >/dev/null 2>&1 &
echo $! > "${PIDFILE}"
chmod 644 "${PIDFILE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment