Statistics
| Branch: | Tag: | Revision:

root / lib / daemon.py @ 7fa310f6

History | View | Annotate | Download (23.5 kB)

# Date Author Comment
8cabf472 02/02/2011 06:02 pm Michael Hanselmann

Reopen log files upon SIGHUP in daemons

Signed-off-by: Michael Hanselmann <>
Reviewed-by: Iustin Pop <>
Reviewed-by: René Nussbaumer <>

cfcc79c6 02/02/2011 06:02 pm Michael Hanselmann

utils.SetupLogging: Make program a mandatory argument

It's passed in by most users (daemons, CLI scripts) and for the others
(burnin, watcher) it certainly doesn't hurt, especially when using
syslog.

Signed-off-by: Michael Hanselmann <>...

79b60c1c 01/11/2011 05:33 pm Michael Hanselmann

utils: Drop RemovePidFile

It's equivalent to a simple RemoveFile now.

Signed-off-by: Michael Hanselmann <>
Reviewed-by: Iustin Pop <>

7b4baeb1 01/11/2011 04:24 pm Michael Hanselmann

utils: Use function to disable fork

Use a function instead of a variable written by another module.

Signed-off-by: Michael Hanselmann <>
Reviewed-by: Iustin Pop <>

8342c325 01/11/2011 04:24 pm Michael Hanselmann

utils: Change RemovePidFile to take path, not name

This avoids having to monkey-patch the utils module for unittests.
Monkey patching is evil and caused a bug while moving code around.

Signed-off-by: Michael Hanselmann <>
Reviewed-by: Iustin Pop <>

ed3920e3 10/07/2010 11:32 am Iustin Pop

Fix a rare bug in StartDaemonChild and GenericMain

I've seen cases where the result from str(sys.exc_info()[1]) is ""; this
breaks the error reporting as the parent relies on non-empty error
messages to properly detect child status (otherwise it will try to read...

3e87c1bf 10/07/2010 11:31 am Iustin Pop

Enhance the error reporting

Since daemon startup error will be often related to socket errors, so it
makes sense to change the original reporting:

Error when starting daemon process: "(98, 'Address already in use')"

Into:

Error when starting daemon process: 'Socket-related error: Address...
b78aa8c2 10/07/2010 11:31 am Iustin Pop

Change daemon.GenericMain/utils.Daemonize workflow

This patch copies the pipe-based error reporting functionality from
utils.StartDaemon (I gave up for now on tryin to merge the two).

This patch will fix two longstanding bugs:

- if we fork, we lose all error reporting from the child to the original...

b42ea9ed 10/07/2010 11:31 am Iustin Pop

Change utils.GenericMain protocol

Currently, GenericMain does a two-staged workflow:

- Check, before forking
- then Exec, after forking

This means we don't have any possibility to treat preparation work
(before the daemon is ready for work) different from the actual work....

5c4d37f9 10/07/2010 11:31 am Iustin Pop

Use only one version of WritePidFile

This patch merges the pid file handling used for ganeti-* daemons and
impexp daemons. The latter version is used, since it's more reliable:
uses locked pid files as opposed to checking 'live' processes.

Signed-off-by: Iustin Pop <>...

f4ec2960 09/16/2010 02:58 pm René Nussbaumer

Bail out if daemon gets fired up under wrong uid

This patch bails out in early stage, if the user invoking the daemon
doesn't match the user set at configure time.

Signed-off-by: René Nussbaumer <>
Reviewed-by: Michael Hanselmann <>

fd346851 09/07/2010 02:26 pm René Nussbaumer

Remove utils.EnsureDir as this is done by ensure-dirs.in now

Signed-off-by: René Nussbaumer <>
Reviewed-by: Michael Hanselmann <>

0070a462 09/07/2010 02:26 pm René Nussbaumer

Revert "Make it possible to call utils.Daemonize with uid and gid to run as"

This reverts commit 743b53d4eb9f3de46edb5e54738dab287b1979ac.

Conflicts:

lib/daemon.py

Trivial conflict resolved. This patch reverts changes from earlier permissions
separation stage. This is not needed anymore as start-stop-daemon takes care...

7dd999fc 08/27/2010 03:44 pm Manuel Franceschini

Handle ENOENT case in ssconf.GetPrimaryIPFamily

This patch adds an optional default parameter to SimpleStore._ReadFile. This
can be used to default the return value of this method in case the ssconf file
is not present.

In this particular case it is used to return AF_INET in case...

981732fb 08/23/2010 01:31 pm Manuel Franceschini

Make family argument in FormatAddress optional

By doing this we delegate the task of finding the correct address family
to the FormatAddress method.

Signed-off-by: Manuel Franceschini <>
Reviewed-by: Iustin Pop <>

e7323b5e 08/19/2010 12:44 pm Manuel Franceschini

Support IPv6 cluster init

Signed-off-by: Manuel Franceschini <>
Reviewed-by: Iustin Pop <>

1a8337f2 08/18/2010 11:28 am Manuel Franceschini

rapi.client, http.client: Format url correctly when using IPv6

This patch moves the FormatAddress helper function from daemon.py to
netutils.py. This enables its use in http.client as well as in
rapi.client. Furthermore this adds functionality to format IPv6...

d8bcfe21 07/12/2010 03:58 pm Manuel Franceschini

Confd IPv6 support

This patch series basically adds a new parameter 'family' to the constructors
of daemon.AsyncUDPSocket and confd.client.ConfdUDPClient. This enables the
users of these two classes to support IPv6.

In ganeti-confd.ConfdAsyncUDPClient a method to check the address families of...

a744b676 07/09/2010 04:37 pm Manuel Franceschini

Introduce lib/netutils.py

This patch moves network utility functions to a dedicated module.

Signed-off-by: Manuel Franceschini <>
Reviewed-by: Iustin Pop <>

14f5f1b6 06/30/2010 01:42 pm Manuel Franceschini

Replace '0.0.0.0' with constant

Signed-off-by: Manuel Franceschini <>
Reviewed-by: Guido Trotter <>

1e063ccd 06/29/2010 02:30 pm Guido Trotter

AsyncTerminatedMessageStream: send_message

This function adds the ability for a AsyncTerminatedMessageStream to
have a thread-safe message delivery function.

Signed-off-by: Guido Trotter <>
Reviewed-by: Michael Hanselmann <>

37e62cb9 06/29/2010 02:30 pm Guido Trotter

AsyncTerminatedMessageStream: limit message count

Currently the message stream can process any number of messages in
parallel (if they get dispatched to different threads or processes).
In order to limit their number we only handle messages and read from...

b628191f 06/17/2010 01:00 pm Guido Trotter

AsyncAwaker: use shutdown on the socketpair

This makes sure the out_socket can only be used for writing, and the
in_socket for reading.

Signed-off-by: Guido Trotter <>
Reviewed-by: Michael Hanselmann <>

743b53d4 06/04/2010 05:22 pm René Nussbaumer

Make it possible to call utils.Daemonize with uid and gid to run as

Signed-off-by: René Nussbaumer <>
Reviewed-by: Guido Trotter <>

495ba852 06/03/2010 01:48 pm Guido Trotter

daemon.AsyncAwaker

This new asyncore dispatcher can be used to force a thread running the
asyncore loop to awake from the select, by signaling it on one of its
selected sockets.

Signed-off-by: Guido Trotter <>
Reviewed-by: Michael Hanselmann <>

a4b605ae 06/03/2010 01:48 pm Guido Trotter

daemon.AsyncStreamServer

This is a new asyncore server which handles listening stream sockets by
calling a non-implemented function for each connection it accepts. It's
the stream-oriented cousing of the AsyncUDPSocket.

Signed-off-by: Guido Trotter <>...

b66ab629 06/03/2010 01:48 pm Guido Trotter

daemon.AsyncTerminatedMessageStream

This is the counterpart of the AsyncStreamServer can be used to handle
connected sockets returned from connected clients if the protocol is a
terminator separated message stream. Nothing in this class is server
specific though: it can be used as a client as well, if the client is...

ff18f526 06/01/2010 08:31 pm Guido Trotter

Merge remote branch 'origin/devel-2.1'

  • origin/devel-2.1:
    Explicitely return None from IgnoreSignals
    AsyncUDPSocket: fix IgnoreSignals usage and test
    Add KVM chroot feature
    Fix and Improve TryToRoman unittest

Conflicts:
test/ganeti.daemon_unittest.py...

6e7e58b4 06/01/2010 08:22 pm Guido Trotter

AsyncUDPSocket: fix IgnoreSignals usage and test

This bug was found in the asyncore master patch series, but actually
applies to 2.1 for AsyncUDPSocket as well.

Signed-off-by: Guido Trotter <>
Reviewed-by: Michael Hanselmann <>

fadc3742 05/25/2010 02:30 pm Guido Trotter

Merge branch 'devel-2.1'

  • devel-2.1:
    Test for errors during inotify callback
    SingleFileEventHandler: Remove try/except blocks
    ErrorLoggingAsyncNotifier
    daemon.GanetiBaseAsyncoreDispatcher

Signed-off-by: Guido Trotter <>
Reviewed-by: Iustin Pop <>

b11780bb 05/25/2010 01:16 pm Guido Trotter

daemon.GanetiBaseAsyncoreDispatcher

Abstract a few common functionalities between all ganeti asyncore
dispatchers:
- Handle errors by logging them, and then continue
- By default check sockets only for readability

Signed-off-by: Guido Trotter <>...

17931833 05/24/2010 01:12 pm Guido Trotter

Merge branch 'devel-2.1'

  • devel-2.1:
    TestSingleFileEventHandler: abstract notifier type
    Mainloop: handle SIGINT as well (and terminate)
    SingleFileEventHandler: update comments

Signed-off-by: Guido Trotter <>
Reviewed-by: Balazs Lecz <>

f59dce3e 05/22/2010 09:58 am Guido Trotter

Mainloop: handle SIGINT as well (and terminate)

This is needed if daemons are in the foreground, and get ctrl+c-ed by
the user. Also add unittests to make sure the correct signals terminate
the mainloop.

Signed-off-by: Guido Trotter <>...

31ff0247 05/17/2010 02:17 pm Michael Hanselmann

Merge branch 'devel-2.1'

  • devel-2.1:
    RAPI: /2/{nodes,instances}/$name should return 404 for unknown items
    ganeti-masterd: Improve error logging for client requests
    Return disk_template from LUQueryInstanceData
    RAPI client: Rename Get{Node,Instance}Info, add new GetInstanceInfo...
b2efcd70 05/14/2010 07:03 pm Guido Trotter

Remove unused import from daemon.py

Signed-off-by: Guido Trotter <>
Reviewed-by: Luca Bigliardi <>

48bf6352 05/14/2010 06:46 pm Guido Trotter

Add a forgotten comment about overriding a method

Signed-off-by: Guido Trotter <>
Reviewed-by: Michael Hanselmann <>

3660fcf5 05/14/2010 06:46 pm Guido Trotter

AsyncUDPSocket.handle_error

By overriding the default asyncore handle_error (which closes the
socket) with our own version, which logs what happened but tries to
proceed, we can get rid of a couple of try/except blocks. The resulting
churn is deindentation of the internal code....

232144d0 05/14/2010 06:46 pm Guido Trotter

utils.IgnoreSignals

Remove duplicate code between a couple of asyncore related function by
having a function in charge of handling EINTR errors. Unittests included.

Signed-off-by: Guido Trotter <>
Reviewed-by: Michael Hanselmann <>

1c54156d 05/13/2010 07:40 pm Luca Bigliardi

Merge branch 'devel-2.1'

Conflicts:
daemons/ganeti-noded
lib/daemon.py
lib/rapi/baserlib.py
lib/rapi/rlib2.py
lib/utils.py

Signed-off-by: Luca Bigliardi <>
Reviewed-by: Michael Hanselmann <>

ff917534 05/13/2010 04:32 pm Luca Bigliardi

Daemons conditionally setup console logging

Signed-off-by: Luca Bigliardi <>
Reviewed-by: Michael Hanselmann <>

01144827 05/10/2010 12:44 pm Guido Trotter

Merge branch 'devel-2.1'

  • devel-2.1: (22 commits)
    NEWS: fix empty lines
    Fix a unittest name and docstring
    Force ssh to allocate a tty
    Fix a unittest docstring
    IsProcessAlive: retry stat() a few times
    Retry{Again,Timeout}: explain reraising
    utils.Retry: pass up timeout arguments...
5a062513 05/07/2010 02:34 pm Guido Trotter

daemon.GenericMain: fix docstring

The docstring reports a wrong type for the "dirs" argument. Fixing.

Signed-off-by: Guido Trotter <>
Reviewed-by: Balazs Lecz <>

cf6fee17 04/07/2010 06:47 pm Michael Hanselmann

Merge branch 'devel-2.1'

  • devel-2.1:
    Fix consistency checks in ConfdFilterCallback
    Fix utils.WaitForFdCondition inner retry loop
    Fix bug introduced in 76e5f8b54: mkdir mode
    utils: Move wrapper code around os.makedirs into separate function
    Fix unittest for the rapi client library...
1b429e2a 04/07/2010 04:55 pm Iustin Pop

Fix utils.WaitForFdCondition inner retry loop

Commit dfdc4060 added WaitForFdCondition which uses utils.Retry without
handling timeout exceptions. This breaks any nested retry loops.

This patch fixes the above function, and also changes utils.Retry to
detect and warn future similar cases. In addition, we add a few small...

791f317d 03/18/2010 03:56 pm Guido Trotter

Merge branch 'devel-2.1'

  • devel-2.1:
    burnin: implement basic confd testing
    AsyncUDPSocket.process_next_packet
    WaitForSocketCondition: rename, handle EINTR
    move http.WaitForSocketCondition to utils
    ConfdCountingCallback
    ConfdClient: add synchronous features...
6ddf5c8f 03/18/2010 01:39 pm Guido Trotter

AsyncUDPSocket.process_next_packet

This function allows receiving socket data synchronously.

Signed-off-by: Guido Trotter <>
Reviewed-by: Michael Hanselmann <>

8216580d 03/18/2010 01:38 pm Guido Trotter

AsyncUDPSocket: abstract do_read function

This basically implements read handling, without catching all
exceptions. When using the socket in synchronous mode, it's useful to
avoid losing exception data (which, in an async daemon, can only be
logged)

Signed-off-by: Guido Trotter <>...

e7307f08 02/01/2010 03:01 pm Michael Hanselmann

Merge branch 'devel-2.1'

  • devel-2.1:
    Bump version to 2.1.0~rc5
    Makefile.am: Targets used directly should depend on BUILT_SOURCES
    Make the snapshot decision based on disk type
    Three small typos in man pages
    Fix missing bridge for xen instances
    Fix flipping MC flag bug...
551b6283 01/28/2010 11:43 am Iustin Pop

Add capability to use syslog for logging

This patch adds a configure-time parameter that will set the defaults
used by all programs, and command-line parameters in the daemons that
allow overriding it.

Syslog 'yes' enables syslog in addition to file-based logging, 'only'...

24cd3744 01/04/2010 12:55 pm Iustin Pop

Merge remote branch 'devel-2.1'

  • devel-2.1: (40 commits)
    Fix unused imports or add silences where needed
    bdev: Add a TODO and a pylint silence
    confd: add a TODO and a pylint disable
    pylint: Temporarily disable W0201
    Disable R0922 in pylint
    Further pylint disables, mostly for Unused args...
7260cfbe 01/04/2010 11:15 am Iustin Pop

Add targeted pylint disables

This patch should have only:

- pylint disables
- docstring changes
- whitespace changes

Signed-off-by: Iustin Pop <>
Reviewed-by: Olivier Tharan <>

0648750e 12/01/2009 03:29 pm Michael Hanselmann

daemon.GenericMain: Don't use dict for SSL paths, improve CLI options

Pass SSL certificate and key paths from ganeti-* instead of using a dict. The
patch also improves the --ssl-{key,cert} options by giving the default in
--help output and changes the validation a bit....

30dabd03 12/01/2009 03:29 pm Michael Hanselmann

daemon.GenericMain: Don't use list of multithreaded daemons

Passing it in as a parameter seems more logical.

Signed-off-by: Michael Hanselmann <>
Reviewed-by: Guido Trotter <>

0a71aa17 12/01/2009 03:29 pm Michael Hanselmann

daemon.GenericMain: Improve --bind and --port options a bit

Signed-off-by: Michael Hanselmann <>
Reviewed-by: Guido Trotter <>

099c52ad 11/03/2009 04:31 pm Iustin Pop

Another round of pylint-related style fixes

A newer version of pylint, more warnings…

Signed-off-by: Iustin Pop <>
Reviewed-by: Michael Hanselmann <>

69b99987 10/12/2009 01:48 pm Michael Hanselmann

Code and docstring style fixes

Found using pylint and epydoc.

Signed-off-by: Michael Hanselmann <>
Reviewed-by: Guido Trotter <>

c124045f 09/24/2009 06:12 pm Iustin Pop

Add missing import sys to lib/daemon.py

It does “print >> sys.stderr, …” but there is no import sys.

Signed-off-by: Iustin Pop <>
Reviewed-by: Michael Hanselmann <>
Reviewed-by: Guido Trotter <>

5f3269fc 09/16/2009 03:55 pm Guido Trotter

Abstract AsyncUDPSocket to daemon

This allows this extended asyncore+udp module to be used also in other
daemons, and in the confd client library

Signed-off-by: Guido Trotter <>
Reviewed-by: Michael Hanselmann <>

c8eded0b 09/16/2009 03:55 pm Guido Trotter

AsyncUDPSocket: Move to a well defined UDP size

Currently we read maximum 4K packets, and don't check packets when
sending them. With this patch we move to a well defined maximum size of
60K.

Signed-off-by: Guido Trotter <>
Reviewed-by: Michael Hanselmann <>

5c566e17 08/28/2009 06:35 pm Michael Hanselmann

Merge branch 'next' into branch-2.1

  • next:
    Add script to clean archived jobs after 21 days
    rapi: export more static node information
    Pass the correct signal to handlers
    cli: Use ToStdout/ToStderr instead of print
    Fix small typo in gnt-node
    Simplify handling of boolean args in rapi...
a02b89cf 08/21/2009 01:02 pm Guido Trotter

Reinsert simple timers in Mainloop

This time we use the standard python sched module, rather than doing it
all by ourselves. The scheduler in mainloop can be manipulated directly
by callers, to enter new events.

Signed-off-by: Guido Trotter <>...

112d240d 08/20/2009 05:04 pm Guido Trotter

Convert the http server/mainloop to asyncore

We can avoid most of the Mainloop.Run() code if we use asyncore
for delivering I/O events, and just concentrate on what's missing in
asyncore: singnal handling and timers. This way confd can be ported to
use Mainloop as well....

a9fe7232 08/20/2009 01:42 pm Guido Trotter

Pass the correct signal to handlers

Mainloop currently calls all handlers with the signal number harcoded to
sigchild. Fixing this.

Signed-off-by: Guido Trotter <>
Reviewed-by: Olivier Tharan <>

9b739173 08/20/2009 12:28 pm Guido Trotter

Convert daemon.Mainloop to @SignalHandled

This makes the function a lot simpler, since it used to install two
different signal handlers, which are now transparently handled by the
decorator. The code is unindented, but remains unchanged apart from the
part that checks the signal handlers (which is now collapsed toghether)....

565fe4c4 08/20/2009 11:43 am Guido Trotter

Simplify IO waiting in Mainloop

IO is never unregistered in our current usage, so dropping that
functionality for now. Also putting the poller outside of the Run()
function allows us to avoid the double step of adding tuples to an
_io_wait_add queue and adding them later in the main loop....

577c90a3 08/20/2009 11:43 am Guido Trotter

Remove timers from Mainloop

Timers are currently unused, slightly buggy (for example timeout doesn't
get updated correctly), and unneeded in the current form. Confd will
have timeouts in more simple fashion, and is not a mainloop user
anyway.

Signed-off-by: Guido Trotter <>...

3b1b0cb6 07/26/2009 01:31 pm Guido Trotter

Collapse SSL key checking/overriding for daemons

Signed-off-by: Guido Trotter <>

04ccf5e9 07/25/2009 05:32 pm Guido Trotter

Collapse daemon's main function

With three ganeti daemons, and one or two more coming, the daemon's main
function started becoming too much cut&pasted code. Collapsing most of
it in a daemon.GenericMain function. Some more code could be collapsed
between the two http-based daemons, but since the new daemons won't be...

53d47a06 03/20/2009 03:06 pm Guido Trotter

Mainloop: avoid calculating timeout every time

set timeout_needs_update to False after calculating the timeout.

Reviewed-by: imsnah

b11c9e5c 11/11/2008 01:02 pm Michael Hanselmann

ganeti.daemon: Add timers to Mainloop

This is a fallout from my work on the HTTP client class. Repeating
timers are prepared, but not yet implemented.

Reviewed-by: iustinp

b14b975f 11/10/2008 02:37 pm Michael Hanselmann

ganeti.daemon: Make Mainloop more flexible

While working on the HTTP client class, I wanted to use Mainloop
before deciding to use threads instead.

- Add docstrings
- Rename "quit" to "running", move it to a local variable
- Support adding and removing I/O listeners while running...

54cf6599 10/23/2008 02:58 pm Michael Hanselmann

daemon.py: Don't wake up every second

We don't have timers yet, hence waking up is not needed at all.

Reviewed-by: ultrotter

a570e2a8 10/17/2008 02:08 pm Guido Trotter

Mainloop: handle sigterm

This fixes removals of the pid files and clean exit in the init script

Reviewed-by: iustinp

07fc5289 10/17/2008 02:07 pm Guido Trotter

Mainloop: init sigchld_handler as None

There is no point in initializing sigchld_handler as an empty dict, when
it will be overwritten by an instance of utils.SignalHandler
immediately after.

Reviewed-by: iustinp

821d9e43 10/10/2008 07:00 pm Michael Hanselmann

Add daemon library with mainloop

This mainloop can be used in daemons like ganeti-noded.

Reviewed-by: iustinp