Skip to content

Instantly share code, notes, and snippets.

@tavinus
Last active December 31, 2015 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tavinus/494f42ff4b9436808ca6 to your computer and use it in GitHub Desktop.
Save tavinus/494f42ff4b9436808ca6 to your computer and use it in GitHub Desktop.
Enforces cloudprint python connector is running from cron
#!/bin/bash
####################################################################
# cloudprint-start.sh
#
# Enforce that CloudPrint is running
# Gustavo Arnosti Neves
#
# Use full-paths to files, or add a PATH variable or you will
# get errors when running this from Cron.
#
# Just edit the variables below to set up for your system.
# You should run this as root though.
#
# Check your Python and Cloudprint Paths with which:
# e.g. $ which python; which cloudprint
#
# Example Cron:
# $ sudo crontab -e
#
# Every 10 minutes:
# 3,13,23,33,43,53 * * * * /PATH/TO/cloudprint-start.sh &> /tmp/cloudprint.log
#
# Or:
# */10 * * * * /PATH/TO/cloudprint-start.sh &> /tmp/cloudprint.log
####################################################################
PYTHON_BIN='/usr/bin/python'
CP_BIN='/usr/bin/cloudprint'
PIDFILE='/var/run/cloudprint_pid'
CREDENTIALS_FILE='/root/.cloudprintauth.json'
LOGFILE='/tmp/cloudprint.log'
if [[ $USER != "root" ]]; then
echo "You should run this as the root user, aborting..."
exit 1
fi
if [[ ! -f $PIDFILE ]]; then
"$PYTHON_BIN" "$CP_BIN" -d -p "$PIDFILE" -a "$CREDENTIALS_FILE" &> "$LOGFILE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment