2016-11-25 17:34:00 -05:00
|
|
|
// This file is part of Moonfire NVR, a security camera digital video recorder.
|
|
|
|
// Copyright (C) 2016 Scott Lamb <slamb@slamb.org>
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// In addition, as a special exception, the copyright holders give
|
|
|
|
// permission to link the code of portions of this program with the
|
|
|
|
// OpenSSL library under certain conditions as described in each
|
|
|
|
// individual source file, and distribute linked combinations including
|
|
|
|
// the two.
|
|
|
|
//
|
|
|
|
// You must obey the GNU General Public License in all respects for all
|
|
|
|
// of the code used other than OpenSSL. If you modify file(s) with this
|
|
|
|
// exception, you may extend this exception to your version of the
|
|
|
|
// file(s), but you are not obligated to do so. If you do not wish to do
|
|
|
|
// so, delete this exception statement from your version. If you delete
|
|
|
|
// this exception statement from all source files in the program, then
|
|
|
|
// also delete it here.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-01-08 17:22:35 -05:00
|
|
|
#![cfg_attr(all(feature="nightly", test), feature(test))]
|
2016-11-25 17:34:00 -05:00
|
|
|
|
|
|
|
extern crate byteorder;
|
|
|
|
extern crate core;
|
|
|
|
extern crate docopt;
|
2017-03-02 22:29:28 -05:00
|
|
|
extern crate futures;
|
2016-11-25 17:34:00 -05:00
|
|
|
extern crate fnv;
|
2016-12-20 21:29:45 -05:00
|
|
|
extern crate http_entity;
|
2016-11-25 17:34:00 -05:00
|
|
|
extern crate hyper;
|
|
|
|
#[macro_use] extern crate lazy_static;
|
|
|
|
extern crate libc;
|
|
|
|
#[macro_use] extern crate log;
|
|
|
|
extern crate lru_cache;
|
2017-03-02 22:29:28 -05:00
|
|
|
extern crate reffers;
|
2016-11-25 17:34:00 -05:00
|
|
|
extern crate rusqlite;
|
|
|
|
extern crate memmap;
|
2017-06-11 15:57:55 -04:00
|
|
|
extern crate mime;
|
2017-09-21 00:06:06 -04:00
|
|
|
extern crate moonfire_ffmpeg;
|
2017-03-26 03:01:48 -04:00
|
|
|
extern crate mylog;
|
2016-11-25 17:34:00 -05:00
|
|
|
extern crate openssl;
|
2017-03-02 22:29:28 -05:00
|
|
|
extern crate parking_lot;
|
2016-11-25 17:34:00 -05:00
|
|
|
extern crate regex;
|
|
|
|
extern crate serde;
|
2017-02-05 23:13:51 -05:00
|
|
|
#[macro_use] extern crate serde_derive;
|
2016-11-25 17:34:00 -05:00
|
|
|
extern crate serde_json;
|
|
|
|
extern crate smallvec;
|
|
|
|
extern crate time;
|
2017-03-02 22:29:28 -05:00
|
|
|
extern crate tokio_core;
|
|
|
|
extern crate tokio_signal;
|
2016-11-25 17:34:00 -05:00
|
|
|
extern crate url;
|
|
|
|
extern crate uuid;
|
|
|
|
|
2016-12-06 21:41:44 -05:00
|
|
|
mod clock;
|
2017-01-03 13:33:53 -05:00
|
|
|
mod coding;
|
2017-01-16 15:50:47 -05:00
|
|
|
mod cmds;
|
2016-11-25 17:34:00 -05:00
|
|
|
mod db;
|
|
|
|
mod dir;
|
|
|
|
mod error;
|
|
|
|
mod h264;
|
2017-02-05 23:13:51 -05:00
|
|
|
mod json;
|
2016-11-25 17:34:00 -05:00
|
|
|
mod mp4;
|
|
|
|
mod recording;
|
2017-02-21 22:37:36 -05:00
|
|
|
mod slices;
|
2016-11-25 17:34:00 -05:00
|
|
|
mod stream;
|
|
|
|
mod streamer;
|
2016-12-09 00:28:50 -05:00
|
|
|
mod strutil;
|
2016-11-25 17:34:00 -05:00
|
|
|
#[cfg(test)] mod testutil;
|
|
|
|
mod web;
|
|
|
|
|
|
|
|
/// Commandline usage string. This is in the particular format expected by the `docopt` crate.
|
|
|
|
/// Besides being printed on --help or argument parsing error, it's actually parsed to define the
|
|
|
|
/// allowed commandline arguments and their defaults.
|
|
|
|
const USAGE: &'static str = "
|
2017-01-16 15:50:47 -05:00
|
|
|
Usage: moonfire-nvr <command> [<args>...]
|
2016-11-25 17:34:00 -05:00
|
|
|
moonfire-nvr (--help | --version)
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-h, --help Show this message.
|
|
|
|
--version Show the version of moonfire-nvr.
|
2017-01-16 15:50:47 -05:00
|
|
|
|
|
|
|
Commands:
|
|
|
|
check Check database integrity
|
2017-01-16 17:21:08 -05:00
|
|
|
init Initialize a database
|
2017-03-26 03:01:48 -04:00
|
|
|
run Run the daemon: record from cameras and serve HTTP
|
2017-02-05 22:58:41 -05:00
|
|
|
shell Start an interactive shell to modify the database
|
2017-03-26 03:01:48 -04:00
|
|
|
ts Translate human-readable and numeric timestamps
|
2017-01-16 17:21:08 -05:00
|
|
|
upgrade Upgrade the database to the latest schema
|
2016-11-25 17:34:00 -05:00
|
|
|
";
|
|
|
|
|
|
|
|
/// Commandline arguments corresponding to `USAGE`; automatically filled by the `docopt` crate.
|
2017-06-11 15:57:55 -04:00
|
|
|
#[derive(Debug, Deserialize)]
|
2016-11-25 17:34:00 -05:00
|
|
|
struct Args {
|
2017-01-16 15:50:47 -05:00
|
|
|
arg_command: Option<cmds::Command>,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn version() -> String {
|
|
|
|
let major = option_env!("CARGO_PKG_VERSION_MAJOR");
|
|
|
|
let minor = option_env!("CARGO_PKG_VERSION_MAJOR");
|
|
|
|
let patch = option_env!("CARGO_PKG_VERSION_MAJOR");
|
|
|
|
match (major, minor, patch) {
|
|
|
|
(Some(major), Some(minor), Some(patch)) => format!("{}.{}.{}", major, minor, patch),
|
|
|
|
_ => "".to_owned(),
|
|
|
|
}
|
2016-11-25 17:34:00 -05:00
|
|
|
}
|
|
|
|
|
2017-03-26 03:01:48 -04:00
|
|
|
fn parse_fmt<S: AsRef<str>>(fmt: S) -> Option<mylog::Format> {
|
|
|
|
match fmt.as_ref() {
|
|
|
|
"google" => Some(mylog::Format::Google),
|
|
|
|
"google-systemd" => Some(mylog::Format::GoogleSystemd),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-25 17:34:00 -05:00
|
|
|
fn main() {
|
2016-12-21 01:08:18 -05:00
|
|
|
// Parse commandline arguments.
|
2017-01-16 15:50:47 -05:00
|
|
|
// (Note this differs from cmds::parse_args in that it specifies options_first.)
|
2016-12-21 01:08:18 -05:00
|
|
|
let args: Args = docopt::Docopt::new(USAGE)
|
2017-01-16 15:50:47 -05:00
|
|
|
.and_then(|d| d.options_first(true)
|
|
|
|
.version(Some(version()))
|
2017-06-11 15:57:55 -04:00
|
|
|
.deserialize())
|
2016-12-21 01:08:18 -05:00
|
|
|
.unwrap_or_else(|e| e.exit());
|
|
|
|
|
2017-03-26 03:01:48 -04:00
|
|
|
let mut h = mylog::Builder::new()
|
|
|
|
.set_format(::std::env::var("MOONFIRE_FORMAT")
|
|
|
|
.ok()
|
|
|
|
.and_then(parse_fmt)
|
|
|
|
.unwrap_or(mylog::Format::Google))
|
|
|
|
.set_spec(&::std::env::var("MOONFIRE_LOG").unwrap_or("info".to_owned()))
|
|
|
|
.build();
|
|
|
|
h.clone().install().unwrap();
|
|
|
|
|
|
|
|
if let Err(e) = { let _a = h.async(); args.arg_command.unwrap().run() } {
|
|
|
|
error!("{}", e);
|
2017-01-16 15:50:47 -05:00
|
|
|
::std::process::exit(1);
|
2016-11-25 17:34:00 -05:00
|
|
|
}
|
2017-03-26 03:01:48 -04:00
|
|
|
info!("Success.");
|
2016-11-25 17:34:00 -05:00
|
|
|
}
|