pub struct Daemonize<T> { /* private fields */ }Expand description
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 root directory;
- change the pid-file ownership to provided user (and/or) group;
- execute any provided action just before dropping privileges.
Implementations§
Source§impl<T> Daemonize<T>
impl<T> Daemonize<T>
Sourcepub fn pid_file<F: AsRef<Path>>(self, path: F) -> Self
pub fn pid_file<F: AsRef<Path>>(self, path: F) -> Self
Create pid-file at path, lock it exclusive and write daemon pid.
Sourcepub fn chown_pid_file(self, chown: bool) -> Self
pub 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
Sourcepub fn working_directory<F: AsRef<Path>>(self, path: F) -> Self
pub fn working_directory<F: AsRef<Path>>(self, path: F) -> Self
Change working directory to path or / by default.
Sourcepub fn privileged_action<N, F: Fn() -> N + Sized + 'static>(
self,
action: F,
) -> Daemonize<N>
pub 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.
Sourcepub fn exit_action<F: Fn() + Sized + 'static>(self, action: F) -> Daemonize<T>
pub fn exit_action<F: Fn() + Sized + 'static>(self, action: F) -> Daemonize<T>
Execute action just before exitin from the parent process. Most common usecase is to wait for forked process.
Sourcepub fn stdout<S: Into<Stdio>>(self, stdio: S) -> Self
pub fn stdout<S: Into<Stdio>>(self, stdio: S) -> Self
Configuration for the child process’s standard output stream.
Sourcepub fn stderr<S: Into<Stdio>>(self, stdio: S) -> Self
pub fn stderr<S: Into<Stdio>>(self, stdio: S) -> Self
Configuration for the child process’s standard error stream.
Sourcepub fn start(self) -> Result<T, DaemonizeError>
pub fn start(self) -> Result<T, DaemonizeError>
Start daemonization process.