A library for writing host-specific, single-binary configuration management and deployment tools
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
945 B

use std::path::Path;
pub fn socket_service(
socket_path: impl AsRef<Path>,
exec: &str,
dir: impl AsRef<Path>,
additional: &str,
) -> String {
format!(
"[Service]
ExecStartPre=/bin/rm -f {}
ExecStart={}
WorkingDirectory={}
Restart=always
{}
[Install]
WantedBy=default.target
",
socket_path.as_ref().to_str().unwrap(),
exec,
dir.as_ref().to_str().unwrap(),
additional
)
}
pub fn nodejs_service<N: AsRef<Path>, S: AsRef<Path>>(
nodejs_path: N,
socket_path: S,
dir: impl AsRef<Path>,
) -> String {
socket_service(
&socket_path,
&format!("/usr/bin/nodejs {}", nodejs_path.as_ref().to_str().unwrap()),
dir,
&format!(
"Environment=NODE_ENV=production
Environment=PORT={0}
ExecStartPost=/bin/sh -c 'for i in 1 2 3 4 5 6 7 8 9 10; do sleep 0.5; chmod 666 {0} && break; done'
#RuntimeDirectory=service
#RuntimeDirectoryMode=766",
socket_path.as_ref().to_str().unwrap()
),
)
}