Merge server and adm to single binary.

This commit is contained in:
Rasmus Kaj 2017-09-01 23:14:17 +02:00
parent 97076336a6
commit 8131f5e5ec
6 changed files with 59 additions and 72 deletions

View File

@ -8,10 +8,6 @@ build = "src/build.rs"
[build-dependencies]
ructe = { version = "^0.3.2", features = ["sass", "mime02"] }
[[bin]]
name = "rphotoserver"
path = "src/main.rs"
[[bin]]
name = "rphotosadm"
path = "src/rphotosadm.rs"

View File

@ -4,6 +4,7 @@ use flate2::{Compression, FlateWriteExt};
use std::fs::{File, create_dir_all};
use std::io::prelude::*;
use std::path::Path;
use templates::statics::STATICS;
pub fn to_dir(dir: &str) -> Result<(), Error> {
let dir: &Path = dir.as_ref();
@ -22,5 +23,3 @@ pub fn to_dir(dir: &str) -> Result<(), Error> {
}
Ok(())
}
include!(concat!(env!("OUT_DIR"), "/templates/statics.rs"));

View File

@ -1,4 +1,3 @@
//! Just fooling around with different ways to count images per year.
extern crate rphotos;
extern crate brotli2;
extern crate clap;
@ -9,8 +8,20 @@ extern crate djangohashers;
extern crate dotenv;
extern crate env_logger;
extern crate flate2;
extern crate hyper;
extern crate libc;
extern crate memcached;
#[macro_use]
extern crate nickel;
extern crate nickel_jwt_session;
extern crate plugin;
extern crate r2d2;
extern crate r2d2_diesel;
extern crate rand;
extern crate regex;
extern crate rexif;
extern crate time;
extern crate typemap;
#[macro_use]
extern crate log;
extern crate image;
@ -18,7 +29,13 @@ extern crate xml;
mod adm;
mod env;
mod memcachemiddleware;
mod nickel_diesel;
mod photosdir;
mod photosdirmiddleware;
mod pidfiles;
mod requestloggermiddleware;
mod server;
use adm::{findphotos, makepublic, readkpa, users, storestatics};
use adm::result::Error;
@ -34,6 +51,8 @@ use std::io::{self, BufReader};
use std::path::Path;
use std::process::exit;
pub use server::{Coord, Group, Link};
fn main() {
dotenv().ok();
env_logger::init().unwrap();
@ -74,6 +93,18 @@ fn main() {
.arg(Arg::with_name("DIR")
.required(true)
.help("Directory to store the files in")))
.subcommand(SubCommand::with_name("runserver")
.about("RPhotos web server")
.version(env!("CARGO_PKG_VERSION"))
.arg(Arg::with_name("PIDFILE")
.long("pidfile")
.takes_value(true)
.help("Write (and read, if --replace) a pid file with the \
name given as <PIDFILE>."))
.arg(Arg::with_name("REPLACE")
.long("replace")
.help("Kill old server (identified by pid file) \
before running")))
.get_matches();
match run(args) {
@ -136,6 +167,9 @@ fn run(args: ArgMatches) -> Result<(), Error> {
("storestatics", Some(args)) => {
storestatics::to_dir(args.value_of("DIR").unwrap())
}
("runserver", Some(args)) => {
server::run(args)
}
_ => Ok(println!("No subcommand given.\n\n{}", args.usage())),
}
}
@ -143,3 +177,5 @@ fn run(args: ArgMatches) -> Result<(), Error> {
fn get_db() -> Result<PgConnection, ConnectionError> {
PgConnection::establish(&dburl())
}
include!(concat!(env!("OUT_DIR"), "/templates.rs"));

View File

@ -1,33 +1,17 @@
#[macro_use]
extern crate nickel;
#[macro_use]
extern crate log;
extern crate djangohashers;
extern crate env_logger;
extern crate nickel_jwt_session;
extern crate typemap;
extern crate plugin;
extern crate image;
extern crate hyper;
extern crate time;
extern crate chrono;
extern crate clap;
extern crate libc;
extern crate rexif;
extern crate rphotos;
extern crate r2d2;
extern crate diesel;
extern crate r2d2_diesel;
extern crate dotenv;
extern crate memcached;
extern crate regex;
mod nickelext;
mod views_by_date;
use adm::result::Error;
use chrono::Datelike;
use clap::{App, Arg};
use clap::ArgMatches;
use diesel::pg::PgConnection;
use diesel;
use diesel::prelude::*;
use dotenv::dotenv;
use djangohashers;
use hyper::header::ContentType;
use image;
use memcachemiddleware::MemcacheMiddleware;
use nickel::{Action, Continue, FormBody, Halt, HttpRouter, MediaType,
MiddlewareResult, Nickel, NickelError, QueryString, Request,
Response};
@ -39,63 +23,36 @@ use nickel_jwt_session::{SessionMiddleware, SessionRequestExtensions,
use r2d2::NopErrorHandler;
use rphotos::models::{Person, Photo, Place, Tag};
mod env;
use env::{dburl, env_or, jwt_key, photos_dir};
mod nickel_diesel;
mod photosdir;
mod requestloggermiddleware;
use requestloggermiddleware::RequestLoggerMiddleware;
mod photosdirmiddleware;
use photosdirmiddleware::{PhotosDirMiddleware, PhotosDirRequestExtensions};
mod memcachemiddleware;
use memcachemiddleware::*;
mod pidfiles;
use pidfiles::handle_pid_file;
use templates;
#[macro_use]
mod nickelext;
use nickelext::{FromSlug, MyResponse, far_expires};
use self::nickelext::{FromSlug, MyResponse, far_expires};
mod views_by_date;
use views_by_date::*;
use self::views_by_date::*;
#[derive(Debug, Clone)]
pub struct Group {
title: String,
url: String,
count: i64,
photo: Photo,
pub title: String,
pub url: String,
pub count: i64,
pub photo: Photo,
}
#[derive(Debug, Clone)]
pub struct Coord {
x: f64,
y: f64,
pub x: f64,
pub y: f64,
}
fn main() {
dotenv().ok();
env_logger::init().unwrap();
info!("Initalized logger");
let args = App::new("rphotoserver")
.about("RPhotos web server")
.version(env!("CARGO_PKG_VERSION"))
.arg(Arg::with_name("PIDFILE")
.long("pidfile")
.takes_value(true)
.help("Write (and read, if --replace) a pid file with the name \
given as <PIDFILE>."))
.arg(Arg::with_name("REPLACE")
.long("replace")
.help("Kill old server (identified by pid file) before running"))
.get_matches();
pub fn run(args: &ArgMatches) -> Result<(), Error> {
if let Some(pidfile) = args.value_of("PIDFILE") {
handle_pid_file(pidfile, args.is_present("REPLACE"))
.unwrap()
@ -136,7 +93,8 @@ fn main() {
server.handle_error(custom_handler);
server.listen(&*env_or("RPHOTOS_LISTEN", "127.0.0.1:6767"))
.expect("listen");
.map_err(|e| Error::Other(format!("listen: {}", e)))?;
Ok(())
}
@ -551,5 +509,3 @@ impl Link {
}
}
}
include!(concat!(env!("OUT_DIR"), "/templates.rs"));

View File

@ -7,7 +7,7 @@ use diesel::prelude::*;
use nickel::{MiddlewareResult, Request, Response};
use nickel_diesel::DieselRequestExtensions;
use nickel_jwt_session::SessionRequestExtensions;
use nickelext::MyResponse;
use server::nickelext::MyResponse;
use rphotos::models::Photo;
use templates;
use time;