Struct daemonizr::Daemonizr

source ·
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

Super

source

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.
source

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.

source

pub fn as_user(self, user: User) -> Self

User to be set after going daemon

source

pub fn as_group(self, group: Group) -> Self

Group to be set after going daemon

source

pub fn umask(self, umask: u16) -> Result<Self, DaemonizrError>

Umask to use for daemon

source

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.

source

pub fn stdout(self, s: Stdout) -> Self

Set behaviour for standard output: close or redirect to the given path.

source

pub fn stderr(self, s: Stderr) -> Self

Set behaviour for standard error: close or redirect to the given path.

source

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

source

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().

Trait Implementations§

source§

impl Debug for Daemonizr

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.