Skip to content

Instantly share code, notes, and snippets.

@tavinus
Last active March 29, 2016 16:51
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/90382c20f8ac923796a8 to your computer and use it in GitHub Desktop.
Save tavinus/90382c20f8ac923796a8 to your computer and use it in GitHub Desktop.
#!/bin/bash
####################################################################
# gcp-start.sh
#
# Enforce that the Google CUPs Connector 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.
#
# Example Cron:
# $ sudo crontab -e
#
# Every 10 minutes:
# 3,13,23,33,43,53 * * * * /PATH/TO/gcp-start.sh > /tmp/gcp-start.log
#
# Or:
# */10 * * * * /PATH/TO/gcp-start.sh &> /tmp/gcp-start.log
####################################################################
GCP_USER="gcp"
CP_BIN='/opt/gcp_cups_connector/gcp-cups-connector'
PIDFILE='/var/run/gcp_cups_connector_pid'
CREDENTIALS_FILE='/etc/gcp_cups_connector/gcp-cups-connector.config.json'
LOGFILE='/tmp/gcp_cups_connector.log'
if [[ $USER != "root" ]]; then
echo "You should run this as the root user, aborting..."
exit 1
fi
if [[ ! -f $PIDFILE ]]; then
sudo -H -u "$GCP_USER" $CP_BIN -config-filename $CREDENTIALS_FILE > $LOGFILE & echo $! > $PIDFILE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment