pub struct Daemonizr { /* private fields */ }
Expand description
Daemonizr holds context needed for spawning the daemon process.
It includes:
- working directory of the daemon;
- UID and GID to be set to after going daemon;
- umask which daemon uses after dropping the privileges;
- the PID file to use;
- setup for stdout/stderr files
Implementations§
source§impl Daemonizr
impl Daemonizr
Super
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new default Daemonizr context with following attributes:
- current directory is used as working directory;
- current user and his default group used for daemon;
- the umask() is set to 0 (means creation mode = 777);
- PID file “daemonizr.pid” in current directory is used as PID file;
- the stdout and stderr are both closed.
sourcepub fn work_dir(self, work_dir: PathBuf) -> Result<Self, DaemonizrError>
pub fn work_dir(self, work_dir: PathBuf) -> Result<Self, DaemonizrError>
Path to working directory for the daemon, this path must be a directory, must exist AND be an absolute path.
sourcepub fn umask(self, umask: u16) -> Result<Self, DaemonizrError>
pub fn umask(self, umask: u16) -> Result<Self, DaemonizrError>
Umask to use for daemon
sourcepub fn pidfile(self, pidfile: PathBuf) -> Self
pub fn pidfile(self, pidfile: PathBuf) -> Self
Path for the pidfile. If path is a relative path, it is assumed to be relative to the working directory.
sourcepub fn stdout(self, s: Stdout) -> Self
pub fn stdout(self, s: Stdout) -> Self
Set behaviour for standard output: close or redirect to the given path.
sourcepub fn stderr(self, s: Stderr) -> Self
pub fn stderr(self, s: Stderr) -> Self
Set behaviour for standard error: close or redirect to the given path.
sourcepub fn spawn(self) -> Result<(), DaemonizrError>
pub fn spawn(self) -> Result<(), DaemonizrError>
Perform the actual creation of a daemon process. In case of success, this function never returns - the parent process will exit with exit code 0 (success), the child (daemon) process will
sourcepub fn search(self) -> Result<u32, DaemonizrError>
pub fn search(self) -> Result<u32, DaemonizrError>
Search for PID of an already spawned daemon. If one is present, its PID is returned, otherwise an error is returned.
Hint: for search, you’ll need to set at least absolute path with Self::pidfile()
,
or, set absolute path using Self::work_dir()
in conjuction with setting a relative
path using Self::pidfile()
.