Struct daemonize_me::Daemon
source · pub struct Daemon<'a> { /* private fields */ }
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 -
before_fork_hook [optional], called before the fork with the current pid as argument
-
after_fork_parent_hook [optional], called after the fork with the parent pid as argument, can be used to continue some work on the parent after the fork (do not return)
-
after_fork_child_hook [optional], called after the fork with the parent and child pid as arguments
-
See the setter function documentation for more details
Beware there is no escalation back if dropping privileges
Implementations§
source§impl<'a> Daemon<'a>
impl<'a> Daemon<'a>
pub fn new() -> Self
sourcepub fn pid_file<T: AsRef<Path>>(self, path: T, chmod: Option<bool>) -> Self
pub fn pid_file<T: AsRef<Path>>(self, path: T, chmod: Option<bool>) -> Self
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)
sourcepub fn work_dir<T: AsRef<Path>>(self, path: T) -> Self
pub fn work_dir<T: AsRef<Path>>(self, path: T) -> Self
As the last step the code will change the working directory to this one defaults to /
sourcepub fn user<T: Into<User>>(self, user: T) -> Self
pub fn user<T: Into<User>>(self, user: T) -> Self
The code will attempt to drop privileges with setuid
to the provided user
sourcepub fn group<T: Into<Group>>(self, group: T) -> Self
pub fn group<T: Into<Group>>(self, group: T) -> Self
The code will attempt to drop privileges with setgid
to the provided group, you mut provide a group if you provide an user