pub struct Daemon {
    pub chdir: PathBuf,
    pub pid_file: Option<PathBuf>,
    pub chown_pid_file: bool,
    pub user: Option<User>,
    pub group: Option<Group>,
    pub umask: u16,
    pub stdin: Stdio,
    pub stdout: Stdio,
    pub stderr: Stdio,
    pub name: Option<OsString>,
}
Expand description

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 “/”

  • name [optional], set the daemon process name eg what shows in ps default is to not set a process name

  • See the setter function documentation for more details

Beware there is no escalation back if dropping privileges

Fields

chdir: PathBufpid_file: Option<PathBuf>chown_pid_file: booluser: Option<User>group: Option<Group>umask: u16stdin: Stdiostdout: Stdiostderr: Stdioname: Option<OsString>

Implementations

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)

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

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

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

Using the parameters set, daemonize the process

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.