Update
This commit is contained in:
parent
1d037da45a
commit
764937e034
1 changed files with 9 additions and 9 deletions
|
|
@ -8,7 +8,7 @@ use std::thread::sleep;
|
|||
use std::time::Duration;
|
||||
use std::ops::Deref;
|
||||
|
||||
use command_runner::CommandRunner;
|
||||
use command_runner::{CommandRunner, SetuidCommandRunner};
|
||||
use resources::Resource;
|
||||
use symbols::Symbol;
|
||||
use symbols::file::File as FileSymbol;
|
||||
|
|
@ -52,15 +52,15 @@ impl<E: Error> fmt::Display for NodeJsSystemdUserServiceError<E> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct NodeJsSystemdUserService<'a, C> where C: Deref<Target=str> {
|
||||
pub struct NodeJsSystemdUserService<'a, C, R> where C: Deref<Target=str>, R: CommandRunner {
|
||||
service_name: &'a str,
|
||||
user_name: &'a str,
|
||||
command_runner: &'a CommandRunner,
|
||||
command_runner: R,
|
||||
file: FileSymbol<C, String>
|
||||
}
|
||||
|
||||
impl<'a> NodeJsSystemdUserService<'a, String> {
|
||||
pub fn new(home: &'a str, user_name: &'a str, name: &'a str, path: &'a str, command_runner: &'a CommandRunner) -> Self {
|
||||
impl<'a, R> NodeJsSystemdUserService<'a, String, SetuidCommandRunner<'a, R>> where R: CommandRunner {
|
||||
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 content = format!("[Service]
|
||||
|
|
@ -81,13 +81,13 @@ WantedBy=default.target
|
|||
NodeJsSystemdUserService {
|
||||
service_name: name,
|
||||
user_name: user_name,
|
||||
command_runner: command_runner,
|
||||
command_runner: SetuidCommandRunner::new(user_name, command_runner),
|
||||
file: FileSymbol::new(file_path, content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, C> NodeJsSystemdUserService<'a, C> where C: Deref<Target=str> {
|
||||
impl<'a, C, R> NodeJsSystemdUserService<'a, C, R> where C: Deref<Target=str>, R: CommandRunner {
|
||||
fn check_if_service(&self) -> Result<bool, Box<Error>> {
|
||||
loop {
|
||||
// Check if service is registered
|
||||
|
|
@ -131,7 +131,7 @@ fn wait_for_metadata(file_name: &str) -> Result<Metadata, Box<Error>> {
|
|||
Ok(result)
|
||||
}
|
||||
|
||||
impl<'a, C> Symbol for NodeJsSystemdUserService<'a, C> where C: Deref<Target=str> {
|
||||
impl<'a, C, R> Symbol for NodeJsSystemdUserService<'a, C, R> where C: Deref<Target=str>, R: CommandRunner {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
||||
if !(try!(self.file.target_reached())) {
|
||||
return Ok(false);
|
||||
|
|
@ -163,7 +163,7 @@ impl<'a, C> Symbol for NodeJsSystemdUserService<'a, C> where C: Deref<Target=str
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, C> fmt::Display for NodeJsSystemdUserService<'a, C> where C: Deref<Target=str> {
|
||||
impl<'a, C, R> fmt::Display for NodeJsSystemdUserService<'a, C, R> where C: Deref<Target=str>, R: CommandRunner {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(),fmt::Error>{
|
||||
write!(f, "Systemd Node.js user service unit for {}", self.service_name)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue