slimta.util.system

Contains functions to simplify the usual daemonization procedures for long- running processes.

slimta.util.system.daemonize()

Daemonizes the current process using the standard double-fork. This function does not affect standard input, output, or error.

Returns:The PID of the daemonized process.
slimta.util.system.redirect_stdio([stdout=None[, stderr=None[, stdin=None]]])

Redirects standard output, error, and input to the given filenames. Standard output and error are opened in append-mode, and standard input is opened in read-only mode. Leaving any parameter blank leaves that stream alone.

Parameters:
  • stdout – filename to append the standard output stream into.
  • stderr – filename to append the standard error stream into.
  • stdin – filename to read from as the standard input stream.
slimta.util.system.drop_privileges([user=None[, group=None]])

Uses the system calls setuid() and setgid() to drop root privileges to the given user and group. This is useful for security purposes, once root-only ports like 25 are opened.

Parameters:
  • user – user name (from /etc/passwd) or UID.
  • group – group name (from /etc/group) or GID.
class slimta.util.system.PidFile([filename=None])

Bases: object

New in version 0.3.13.

Context manager which creates a PID file containing the current process id, runs the context, and then removes the PID file.

An OSError exceptions when creating the PID file will be propogated without executing the context.

Parameters:filename – The filename to use for the PID file. If None is given, the context is simply executed with no PID file created.