Browse Source

Various fixes

master
Adrian Heine 7 years ago
parent
commit
85a2e14fad
  1. 2
      src/symbols/npm.rs
  2. 17
      src/symbols/systemd/node_js_user_service.rs
  3. 4
      src/symbols/user.rs

2
src/symbols/npm.rs

@ -31,7 +31,7 @@ impl<'a> Symbol for NpmInstall<'a> {
}
fn execute(&self) -> Result<(), Box<Error>> {
try!(self.command_runner.run_with_args("sh", &["-c", &format!("cd '{}' && npm install --production", self.target)]));
try!(self.command_runner.run_with_args("sh", &["-c", &format!("cd '{}' && npm install --production --unsafe-perm", self.target)]));
Ok(())
}
}

17
src/symbols/systemd/node_js_user_service.rs

@ -12,7 +12,6 @@ use std::ops::Deref;
use command_runner::CommandRunner;
use symbols::Symbol;
use symbols::file::File as FileSymbol;
use resources::Resource;
#[derive(Debug)]
pub enum NodeJsSystemdUserServiceError<E: Error> {
@ -55,8 +54,7 @@ impl<E: Error> fmt::Display for NodeJsSystemdUserServiceError<E> {
pub struct NodeJsSystemdUserService<'a, P, C> where P: AsRef<str> + fmt::Display, C: Deref<Target=str> {
name: &'a str,
home: &'a str,
uid: u32,
user_name: &'a str,
path: P,
command_runner: &'a CommandRunner,
file: FileSymbol<C, Cow<'a, str>>
@ -65,7 +63,7 @@ pub struct NodeJsSystemdUserService<'a, P, C> where P: AsRef<str> + fmt::Display
use std::borrow::Cow;
impl<'a> NodeJsSystemdUserService<'a, Cow<'a, str>, String> {
pub fn new(home: &'a str, uid: u32, name: &'a str, path: &'a str, command_runner: &'a CommandRunner) -> Self {
pub fn new(home: &'a str, user_name: &'a str, name: &'a str, path: &'a str, command_runner: &'a CommandRunner) -> Self {
let file_path: Cow<str> = Cow::from(String::from(home.trim_right()) + "/.config/systemd/user/" + name + ".service");
let content = format!("[Service]
@ -79,11 +77,10 @@ Environment=PORT=/var/tmp/{1}-{2}.socket
[Install]
WantedBy=default.target
", path, uid, name);
", path, user_name, name);
NodeJsSystemdUserService {
name: name,
uid: uid,
home: home,
user_name: user_name,
path: file_path.clone(),
command_runner: command_runner,
file: FileSymbol::new(file_path, content)
@ -97,7 +94,7 @@ impl<'a, P, C> NodeJsSystemdUserService<'a, P, C> where P: AsRef<str> + fmt::Dis
// Check if service is registered
let active_state = try!(self.command_runner.run_with_args("systemctl", &["--user", "show", "--property", "ActiveState", self.name]));
if !active_state.status.success() {
return Ok(false);
return Err(String::from_utf8(active_state.stderr).unwrap().trim_right().into());
}
// Check if service is running
match String::from_utf8(active_state.stdout).unwrap().trim_right() {
@ -131,14 +128,14 @@ impl<'a, P, C> Symbol for NodeJsSystemdUserService<'a, P, C> where P: AsRef<str>
// try!(create_dir_all(Path::new(&path).parent().unwrap()));
match self.file.execute() {
Ok(_) => {},
Err(e) => return Err(Box::new(NodeJsSystemdUserServiceError::GenericError as NodeJsSystemdUserServiceError<io::Error>))
Err(e) => return Err(e)
}
try!(self.command_runner.run_with_args("systemctl", &["--user", "enable", self.name]));
try!(self.command_runner.run_with_args("systemctl", &["--user", "start", self.name]));
if !(try!(self.check_if_service())) { return Err(Box::new(NodeJsSystemdUserServiceError::GenericError as NodeJsSystemdUserServiceError<io::Error>)); }
let file_name = format!("/var/tmp/{}-{}.socket", self.uid, self.name);
let file_name = format!("/var/tmp/{}-{}.socket", self.user_name, self.name);
// try!(self.command_runner.run_with_args("chmod", &["666", &file_name]));
sleep(Duration::from_millis(500));

4
src/symbols/user.rs

@ -188,13 +188,13 @@ mod test {
#[test]
fn test_target_reached_nonexisting() {
let symbol = User { user_name: "nonexisting", command_runner: &StdCommandRunner, user_adder: &DummyUserAdder };
let symbol = User { user_name: "nonexisting".into(), command_runner: &StdCommandRunner, user_adder: &DummyUserAdder };
assert_eq!(symbol.target_reached().unwrap(), false);
}
#[test]
fn test_target_reached_root() {
let symbol = User { user_name: "root", command_runner: &StdCommandRunner, user_adder: &DummyUserAdder };
let symbol = User { user_name: "root".into(), command_runner: &StdCommandRunner, user_adder: &DummyUserAdder };
assert_eq!(symbol.target_reached().unwrap(), true);
}
}
Loading…
Cancel
Save