Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As part of the Ubuntu Accomplishments system I have a daemon that runs as well as a client that connects to it. The daemon is written in Python (using Twisted) and provides a dbus service and a means of processing requests from the clients.

Right now the daemon is just a program I run before I run the client and it sets up the dbus service and provides an API that can be used by the clients.

I want to transform this into something that can be installed and run as a system service for the user's session (e.g. starting on boot) and providing a means to start and stop it etc.

The problem is, I am not sure what I need to do to properly daemonify it so it can run as this service. I wanted to ask if others can provide some guidance. Some things I need to ask:

  • How can I treat it as a service that is run for the current user service (not a system service right now)?
  • How do I ensure I can start, stop, and restart this session service?
  • When packaging this, how do I ensure that it installs it as a service for the user's session and is started on login etc?

In responding, if you can point me to specific examples or solutions I need to implement, that would be helpful. :-)


share|improve this question

I found several how-to's just by running a Google search:

I hope they can help you on your way.

share|improve this answer
Thanks for the recommended links. I guess the first thing I am trying to figure out is if I can do this easily using Twisted. I see there is something called twistd which might help here, but I am not sure where to start. – jonobacon Feb 25 '12 at 3:54

A daemon is basically a program with no direct user interaction... So there is nothing really specific about it. Nevertheless, you have to take care about some keys points :

  • any output or log should go to syslog, not the standard output
  • at startup, create a pid file under /var/run. And clear it at shutdown.
  • you have to write a service supervision file, to be located in /etc/init.d (scripts for existing daemon are a good source of inspiration). This script usually has to start the daemon under the right user, provide it with the right configuration files and so on.
  • your process might begin with a fork, to detach from the calling process, but I'm not really sure about that, especially for a python program.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.