Browse Source

Some updates

master
Adrian Heine 5 years ago
parent
commit
42d97d6eea
  1. 2
      src/command_runner.rs
  2. 5
      src/symbols/acme/account_key.rs
  3. 3
      src/symbols/mariadb/database_dump.rs
  4. 17
      src/symbols/systemd/node_js_user_service.rs

2
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<Output> {
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);

5
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<Error>> {
self.command_runner.run_successfully("openssl", &["genrsa", "-out", self.get_path(), &self.get_bytes().to_string()])
}
fn get_prerequisites(&self) -> Vec<Resource> {
vec![ Resource::new("dir", Path::new(self.get_path()).parent().unwrap().to_string_lossy() ) ]
}
}
#[cfg(test)]

3
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<bool, Box<Error>> {
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)
}

17
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<Targ
let file_name = format!("/var/tmp/{}-{}.socket", self.user_name, self.service_name);
let metadata = try!(wait_for_metadata(&file_name));
/*
let mut perms = metadata.permissions();
perms.set_mode(0o666);
try!(fs::set_permissions(file_name, perms));
*/
Ok(())
}

Loading…
Cancel
Save