Skip to content

Instantly share code, notes, and snippets.

@tavinus
Last active January 2, 2016 02:47
Show Gist options
  • Save tavinus/e1062f66fe497fa4949d to your computer and use it in GitHub Desktop.
Save tavinus/e1062f66fe497fa4949d to your computer and use it in GitHub Desktop.
Run Google Cloudprint as service - Centos6.5 - armooo's python cloudprint connector
#!/bin/bash
#
# cloudprint Starts the cloudprint connector daemon
# description: Google cloudprint is a service for sharing printers \
# among computers through the internet.
#
### BEGIN INIT INFO
# Provides: cloudprint
# Required-Start: $cups $network $local_fs $syslog
# Required-Stop: $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts the cloudprint connector daemon
# Description: Google cloudprint is a service for sharing printers
# among computers through the internet.
### END INIT INFO
####################################################################
# cloudprint service for /etc/init.d/cloudprint
#
# Run cloudprint python connector as a Service
# Author: Gustavo Arnosti Neves
# System: Centos 6.5
#
# Cloudprint python connector:
# https://github.com/armooo/cloudprint
#
# This script:
# https://gist.github.com/tavinus/e1062f66fe497fa4949d
#
# Cron checker script:
# https://gist.github.com/tavinus/494f42ff4b9436808ca6
#
# You should first run cloudprint as root from Bash to get a
# Token/URL and link this computer to Google Cloud Print. After
# the computer is linked you can use the Credentials file here.
# Just wait for cloudprint to finish installing the credentials
# and loading the printers. Then kill the cloudprint process
# and try installing/running the service.
#
# To kill the cloudprint process:
# sudo kill $(ps aux | grep "[c]loudprint" | awk {'print $2'})
#
# This init file requires the [daemon] install of the cloudprint.
# Just edit the variables below to set up for your system.
# You should run this as root (or you will need to change stuff).
#
# Use full-paths to files, or add a PATH variable or you will
# get errors.
#
# Check your Python and Cloudprint Paths with which:
# e.g. $ which python; which cloudprint
#
# Run on boot:
# $ sudo cp cloudprint /etc/init.d/cloudprint # copy file
# $ sudo chkconfig --level 2345 cloudprint on # turn on
#
####################################################################
USER="root"
PYTHON_BIN='/usr/bin/python'
CP_BIN='/usr/bin/cloudprint'
PIDFILE='/var/run/cloudprint_pid'
CREDENTIALS_FILE='/root/.cloudprintauth.json'
LOGFILE='/tmp/cloudprint.log'
print_results() {
if [[ $1 -eq 0 ]]; then
echo '[ Ok ]'
else
echo '[ Fail ]'
fi
}
case $1 in
start)
if [[ -f $PIDFILE ]]; then
echo "[ -- ] Cloud Print Daemon is already running..."
else
echo -ne '[ -- ] Starting Google Cloud Print Daemon...\r'
"$PYTHON_BIN" "$CP_BIN" -d -p "$PIDFILE" -a "$CREDENTIALS_FILE" &> "$LOGFILE"
print_results $?
fi
;;
stop)
if [[ -f $PIDFILE ]]; then
echo -ne '[ -- ] Stopping Google Cloud Print Daemon...\r'
kill $(cat "$PIDFILE")
wait ${!} 2>/dev/null
print_results $?
rm -f "$PIDFILE" 2>/dev/null
else
echo "[ -- ] Nothing to be stopped..."
fi
;;
status)
if [[ -f $PIDFILE ]]; then
echo 'Google Cloud Print Daemon is running with PID: '$(cat "$PIDFILE")
else
echo 'Google Cloud Print Daemon is NOT running...'
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "Usage: cloudprint {start|stop|status|restart}"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment