Struct daemonize::Daemonize [] [src]

pub struct Daemonize<T> {
    // some fields omitted
}

Daemonization options.

Fork the process in the background, disassociate from its process group and the control terminal. Change umask value to 0o027, redirect all standard streams to /dev/null. Change working directory to / or provided value.

Optionally:

  • maintain and lock the pid-file;
  • drop user privileges;
  • drop group privileges;
  • change the pid-file ownership to provided user (and/or) group;
  • execute any provided action just before dropping privileges.

Methods

impl Daemonize<()>
[src]

fn new() -> Self

impl<T> Daemonize<T>
[src]

fn pid_file<F: AsRef<Path>>(self, path: F) -> Self

Create pid-file at path, lock it exclusive and write daemon pid.

fn chown_pid_file(self, chown: bool) -> Self

If chown is true, daemonize will change the pid-file ownership, if user or group are provided

fn working_directory<F: AsRef<Path>>(self, path: F) -> Self

Change working directory to path or / by default.

fn user<U: Into<User>>(self, user: U) -> Self

Drop privileges to user.

fn group<G: Into<Group>>(self, group: G) -> Self

Drop privileges to group.

fn privileged_action<N, F: Fn() -> N + Sized + 'static>(self, action: F) -> Daemonize<N>

Execute action just before dropping privileges. Most common usecase is to open listening socket. Result of action execution will be returned by start method.

fn start(self) -> Result<T, DaemonizeError>

Start daemonization process.