|
@ -28,14 +28,14 @@ impl From<io::Error> for NodeJsSystemdUserServiceError<io::Error> { |
|
|
impl<E: Error> Error for NodeJsSystemdUserServiceError<E> {
|
|
|
impl<E: Error> Error for NodeJsSystemdUserServiceError<E> {
|
|
|
fn description(&self) -> &str {
|
|
|
fn description(&self) -> &str {
|
|
|
match self {
|
|
|
match self {
|
|
|
&NodeJsSystemdUserServiceError::ExecError(ref e) => e.description(),
|
|
|
|
|
|
&NodeJsSystemdUserServiceError::GenericError => "Generic error",
|
|
|
|
|
|
&NodeJsSystemdUserServiceError::ActivationFailed(_) => "Activation of service failed"
|
|
|
|
|
|
|
|
|
NodeJsSystemdUserServiceError::ExecError(ref e) => e.description(),
|
|
|
|
|
|
NodeJsSystemdUserServiceError::GenericError => "Generic error",
|
|
|
|
|
|
NodeJsSystemdUserServiceError::ActivationFailed(_) => "Activation of service failed"
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
fn cause(&self) -> Option<&Error> {
|
|
|
fn cause(&self) -> Option<&Error> {
|
|
|
match self {
|
|
|
match self {
|
|
|
&NodeJsSystemdUserServiceError::ExecError(ref e) => Some(e),
|
|
|
|
|
|
|
|
|
NodeJsSystemdUserServiceError::ExecError(ref e) => Some(e),
|
|
|
_ => None
|
|
|
_ => None
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@ -44,7 +44,7 @@ impl<E: Error> Error for NodeJsSystemdUserServiceError<E> { |
|
|
impl<E: Error> fmt::Display for NodeJsSystemdUserServiceError<E> {
|
|
|
impl<E: Error> fmt::Display for NodeJsSystemdUserServiceError<E> {
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
|
|
try!(write!(f, "{}", self.description()));
|
|
|
try!(write!(f, "{}", self.description()));
|
|
|
if let &NodeJsSystemdUserServiceError::ActivationFailed(Ok(ref log)) = self {
|
|
|
|
|
|
|
|
|
if let NodeJsSystemdUserServiceError::ActivationFailed(Ok(ref log)) = self {
|
|
|
try!(write!(f, ": {:?}", log));
|
|
|
try!(write!(f, ": {:?}", log));
|
|
|
};
|
|
|
};
|
|
|
Ok(())
|
|
|
Ok(())
|
|
@ -59,10 +59,10 @@ pub struct NodeJsSystemdUserService<'a, C, R> where C: Deref<Target=str>, R: Com |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl<'a, R> NodeJsSystemdUserService<'a, String, SetuidCommandRunner<'a, R>> where R: CommandRunner {
|
|
|
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);
|
|
|
|
|
|
|
|
|
pub fn new(home: &'a str, user_name: &'a str, service_name: &'a str, path: &'a str, command_runner: &'a R) -> Self {
|
|
|
|
|
|
let file_path = format!("{}/.config/systemd/user/{}.service", home.trim_right(), service_name);
|
|
|
|
|
|
|
|
|
let port = format!("/var/tmp/{}-{}.socket", user_name, name);
|
|
|
|
|
|
|
|
|
let port = format!("/var/tmp/{}-{}.socket", user_name, service_name);
|
|
|
let content = format!("[Service]
|
|
|
let content = format!("[Service]
|
|
|
Environment=NODE_ENV=production
|
|
|
Environment=NODE_ENV=production
|
|
|
Environment=PORT={1}
|
|
|
Environment=PORT={1}
|
|
@ -81,8 +81,8 @@ WantedBy=default.target |
|
|
", path, port);
|
|
|
", path, port);
|
|
|
|
|
|
|
|
|
NodeJsSystemdUserService {
|
|
|
NodeJsSystemdUserService {
|
|
|
service_name: name,
|
|
|
|
|
|
user_name: user_name,
|
|
|
|
|
|
|
|
|
service_name,
|
|
|
|
|
|
user_name,
|
|
|
command_runner: SetuidCommandRunner::new(user_name, command_runner),
|
|
|
command_runner: SetuidCommandRunner::new(user_name, command_runner),
|
|
|
file: FileSymbol::new(file_path, content)
|
|
|
file: FileSymbol::new(file_path, content)
|
|
|
}
|
|
|
}
|
|
|