Various fixes
This commit is contained in:
parent
b49f712b6d
commit
85a2e14fad
3 changed files with 10 additions and 13 deletions
|
|
@ -31,7 +31,7 @@ impl<'a> Symbol for NpmInstall<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute(&self) -> Result<(), Box<Error>> {
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ use std::ops::Deref;
|
||||||
use command_runner::CommandRunner;
|
use command_runner::CommandRunner;
|
||||||
use symbols::Symbol;
|
use symbols::Symbol;
|
||||||
use symbols::file::File as FileSymbol;
|
use symbols::file::File as FileSymbol;
|
||||||
use resources::Resource;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum NodeJsSystemdUserServiceError<E: Error> {
|
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> {
|
pub struct NodeJsSystemdUserService<'a, P, C> where P: AsRef<str> + fmt::Display, C: Deref<Target=str> {
|
||||||
name: &'a str,
|
name: &'a str,
|
||||||
home: &'a str,
|
user_name: &'a str,
|
||||||
uid: u32,
|
|
||||||
path: P,
|
path: P,
|
||||||
command_runner: &'a CommandRunner,
|
command_runner: &'a CommandRunner,
|
||||||
file: FileSymbol<C, Cow<'a, str>>
|
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;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
impl<'a> NodeJsSystemdUserService<'a, Cow<'a, str>, String> {
|
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 file_path: Cow<str> = Cow::from(String::from(home.trim_right()) + "/.config/systemd/user/" + name + ".service");
|
||||||
|
|
||||||
let content = format!("[Service]
|
let content = format!("[Service]
|
||||||
|
|
@ -79,11 +77,10 @@ Environment=PORT=/var/tmp/{1}-{2}.socket
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=default.target
|
WantedBy=default.target
|
||||||
", path, uid, name);
|
", path, user_name, name);
|
||||||
NodeJsSystemdUserService {
|
NodeJsSystemdUserService {
|
||||||
name: name,
|
name: name,
|
||||||
uid: uid,
|
user_name: user_name,
|
||||||
home: home,
|
|
||||||
path: file_path.clone(),
|
path: file_path.clone(),
|
||||||
command_runner: command_runner,
|
command_runner: command_runner,
|
||||||
file: FileSymbol::new(file_path, content)
|
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
|
// Check if service is registered
|
||||||
let active_state = try!(self.command_runner.run_with_args("systemctl", &["--user", "show", "--property", "ActiveState", self.name]));
|
let active_state = try!(self.command_runner.run_with_args("systemctl", &["--user", "show", "--property", "ActiveState", self.name]));
|
||||||
if !active_state.status.success() {
|
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
|
// Check if service is running
|
||||||
match String::from_utf8(active_state.stdout).unwrap().trim_right() {
|
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()));
|
// try!(create_dir_all(Path::new(&path).parent().unwrap()));
|
||||||
match self.file.execute() {
|
match self.file.execute() {
|
||||||
Ok(_) => {},
|
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", "enable", self.name]));
|
||||||
try!(self.command_runner.run_with_args("systemctl", &["--user", "start", 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>)); }
|
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]));
|
// try!(self.command_runner.run_with_args("chmod", &["666", &file_name]));
|
||||||
|
|
||||||
sleep(Duration::from_millis(500));
|
sleep(Duration::from_millis(500));
|
||||||
|
|
|
||||||
|
|
@ -188,13 +188,13 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_target_reached_nonexisting() {
|
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);
|
assert_eq!(symbol.target_reached().unwrap(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_target_reached_root() {
|
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);
|
assert_eq!(symbol.target_reached().unwrap(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue