developer.shyd.de. studying my hobby

3Jan/1223

Remote printing: Debian and Google Cloud Print

Google_Cloud_Print_logo
(8 votes, average: 4.75 out of 5)
Loading...Loading...

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!

  • curti

    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.

  • http://drewwithers.com Drew

    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!

    • http://drewwithers.com Drew

      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.

      • shyd

        Thanks, nice to know!

  • Andy

    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?

    • shyd

      Hm I am sorry, but I don’t know, maybe it’s an issue with wheezy?
      I guess your rpi is running wheezy?

      • David

        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?

        • markus

          pip install python-daemon

          • rob

            pip uninstall daemon
            apt-get install python-daemon
            worked for me

    • Bosn

      same error here
      re-installing the daemon does not help
      any ideas?

  • sam

    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

    • shyd

      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.

      • sam

        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.

  • smagee

    Reboot the RPi and the “daemon module required” message goes away. At least that worked for me.

  • ev23

    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 ?

    • http://www.unsatisfactorysoftware.co.uk Chris

      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!

  • David Steele

    Debian packages for Cloud Print, with an init.d service:

    https://github.com/davesteele/cloudprint-debian

    Install, then run “service cloudprintd login” as root.

    • Stuart

      this worked a treat, thanks David

  • Jason

    Thanks for sharing but it doesn’t seem to work with GAPPs accounts (ie. username@myOwnDomain.com).

    • http://dev.shyd.de/ shyd

      I can’t test right now. But I set this up with my GAPPs account when I wrote this article.

  • Nick Sillito

    I’ve just tries setting this up on my system — running Ubuntu 10.04 LTS (64 bit), with a Canon PIXMA printer. This all works fine, and I can see the printer ok on the Google cloud print home page.

    However, when I try to print from my ‘phone — a Google Nexus 5 — as soon as I select this printer, I get the message “the print spooler has crashed, do you want to send an error report”

    I have some other printers set up on my account, and they work fine.

    Any ideas?

  • Thierry CHARLES

    fully reviewed service script for debian :

    #!/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=”pi”
    PIDFILE=”/var/run/cloudprint.pid”
    TMPPID=”/tmp/cloudprint$$.pid”

    . /lib/lsb/init-functions

    function start() {
    log_begin_msg “Starting Google Cloud Print”
    if [ -f $PIDFILE ]
    then
    log_end_msg 1
    return 1
    fi

    su – $USER -c “cloudprint -d -p $TMPPID”
    WAIT=5
    while [ $WAIT -gt 0 -a "!" -f $TMPPID ]
    do
    sleep 1
    WAIT=$(( $WAIT – 1 ))
    done

    if [ -f $TMPPID ]
    then
    log_end_msg 0
    mv $TMPPID $PIDFILE
    return 0
    else
    log_end_msg 1
    return 1
    fi
    }

    function stop() {
    log_begin_msg “Stopping Google Cloud Print”
    if [ "!" -f $PIDFILE ]
    then
    log_end_msg 1
    return 1
    fi

    kill -9 `cat $PIDFILE`
    rm $PIDFILE
    log_end_msg 0
    return 0
    }

    case $1 in
    start)
    start
    RT=$?
    ;;
    stop)
    stop
    RT=$?
    ;;
    restart)
    stop
    sleep 1
    start
    RT=$?
    ;;
    *)
    echo “Usage: cloudprint {start|stop|restart}”
    RT=1
    ;;
    esac

    exit $RT

  • Ecclesia

    When I try to set up for insserv I am getting this error: insserv: script lpd: service cups already provided!

    Does anyone know how to set this up so that I can allow the script to start at boot. Obviously, it depends on cups – so if I remove this from init.d the script will run, but it won’t connect to cups and thus fails.