[][src]Struct daemonize_me::Daemon

pub struct Daemon { /* fields omitted */ }

Basic daemonization consists of: forking the process, getting a new sid, setting the umask, changing the standard io streams to files and finally dropping privileges.

Options:

  • user [optional], if set will drop privileges to the specified user NOTE: This library is strict and makes no assumptions if you provide a user you must provide a group
  • group [optional(see note on user)], if set will drop privileges to specified group
  • umask [optional], umask for the process defaults to 0o027
  • pid_file [optional], if set a pid file will be created default is that no file is created *
  • stdio [optional][recommended], this determines where standard output will be piped to since daemons have no console it's highly recommended to set this
  • stderr [optional][recommended], same as above but for standard error
  • chdir [optional], default is "/"

* See the setter function documentation for more details

Beware there is no escalation back if dropping privileges TODO:

  • [ ] Add chroot option
  • [ ] Add before drop lambda

Implementations

impl Daemon[src]

pub fn new() -> Self[src]

pub fn pid_file<T: AsRef<Path>>(self, path: T, chmod: Option<bool>) -> Self[src]

This is a setter to give your daemon a pid file

Arguments

  • path - path to the file suggested /var/run/my_program_name.pid
  • chmod - if set a chmod of the file to the user and group passed will be attempted (this being true makes setting an user and group mandatory)

pub fn work_dir<T: AsRef<Path>>(self, path: T) -> Self[src]

As the last step the code will change the working directory to this one defaults to /

pub fn user<T: Into<User>>(self, user: T) -> Self[src]

The code will attempt to drop privileges with setuid to the provided user

pub fn group<T: Into<Group>>(self, group: T) -> Self[src]

The code will attempt to drop privileges with setgid to the provided group, you mut provide a group if you provide an user

pub fn umask(self, mask: u16) -> Self[src]

pub fn stdin<T: Into<Stdio>>(self, stdio: T) -> Self[src]

pub fn stdout<T: Into<Stdio>>(self, stdio: T) -> Self[src]

pub fn stderr<T: Into<Stdio>>(self, stdio: T) -> Self[src]

pub fn start(self) -> Result<()>[src]

Using the parameters set daemonize the process

Auto Trait Implementations

impl RefUnwindSafe for Daemon

impl Send for Daemon

impl Sync for Daemon

impl Unpin for Daemon

impl UnwindSafe for Daemon

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.