|
@ -56,6 +56,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,
|
|
|
home: &'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>>
|
|
@ -64,20 +65,24 @@ 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, name: &'a str, path: &'a str, command_runner: &'a CommandRunner) -> Self {
|
|
|
|
|
|
|
|
|
pub fn new(home: &'a str, uid: u32, 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]
|
|
|
ExecStart=/usr/bin/nodejs {}
|
|
|
|
|
|
|
|
|
ExecStartPre=rm /var/tmp/{1}-{2}.socket
|
|
|
|
|
|
ExecStart=/usr/bin/nodejs {0}
|
|
|
Restart=always
|
|
|
Restart=always
|
|
|
Environment=NODE_ENV=production
|
|
|
Environment=NODE_ENV=production
|
|
|
Environment=PORT={}/var/service.socket
|
|
|
|
|
|
|
|
|
Environment=PORT=/var/tmp/{1}-{2}.socket
|
|
|
|
|
|
#RuntimeDirectory=service
|
|
|
|
|
|
#RuntimeDirectoryMode=766
|
|
|
|
|
|
|
|
|
[Install]
|
|
|
[Install]
|
|
|
WantedBy=default.target
|
|
|
WantedBy=default.target
|
|
|
", path, home);
|
|
|
|
|
|
|
|
|
", path, uid, name);
|
|
|
NodeJsSystemdUserService {
|
|
|
NodeJsSystemdUserService {
|
|
|
name: name,
|
|
|
name: name,
|
|
|
|
|
|
uid: uid,
|
|
|
home: home,
|
|
|
home: home,
|
|
|
path: file_path.clone(),
|
|
|
path: file_path.clone(),
|
|
|
command_runner: command_runner,
|
|
|
command_runner: command_runner,
|
|
@ -121,9 +126,6 @@ impl<'a, P, C> Symbol for NodeJsSystemdUserService<'a, P, C> where P: AsRef<str> |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
fn execute(&self) -> Result<(), Box<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)]));
|
|
|
|
|
|
|
|
|
|
|
|
try!(self.command_runner.run_with_args("mkdir", &["-p", Path::new(self.path.as_ref()).parent().unwrap().to_str().unwrap()]));
|
|
|
try!(self.command_runner.run_with_args("mkdir", &["-p", Path::new(self.path.as_ref()).parent().unwrap().to_str().unwrap()]));
|
|
|
// FIXME: Permissions
|
|
|
// FIXME: Permissions
|
|
|
// try!(create_dir_all(Path::new(&path).parent().unwrap()));
|
|
|
// try!(create_dir_all(Path::new(&path).parent().unwrap()));
|
|
@ -136,7 +138,7 @@ impl<'a, P, C> Symbol for NodeJsSystemdUserService<'a, P, C> where P: AsRef<str> |
|
|
|
|
|
|
|
|
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/service.socket", self.home);
|
|
|
|
|
|
|
|
|
let file_name = format!("/var/tmp/{}-{}.socket", self.uid, 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));
|
|
@ -148,9 +150,11 @@ impl<'a, P, C> Symbol for NodeJsSystemdUserService<'a, P, C> where P: AsRef<str> |
|
|
Ok(())
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* // FIXME
|
|
|
fn get_prerequisites(&self) -> Vec<Box<Resource>> {
|
|
|
fn get_prerequisites(&self) -> Vec<Box<Resource>> {
|
|
|
self.file.get_prerequisites()
|
|
|
self.file.get_prerequisites()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl<'a, P, C> fmt::Display for NodeJsSystemdUserService<'a, P, C> where P: AsRef<str> + fmt::Display, C: Deref<Target=str> {
|
|
|
impl<'a, P, C> fmt::Display for NodeJsSystemdUserService<'a, P, C> where P: AsRef<str> + fmt::Display, C: Deref<Target=str> {
|
|
|