How do I add a daemon to my Quickly application?

I am building a app with quickly, and I wanted to add a daemon that will run in the background. How do you do this?


Solution 1:

As far I know there is nothing specific in quickly to prevent or assist you with running daemons, but there is at least two options I know/guess you can do it with python:

Option #1: Distutils

NOTE: I didn't tried this one yet :)

  1. put your daemon script into the bin directory of your quickly project, e.g.: bin/yourapp-launcher

  2. add the following into the data/yourapp-launcher.desktop file:

    [Desktop Entry]
    Name=Your App
    Exec=/bin/sh -c 'yourapp-launcher'
    Type=Application
    X-GNOME-Autostart-Delay=30
    Icon=yourapp
    Comment=
    NoDisplay=true
    
  3. edit setup.py and specify additional data_files in DistUtilsExtra section, e.g.:

    DistUtilsExtra.auto.setup(
    name='hello-ubuntu',
    version='0.1',
    #license='GPL-3',
    #author='Your Name',
    #author_email='[email protected]',
    #description='UI for managing â¦',
    #long_description='Here a longer description',
    #url='https://launchpad.net/hello-ubuntu',
    cmdclass={'install': InstallAndUpdateDataDirectory},
    data_files=[('/etc/xdg/autostart', ['data/yourapp-launcher.desktop'])]
    )
    

Seems a way to go when daemon must be running for all users, e.g. similar how U1 works.

Option #2: Hardcode

Hardcode everything into your app logic, for example initialize ~/.config/autostart/yurapp-launcher.desktop on the first run, e.g. similar to how GmailNotify App does it.

Unlike GmailNotify App you can relie on the python-xdg library to access freedesktop.org standards:

import xdg
print xdg.BaseDirectory.xdg_config_home

Seems good for user managed daemons.

Solution 2:

From what I can see there is no template to add a daemon in quickly. However, you can contribute by creating a daemon template. How to create your own template is explained in the answer to this question: How to create a new quickly application template

You could also join the community templates group at Launchpad, to make your template available for others to use.

EDIT: There is also the Unity lens template. It will only work with Ubuntu Unity, so you will be platform dependent (rather significant weakness if you ask me). But it seems to have D-Bus things ready from the start. Kind of like a daemon, but maybe not quite. You could use this as a starting-point to create a platform independent daemon, perhaps...

I don't know any details other than what I can link from others, sorry. Just looking at this myself to find out how to use Qt4 with quickly. EDIT2: Just found that there is a D-Bus component to Qt, which would make your daemon platform independent (working on Windows and Linux etc). This discussion forum (http://www.qtcentre.org/threads/38453-Send-and-receive-a-signal-between-2-Qt-applications) has an example (in C++, but still) of how to use it. Or you can google for QDBusConnection and QDBusMessage.