Commit b343c270 authored by Stavros Korokithakis's avatar Stavros Korokithakis

Kill IPFS on exit

parent b960e981
......@@ -25,6 +25,9 @@ use std::process::Command;
static DEBOUNCING_DONE: AtomicBool = AtomicBool::new(true);
lazy_static! {
static ref IPFS_PID: Mutex<u32> = Mutex::new(0);
}
lazy_static! {
static ref IPFS_HASHES: Mutex<HashMap<String, String>> = Mutex::new(HashMap::new());
......@@ -130,16 +133,23 @@ fn start_ipfs() {
notify_ipfs(true);
});
let output = Command::new(IPFS_EXECUTABLE)
let mut child = Command::new(IPFS_EXECUTABLE)
.env("IPFS_PATH", &*IPFS_PATH)
.args(&["daemon", "--writable", "--enable-gc", "--migrate"])
.output()
.spawn()
.unwrap_or_else(|_| {
println!("Could not launch IPFS daemon.");
process::exit(1)
});
{
// Manage the lock here.
let mut ipfs_pid = IPFS_PID.lock().unwrap();
*ipfs_pid = child.id();
}
child.wait().expect("Failed to wait on IPFS daemon.");
println!("IPFS daemon died, exiting...");
println!("{:?}", output);
process::exit(1)
}
......
use rouille;
use rouille::Response;
use std::process;
use std::ffi::OsStr;
use std::{thread, time};
use IPFS_HASHES;
use IPFS_PID;
#[derive(RustcEncodable)]
struct ExitResponse {
......@@ -28,6 +30,13 @@ pub fn start_api() {
thread::sleep(time::Duration::from_secs(1));
process::exit(1);
});
let ipfs_pid = {
IPFS_PID.lock().unwrap()
};
process::Command::new("kill")
.args(&[OsStr::new(&*ipfs_pid.to_string())])
.output()
.expect("Could not kill IPFS daemon.");
Response::json(&ExitResponse{result: "ok".to_owned()})
},
(GET) (/api/path/) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment