Remove symbol error type

This commit is contained in:
Adrian Heine 2017-02-07 13:54:06 +01:00
parent 55f2cfae95
commit 4be608a002
10 changed files with 85 additions and 108 deletions

View file

@ -86,7 +86,7 @@ WantedBy=default.target
}
impl<'a, P, C> NodeJsSystemdUserService<'a, P, C> where P: AsRef<str> + fmt::Display, C: Deref<Target=str> {
fn check_if_service(&self) -> Result<bool, <Self as Symbol>::Error> {
fn check_if_service(&self) -> Result<bool, Box<Error>> {
loop {
// Check if service is registered
let active_state = try!(self.command_runner.run_with_args("systemctl", &["--user", "show", "--property", "ActiveState", self.name]));
@ -97,7 +97,7 @@ impl<'a, P, C> NodeJsSystemdUserService<'a, P, C> where P: AsRef<str> + fmt::Dis
match String::from_utf8(active_state.stdout).unwrap().trim_right() {
"ActiveState=activating" => sleep(Duration::from_millis(500)),
"ActiveState=active" => return Ok(true),
"ActiveState=failed" => return Err(NodeJsSystemdUserServiceError::ActivationFailed(self.command_runner.run_with_args("journalctl", &["--user", &format!("--user-unit={}", self.name)]))),
"ActiveState=failed" => return Err(Box::new(NodeJsSystemdUserServiceError::ActivationFailed(self.command_runner.run_with_args("journalctl", &["--user", &format!("--user-unit={}", self.name)])) as NodeJsSystemdUserServiceError<io::Error>)),
_ => return Ok(false)
}
}
@ -105,12 +105,11 @@ impl<'a, P, C> NodeJsSystemdUserService<'a, P, C> where P: AsRef<str> + fmt::Dis
}
impl<'a, P, C> Symbol for NodeJsSystemdUserService<'a, P, C> where P: AsRef<str> + fmt::Display, C: Deref<Target=str> {
type Error = NodeJsSystemdUserServiceError<io::Error>;
fn target_reached(&self) -> Result<bool, Self::Error> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
match self.file.target_reached() {
Ok(false) => return Ok(false),
Ok(true) => {},
Err(e) => return Err(NodeJsSystemdUserServiceError::GenericError)
Err(e) => return Err(Box::new(NodeJsSystemdUserServiceError::GenericError as NodeJsSystemdUserServiceError<io::Error>))
}
/*
if !(try!(self.file.target_reached())) {
@ -120,7 +119,7 @@ impl<'a, P, C> Symbol for NodeJsSystemdUserService<'a, P, C> where P: AsRef<str>
self.check_if_service()
}
fn execute(&self) -> Result<(), Self::Error> {
fn execute(&self) -> Result<(), Box<Error>> {
try!(self.command_runner.run_with_args("mkdir", &["-p", &format!("{}/var", self.home)]));
try!(self.command_runner.run_with_args("rm", &[&format!("{}/var/service.socket", self.home)]));
@ -129,12 +128,12 @@ 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(NodeJsSystemdUserServiceError::GenericError)
Err(e) => return Err(Box::new(NodeJsSystemdUserServiceError::GenericError as NodeJsSystemdUserServiceError<io::Error>))
}
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(NodeJsSystemdUserServiceError::GenericError); }
if !(try!(self.check_if_service())) { return Err(Box::new(NodeJsSystemdUserServiceError::GenericError as NodeJsSystemdUserServiceError<io::Error>)); }
let file_name = format!("{}/var/service.socket", self.home);
// try!(self.command_runner.run_with_args("chmod", &["666", &file_name]));

View file

@ -49,21 +49,20 @@ impl<'a> SystemdUserSession<'a> {
}
impl<'a> Symbol for SystemdUserSession<'a> {
type Error = SystemdUserSessionError<IoError>;
fn target_reached(&self) -> Result<bool, Self::Error> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
let mut path = PathBuf::from("/var/lib/systemd/linger");
path.push(self.user_name);
Ok(path.exists())
// Could also do `loginctl show-user ${self.user_name} | grep -F 'Linger=yes`
}
fn execute(&self) -> Result<(), Self::Error> {
fn execute(&self) -> Result<(), Box<Error>> {
match self.command_runner.run_with_args("loginctl", &["enable-linger", self.user_name]) {
Ok(output) => { println!("{:?} {:?}", from_utf8(&output.stdout).unwrap(), from_utf8(&output.stderr).unwrap() ); match output.status.code() {
Some(0) => Ok(()),
_ => Err(SystemdUserSessionError::GenericError)
_ => Err(Box::new(SystemdUserSessionError::GenericError as SystemdUserSessionError<IoError>))
} },
Err(e) => Err(SystemdUserSessionError::ExecError(e))
Err(e) => Err(Box::new(SystemdUserSessionError::ExecError(e)))
}
}
}