Struct Daemonize

Source
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 Daemonize<()>

Source

pub fn new() -> Self

Source§

impl<T> Daemonize<T>

Source

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

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

Source

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

Source

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

Change working directory to path or / by default.

Source

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

Drop privileges to user.

Source

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

Drop privileges to group.

Source

pub fn umask(self, mask: mode_t) -> Self

Change umask to mask or 0o027 by default.

Source

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

Change root to path

Source

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.

Source

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.

Source

pub fn stdout<S: Into<Stdio>>(self, stdio: S) -> Self

Configuration for the child process’s standard output stream.

Source

pub fn stderr<S: Into<Stdio>>(self, stdio: S) -> Self

Configuration for the child process’s standard error stream.

Source

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

Start daemonization process.

Trait Implementations§

Source§

impl<T> Debug for Daemonize<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Daemonize<T>

§

impl<T> !RefUnwindSafe for Daemonize<T>

§

impl<T> !Send for Daemonize<T>

§

impl<T> !Sync for Daemonize<T>

§

impl<T> Unpin for Daemonize<T>

§

impl<T> !UnwindSafe for Daemonize<T>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.