Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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. :-)

Thanks!

share|improve this question

2 Answers 2

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

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

http://www.enderunix.org/docs/eng/daemon.php

http://www.netzmafia.de/skripten/unix/linux-daemon-howto.html

http://code.activestate.com/recipes/66012-fork-a-daemon-process-on-unix/

http://cjh.polyplex.org/software/daemon.pdf

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

Your Answer

 
discard

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.