Remote printing: Debian and Google Cloud Print
Have you ever heard of google cloud print? It allows you to add your printers to the cloud and share them. You can print on them from any device supporting this service, even if you are on another network. This sounds pretty cool, I gave it a try and I am really amazed.
None of my printers doesn't support cloud print directly, so I need a google chrome installation to share the printer. But I don't want to have my computer to run when printing remotely. There is a project called Google CloudPrint on Linux which allows you to use this nice service from the command line. At this point the dockstar or the linkstation joines the game.
To use your debian server as a printserver for cloud print, you need to configure your printer correctly. You will need cups. Here you can find everything needed to set it up: Debian as Printserver and Scanserver with HPLIP, CUPS, SANE
Now lets install cloudprint:
apt-get install python-pip python-cups pip install daemon pip install cloudprint
To manage startup, create the init-script /etc/init.d/cloudprint with following contents:
Make sure to set USER to the user you want cloudprint is ran as.
#!/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
USER="myuser"
PIDFILE="/var/run/cloudprint/pid"
case $1 in
start)
echo -n "Starting Google Cloud Print: "
sudo -u $USER cloudprint -d -p $PIDFILE
;;
stop)
echo -n "Stopping Google Cloud Print: "
killall cloudprint
;;
restart)
echo -n "Restarting Google Cloud Print: "
killall cloudprint
sudo -u $USER cloudprint -d -p $PIDFILE
;;
*)
echo "Usage: cloudprint {start|stop|restart}"
;;
esac
Make it executable, create the path for the pidfile and start it on startup:
chmod +x /etc/init.d/cloudprint mkdir /var/run/cloudprint chmod 777 /var/run/cloudprint insserv cloudprint
You now should be able to run a test:
/etc/init.d/cloudprint start
Enter the username and password of the google account you want to use when prompted. If everything is done you should see the printer at http://www.google.com/cloudprint/#printers.
If you now hit CTRL+P in chrome and select cloud print, a print job should be created and your printer will start printing.
Check this for other clients to print in a cloud:
http://www.google.com/cloudprint/learn/apps.html
I have tested the android app Cloud Print BETA and my job has been printed flawlessly!
Enjoy this article?
No trackbacks yet.

(7 votes, average: 4.86 out of 5)

February 1st, 2012 - 22:41
Thank you for this post. I have successfully set it up. It took some time due to driver issues but everything is working now.
I also had issues with the script above. I’m not too familiar with Linux and made a slight change to the script above. I received a script error (I don’t remember the exact details but it had to do with the line(s) that included sudo) and changed sudo to su and it seemed to work.
I look forward to more posts about the Dockstar.
P.S. I’d also like to thank you for your HowTo post to install Debian Squeeze which I found browsing Jeff’s forum.
August 10th, 2012 - 04:18
Love this! I also made a few tweaks to it. I removed the sudo portion and allow it to run as root be default. I also changed the name of the script to cloudprintd. The reason for this is, since the init script carries the same name as the executable, the killall command terminates the script that called it as well and so the restart command never gets executed. I chose the above method, but one could also merely change line 29 to read:
kill `cat $PIDFILE`
This would target the actual cloudprint process by PID.
Thanks!
August 10th, 2012 - 05:31
I also changed
PIDFILE=”/var/run/cloudprint/pid”
to
PIDFILE=”/var/run/cloudprintd.pid”
since the folder gets wiped out at reboot and
# Required-Start: $cups $network $local_fs $syslog
to
# Required-Start: cups $network $local_fs $syslog
since $cups is incorrect.
August 10th, 2012 - 10:24
Thanks, nice to know!
January 19th, 2013 - 22:38
I’ve been trying to get this to work on a raspberry pi, but keep getting “daemon module required for -d” when I run the script, but the daemon is definitely installed. Any ideas?
January 20th, 2013 - 19:21
Hm I am sorry, but I don’t know, maybe it’s an issue with wheezy?
I guess your rpi is running wheezy?
February 6th, 2013 - 19:57
I have the same issue with my pi running wheezy. The printers are recognized in CloudPrint but the daemon module can’t be found as described above.
Maybe someone has an idea to solve this problem?
February 9th, 2013 - 15:30
pip install python-daemon
February 13th, 2013 - 23:29
Hi thx for the tutorial, but i have a problem.
I wirte: sudo insserv cloudprint
Outputtext is: “insserv: script pyload: service pyload already provided!”
What can i do now?
thx sam
February 14th, 2013 - 00:12
Ew that’s weird. Stupid question, but are you sure you pasted the correct content into your file?
Check if there is another executable script with pyload in it in /etc/init.d/. insserv checks through all executables when ran.
February 16th, 2013 - 16:18
So this probrem is solved. I had 2 Script for pyload in the init.d -.-
But now ich hab a new problem with the deamon.
first he sayed after “cloudprint start” i need the deamon.
then i installed it with pip install python-deamon.
So, and now i have this exception, after “cloudprint start”:
pi@raspberrypi /usr/local/bin $ /etc/init.d/cloudprint start
Starting Google Cloud Print: pi@raspberrypi /usr/local/bin $ Traceback (most recent call last):
File “/usr/local/bin/cloudprint”, line 9, in
load_entry_point(‘cloudprint==0.7′, ‘console_scripts’, ‘cloudprint’)()
File “/usr/local/lib/python2.7/dist-packages/cloudprint/cloudprint.py”, line 475, in main
daemon_runner.do_action()
File “/usr/local/lib/python2.7/dist-packages/daemon/runner.py”, line 189, in do_action
func(self)
File “/usr/local/lib/python2.7/dist-packages/daemon/runner.py”, line 124, in _start
self.daemon_context.open()
File “/usr/local/lib/python2.7/dist-packages/daemon/daemon.py”, line 346, in open
self.pidfile.__enter__()
File “/usr/local/lib/python2.7/dist-packages/lockfile/__init__.py”, line 226, in __enter__
self.acquire()
File “/usr/local/lib/python2.7/dist-packages/daemon/pidfile.py”, line 42, in acquire
super(TimeoutPIDLockFile, self).acquire(timeout, *args, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/lockfile/pidlockfile.py”, line 90, in acquire
raise LockFailed
lockfile.LockFailed
And now i dont know, what i should do.
March 10th, 2013 - 15:57
Reboot the RPi and the “daemon module required” message goes away. At least that worked for me.
April 1st, 2013 - 20:06
Things are working fine on Raspbian on a manual start “cloudprint start” but it doesn’t start on boot (made the insserv command) ….. any advice ?
May 15th, 2013 - 14:41
I too had massive problems getting this to work. Well, actually, the script itself worked flawlessly when run as root and had me surprised at how easy it was to get it going. I spent hours trying to get it to work at boot time though. Nothing worked – manually adding to /etc/rc.local, specifying authentication with -a, hard-coding my details. The two problems seemed to be: (a) it was still prompting for details (despite me having typed them in from the command line once and it not prompting when I ran it manually) and (b) with the details hard-coded it would give an error about the service not being found. -a doesn’t seem to work at all, it wipes the auth file and then gives an authentication error, so I gave up with that.
Eventually I figured out that the problem was my wireless hadn’t come up by the time cloudprint was run.
Solution:
1. Hard-code the logon details in the script (details in the link in the original post, although the line is more like 440 rather than 40)
2. Create a script /etc/network/if-up.d/zcloudprintd which is simply (your init.d script name may vary; I changed mine):
#!/bin/sh
/etc/init.d/cloudprintd start
Reboot!