diff options
author | Erik de Castro Lopo <erikd@mega-nerd.com> | 2017-07-19 21:45:00 +1000 |
---|---|---|
committer | Erik de Castro Lopo <erikd@mega-nerd.com> | 2017-07-22 08:34:56 +1000 |
commit | 51efb21713ee630ca9c2f6aaaea98f18bce72106 (patch) | |
tree | e83f41547dff0da048f980ab21175a3257240eee /src/daemonizer/posix_daemonizer.inl | |
parent | Merge pull request #2159 (diff) | |
download | monero-51efb21713ee630ca9c2f6aaaea98f18bce72106.tar.xz |
daemon: Add ability to write a PID file
The PID file will only be written if the daemon is called with the
`--detach` command line argument and a `--pidfile /some/file/path`
argument.
Diffstat (limited to 'src/daemonizer/posix_daemonizer.inl')
-rw-r--r-- | src/daemonizer/posix_daemonizer.inl | 12 |
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(); } |