Setting Up Printer with Cloud Print

I’ve just set up my new server, and I want it to act as a print server.  I want it to accept jobs from both the cloud and from my other Linux machines in my house.  Here’s what I did.

My Printer for Google Cloudprint

Cups Installation

First, I had to install cups and get my printer working.  Here’s how I installed cups:

sudo apt-get install cups

Before editing the configuration file, I backed it up as recommended:

sudo cp /etc/cups/cupsd.conf /etc/cups/cupsd.conf.original
sudo chmod a-w /etc/cups/cupsd.conf.original
sudo vi /etc/cups/cupsd.conf

I added this line after the two Listen lines:

Port 631

I also added the “ServerAdmin” line to add my email address.  Finally, I restarted the service to make the changes take affect:

sudo service cups restart

For security, I added my regular user to the lpadmin group:

sudo usermod -aG lpadmin <regular username>

After that, I kept getting “Forbidden” on the web page.  So, I found this command:

sudo cupsctl --remote-admin
sudo service cups restart

Configuring the Printer

First on the server, I had to install the hplip package:

sudo apt-get install hplip

From the admin web interface (https://server-ip:631/admin/), I clicked the “Add Printer” button.  It asked for my username and password.  I entered the same one that I used to log into the machine.

My printer (HP PSC) was under the local section.  I picked it off the list.  Next, I just had to give it a name and choose to share it.  Next, I picked the printer model (hplip had to be installed).

Google Cloud Print

First, I had to install a few prerequisites:

sudo apt-get install git-core python python-cups

To make the pip install command work, I had to install this package:

sudo apt-get install python-pip

Then, I ran the install command:

sudo pip install cloudprint

Then, I just ran:

cloudprint

On the first run, it prompted me for my Google account username/email address and my password.  After that, it added my PSC printer to my “devices” list on my Google account.

Installing as a Service

I installed the python daemon package:

sudo apt-get install python-daemon

Then, I swiped junkyhlm’s service script.  I opened up a new script:

sudo vi /etc/init.d/cloudprint
#!/bin/bash
# /etc/rc.d/cloudprint
# Description: Starts the Google Cloud Print script on startup
# ----------------
#
### BEGIN INIT INFO
# Provides: Cloud-Print
# Required-Start: $cups $network $local_fs $syslog
# Required-Stop: $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Start Google Cloud Print
### END INIT INFO

PIDFILE="/var/run/cloudprint/pid"

case $1 in
        start)
                echo -n "Starting Google Cloud Print: "
                cloudprint -d -p $PIDFILE
        ;;
        stop)
                echo -n "Stopping Google Cloud Print: "
                killall -9 cloudprint
        ;;
        restart)
                echo -n "Restarting Google Cloud Print: "
                killall -9 cloudprint
                cloudprint -d -p $PIDFILE
        ;;
        *)
                echo "Usage: cloudprint {start|stop|restart}"
        ;;
esac

Make sure to change the username if you use this.

I made sure the script was executable and make sure the var, run directory exists:

sudo chmod 755 /etc/init.d/cloudprint
sudo mkdir /var/run/cloudprint

Finally, I could start the service:

sudo service cloudprint start

To make the service autostart upon boot, I ran the following command:

sudo update-rc.d cloudprint defaults

Cloud Print — Failed Method

Now, that all worked fine for me.  I did try to install Cloudprint a different way initially, and that wouldn’t work.  I am  including it for reference in case anyone runs into the same error or if someone wants to point out what I did wrong.  The “pip” installer worked better than trying to install from the GitHub repository.

So, first I downloaded the source with git:

cd ~
git clone git://github.com/armooo/cloudprint.git

That created a “cloudprint” folder.  Then, I built it with this:

cd cloudprint
python setup.py build

Next, I installed it with this command:

sudo python setup.py install

The third line from the bottom of the output tells me that it installed the program in /usr/local/lib/python2.7/dist-packages/cloudprint-0.11-py2.7.egg

When I tried to run it, I got this message:

$ python /usr/local/lib/python2.7/dist-packages/cloudprint-0.11-py2.7.egg
/usr/bin/python: can't find '__main__' module in '/usr/local/lib/python2.7/dist-packages/cloudprint-0.11-py2.7.egg'

Resources

Leave a Comment

Your email address will not be published. Required fields are marked *