aboutsummaryrefslogtreecommitdiff
path: root/src/daemonizer/posix_daemonizer.inl
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemonizer/posix_daemonizer.inl')
-rw-r--r--src/daemonizer/posix_daemonizer.inl12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/daemonizer/posix_daemonizer.inl b/src/daemonizer/posix_daemonizer.inl
index f8be15dda..506c7766f 100644
--- a/src/daemonizer/posix_daemonizer.inl
+++ b/src/daemonizer/posix_daemonizer.inl
@@ -43,6 +43,10 @@ namespace daemonizer
"detach"
, "Run as daemon"
};
+ const command_line::arg_descriptor<std::string> arg_pidfile = {
+ "pidfile"
+ , "File path to write the daemon's PID to (optional, requires --detach)"
+ };
const command_line::arg_descriptor<bool> arg_non_interactive = {
"non-interactive"
, "Run non-interactive"
@@ -55,6 +59,7 @@ namespace daemonizer
)
{
command_line::add_arg(normal_options, arg_detach);
+ command_line::add_arg(normal_options, arg_pidfile);
command_line::add_arg(normal_options, arg_non_interactive);
}
@@ -80,7 +85,12 @@ namespace daemonizer
if (command_line::has_arg(vm, arg_detach))
{
tools::success_msg_writer() << "Forking to background...";
- posix::fork();
+ std::string pidfile;
+ if (command_line::has_arg(vm, arg_pidfile))
+ {
+ pidfile = command_line::get_arg(vm, arg_pidfile);
+ }
+ posix::fork(pidfile);
auto daemon = executor.create_daemon(vm);
return daemon.run();
}