diff --git a/src/command_runner.rs b/src/command_runner.rs index bfdd35e..8a29799 100644 --- a/src/command_runner.rs +++ b/src/command_runner.rs @@ -82,7 +82,7 @@ impl<'a> Drop for TempSetEnv<'a> { impl<'a, C> CommandRunner for SetuidCommandRunner<'a, C> where C: 'a + CommandRunner { fn run_with_args(&self, program: &str, args: &[&str]) -> IoResult { - let uid = get_user_by_name(self.user_name).unwrap().uid(); + let uid = get_user_by_name(self.user_name).expect("User does not exist").uid(); let set_home = TempSetEnv::new("HOME", format!("/home/{}", self.user_name)); let set_dbus = TempSetEnv::new("XDG_RUNTIME_DIR", format!("/run/user/{}", uid)); println!("{} {:?}", program, args); diff --git a/src/symbols/acme/account_key.rs b/src/symbols/acme/account_key.rs index 1e5da2f..c619cd6 100644 --- a/src/symbols/acme/account_key.rs +++ b/src/symbols/acme/account_key.rs @@ -4,6 +4,7 @@ use std::fmt; use std::path::Path; use command_runner::CommandRunner; +use resources::Resource; use symbols::Symbol; pub struct AcmeAccountKey<'a> { @@ -46,6 +47,10 @@ impl<'a> Symbol for AcmeAccountKey<'a> { fn execute(&self) -> Result<(), Box> { self.command_runner.run_successfully("openssl", &["genrsa", "-out", self.get_path(), &self.get_bytes().to_string()]) } + + fn get_prerequisites(&self) -> Vec { + vec![ Resource::new("dir", Path::new(self.get_path()).parent().unwrap().to_string_lossy() ) ] + } } #[cfg(test)] diff --git a/src/symbols/mariadb/database_dump.rs b/src/symbols/mariadb/database_dump.rs index a304b02..d582502 100644 --- a/src/symbols/mariadb/database_dump.rs +++ b/src/symbols/mariadb/database_dump.rs @@ -30,7 +30,7 @@ impl<'a, S> DatabaseDump<'a, S> where S: Storage { impl<'a, S> fmt::Display for DatabaseDump<'a, S> where S: Storage { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "MariaDB Database {}", self.db_name) + write!(f, "Dump MariaDB Database {}", self.db_name) } } @@ -38,6 +38,7 @@ impl<'a, S> Symbol for DatabaseDump<'a, S> where S: Storage { fn target_reached(&self) -> Result> { let dump_date = try!(self.storage.recent_date()); let modified_date = try!(self.run_sql(&format!("select UNIX_TIMESTAMP(MAX(UPDATE_TIME)) from information_schema.tables WHERE table_schema = '{}'", self.db_name))); + if modified_date.trim_right() == "NULL" { return Ok(false); } Ok(try!(u64::from_str(modified_date.trim_right())) <= dump_date) } diff --git a/src/symbols/systemd/node_js_user_service.rs b/src/symbols/systemd/node_js_user_service.rs index ff8a176..91ddc6c 100644 --- a/src/symbols/systemd/node_js_user_service.rs +++ b/src/symbols/systemd/node_js_user_service.rs @@ -63,20 +63,23 @@ impl<'a, R> NodeJsSystemdUserService<'a, String, SetuidCommandRunner<'a, R>> whe pub fn new(home: &'a str, user_name: &'a str, name: &'a str, path: &'a str, command_runner: &'a R) -> Self { let file_path = format!("{}/.config/systemd/user/{}.service", home.trim_right(), name); + let port = format!("/var/tmp/{}-{}.socket", user_name, name); let content = format!("[Service] -ExecStartPre=/bin/rm -f /var/tmp/{1}-{2}.socket -# This only works if the path is a directory -WorkingDirectory={0} +Environment=NODE_ENV=production +Environment=PORT={1} +ExecStartPre=/bin/rm -f {1} ExecStart=/usr/bin/nodejs {0} +ExecStartPost=/bin/sh -c 'sleep 1 && chmod 666 {1}' + +# FIXME: This only works if the nodejs path is a directory +WorkingDirectory={0} Restart=always -Environment=NODE_ENV=production -Environment=PORT=/var/tmp/{1}-{2}.socket #RuntimeDirectory=service #RuntimeDirectoryMode=766 [Install] WantedBy=default.target -", path, user_name, name); +", path, port); NodeJsSystemdUserService { service_name: name, @@ -167,9 +170,11 @@ impl<'a, C, R> Symbol for NodeJsSystemdUserService<'a, C, R> where C: Deref