Struct daemonize_me::daemon::Daemon
source · [−]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
psdefault 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.pidchmod- 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