scm daemon, write pid file (to be used for restart after log rotation)

Summary: write pid file

Reviewed By: markbt

Differential Revision: D8331445

fbshipit-source-id: 47492ffc9cc87a2ef228ce9581873dec6e01e369
This commit is contained in:
Liubov Dmitrieva 2018-06-08 06:21:17 -07:00 committed by Facebook Github Bot
parent 63fe3fd2c3
commit 2d82868f9f

View File

@ -17,6 +17,7 @@ use commitcloudsubscriber::{CommitCloudConfig, CommitCloudTcpReceiverService,
CommitCloudWorkspaceSubscriberService};
use std::fs::File;
use std::io::Read;
use std::io::Write;
/// This is what we're going to decode toml config into.
/// Each field is optional, meaning that it doesn't have to be present in TOML.
@ -48,9 +49,16 @@ fn run() -> Result<()> {
.help(help)
.args(&[
Arg::from_usage("--config [config file (toml format)]").required(true),
Arg::from_usage("--pidfile [specify path to pidfile]").required(false),
])
.get_matches();
// write pidfile
// do not rely on existence of this file to check if program running
if let Some(path) = matches.value_of("pidfile") {
File::create(path)?.write_fmt(format_args!("{}", std::process::id()))?;
}
// read required config path
let configfile = matches.value_of("config").unwrap();