Compare commits
No commits in common. "4938a51ad72b78a4da4b7c714f9b75ec945bebfa" and "52e00de3bb038f57fb11181ec4e8db4129bbbd67" have entirely different histories.
4938a51ad7
...
52e00de3bb
7 changed files with 28 additions and 43 deletions
|
|
@ -33,9 +33,7 @@ use crate::symbols::wordpress::{
|
||||||
Plugin as WordpressPluginSymbol, Translation as WordpressTranslationSymbol,
|
Plugin as WordpressPluginSymbol, Translation as WordpressTranslationSymbol,
|
||||||
};
|
};
|
||||||
use crate::templates::nginx;
|
use crate::templates::nginx;
|
||||||
use crate::templates::php::{
|
use crate::templates::php::{fpm_pool_config as php_fpm_pool_config, FpmPoolConfig as PhpFpmPoolConfig};
|
||||||
fpm_pool_config as php_fpm_pool_config, FpmPoolConfig as PhpFpmPoolConfig,
|
|
||||||
};
|
|
||||||
use crate::templates::systemd::{
|
use crate::templates::systemd::{
|
||||||
nodejs_service as systemd_nodejs_service, socket_service as systemd_socket_service,
|
nodejs_service as systemd_nodejs_service, socket_service as systemd_socket_service,
|
||||||
};
|
};
|
||||||
|
|
@ -252,9 +250,7 @@ impl<D: AsRef<str> + Clone + Display> ImplementationBuilder<ServeCustom<D>> for
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Clone + Display, P: AsRef<Path>, C: Clone + Into<PhpFpmPoolConfig>>
|
impl<D: Clone + Display, P: AsRef<Path>, C: Clone + Into<PhpFpmPoolConfig>> ImplementationBuilder<ServePhp<D, P, C>> for DefaultBuilder {
|
||||||
ImplementationBuilder<ServePhp<D, P, C>> for DefaultBuilder
|
|
||||||
{
|
|
||||||
type Prerequisites = (
|
type Prerequisites = (
|
||||||
PhpFpmPool<D>,
|
PhpFpmPool<D>,
|
||||||
CertChain<D>,
|
CertChain<D>,
|
||||||
|
|
@ -790,6 +786,6 @@ impl<D: Clone> ImplementationBuilder<Cron<D>> for DefaultBuilder {
|
||||||
(): &<Cron<D> as Resource>::Artifact,
|
(): &<Cron<D> as Resource>::Artifact,
|
||||||
user_name: <Self::Prerequisites as ToArtifact>::Artifact,
|
user_name: <Self::Prerequisites as ToArtifact>::Artifact,
|
||||||
) -> Self::Implementation {
|
) -> Self::Implementation {
|
||||||
CronSymbol::new((user_name.0).0, &resource.1, &StdCommandRunner)
|
CronSymbol::new((user_name.0).0, resource.1.clone(), &StdCommandRunner)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,17 +33,17 @@ pub fn get_output(output: Output) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
|
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
pub trait CommandRunner {
|
pub trait CommandRunner {
|
||||||
async fn run(&self, program: &str, args: &[&OsStr], stdin: &[u8]) -> IoResult<Output>;
|
async fn run(&self, program: &str, args: &[&OsStr], stdin: &str) -> IoResult<Output>;
|
||||||
|
|
||||||
async fn run_with_args(&self, program: &str, args: &[&OsStr]) -> IoResult<Output> {
|
async fn run_with_args(&self, program: &str, args: &[&OsStr]) -> IoResult<Output> {
|
||||||
self.run(program, args, b"").await
|
self.run(program, args, "").await
|
||||||
}
|
}
|
||||||
async fn get_output(&self, program: &str, args: &[&OsStr]) -> Result<Vec<u8>, Box<dyn Error>> {
|
async fn get_output(&self, program: &str, args: &[&OsStr]) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
let output = self.run_with_args(program, args).await?;
|
let output = self.run_with_args(program, args).await?;
|
||||||
get_output(output)
|
get_output(output)
|
||||||
}
|
}
|
||||||
async fn run_successfully(&self, program: &str, args: &[&OsStr]) -> Result<(), Box<dyn Error>> {
|
async fn run_successfully(&self, program: &str, args: &[&OsStr]) -> Result<(), Box<dyn Error>> {
|
||||||
is_success(self.run(program, args, b"").await)?;
|
is_success(self.run(program, args, "").await)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
async fn get_stderr(&self, program: &str, args: &[&OsStr]) -> Result<Vec<u8>, Box<dyn Error>> {
|
async fn get_stderr(&self, program: &str, args: &[&OsStr]) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
|
|
@ -56,7 +56,7 @@ pub struct StdCommandRunner;
|
||||||
|
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
impl CommandRunner for StdCommandRunner {
|
impl CommandRunner for StdCommandRunner {
|
||||||
async fn run(&self, program: &str, args: &[&OsStr], input: &[u8]) -> IoResult<Output> {
|
async fn run(&self, program: &str, args: &[&OsStr], input: &str) -> IoResult<Output> {
|
||||||
//println!("{} {:?}", program, args);
|
//println!("{} {:?}", program, args);
|
||||||
let mut child = Command::new(program)
|
let mut child = Command::new(program)
|
||||||
.args(args)
|
.args(args)
|
||||||
|
|
@ -67,7 +67,7 @@ impl CommandRunner for StdCommandRunner {
|
||||||
.expect("Failed to spawn child process");
|
.expect("Failed to spawn child process");
|
||||||
let stdin = child.stdin.as_mut().expect("Failed to open stdin");
|
let stdin = child.stdin.as_mut().expect("Failed to open stdin");
|
||||||
stdin
|
stdin
|
||||||
.write_all(input)
|
.write_all(input.as_bytes())
|
||||||
.await
|
.await
|
||||||
.expect("Failed to write to stdin");
|
.expect("Failed to write to stdin");
|
||||||
let res = child.wait_with_output().await;
|
let res = child.wait_with_output().await;
|
||||||
|
|
@ -122,7 +122,7 @@ impl Drop for TempSetEnv<'_> {
|
||||||
|
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
impl<U: AsRef<str>, C: CommandRunner> CommandRunner for SetuidCommandRunner<'_, U, C> {
|
impl<U: AsRef<str>, C: CommandRunner> CommandRunner for SetuidCommandRunner<'_, U, C> {
|
||||||
async fn run(&self, program: &str, args: &[&OsStr], input: &[u8]) -> IoResult<Output> {
|
async fn run(&self, program: &str, args: &[&OsStr], input: &str) -> IoResult<Output> {
|
||||||
let uid = get_user_by_name(self.user_name.as_ref())
|
let uid = get_user_by_name(self.user_name.as_ref())
|
||||||
.expect("User does not exist")
|
.expect("User does not exist")
|
||||||
.uid();
|
.uid();
|
||||||
|
|
@ -140,7 +140,7 @@ impl<U: AsRef<str>, C: CommandRunner> CommandRunner for SetuidCommandRunner<'_,
|
||||||
.expect("Failed to spawn child process");
|
.expect("Failed to spawn child process");
|
||||||
let stdin = child.stdin.as_mut().expect("Failed to open stdin");
|
let stdin = child.stdin.as_mut().expect("Failed to open stdin");
|
||||||
stdin
|
stdin
|
||||||
.write_all(input)
|
.write_all(input.as_bytes())
|
||||||
.await
|
.await
|
||||||
.expect("Failed to write to stdin");
|
.expect("Failed to write to stdin");
|
||||||
let res = child.wait_with_output().await;
|
let res = child.wait_with_output().await;
|
||||||
|
|
@ -179,7 +179,7 @@ impl<'a, C> CommandRunner for SuCommandRunner<'a, C>
|
||||||
where
|
where
|
||||||
C: 'a + CommandRunner,
|
C: 'a + CommandRunner,
|
||||||
{
|
{
|
||||||
async fn run(&self, program: &str, args: &[&OsStr], input: &[u8]) -> IoResult<Output> {
|
async fn run(&self, program: &str, args: &[&OsStr], input: &str) -> IoResult<Output> {
|
||||||
let raw_new_args = [self.user_name, "-s", "/usr/bin/env", "--", program];
|
let raw_new_args = [self.user_name, "-s", "/usr/bin/env", "--", program];
|
||||||
let mut new_args: Vec<&OsStr> = raw_new_args.iter().map(AsRef::as_ref).collect();
|
let mut new_args: Vec<&OsStr> = raw_new_args.iter().map(AsRef::as_ref).collect();
|
||||||
new_args.extend_from_slice(args);
|
new_args.extend_from_slice(args);
|
||||||
|
|
@ -201,8 +201,8 @@ mod test {
|
||||||
run(async {
|
run(async {
|
||||||
let args = args!["1"];
|
let args = args!["1"];
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let res = c.run("sleep", args, b"").fuse();
|
let res = c.run("sleep", args, "").fuse();
|
||||||
let ps = c.run("ps", args![], b"").fuse();
|
let ps = c.run("ps", args![], "").fuse();
|
||||||
futures_util::pin_mut!(res, ps);
|
futures_util::pin_mut!(res, ps);
|
||||||
loop {
|
loop {
|
||||||
futures_util::select! {
|
futures_util::select! {
|
||||||
|
|
|
||||||
|
|
@ -302,10 +302,7 @@ impl<D: AsRef<Path>, P, C, POLICY> ResourceLocator<ServePhp<D, P, C>> for Defaul
|
||||||
type Prerequisites = ();
|
type Prerequisites = ();
|
||||||
fn locate(
|
fn locate(
|
||||||
resource: &ServePhp<D, P, C>,
|
resource: &ServePhp<D, P, C>,
|
||||||
) -> (
|
) -> (<ServePhp<D, P, C> as Resource>::Artifact, Self::Prerequisites) {
|
||||||
<ServePhp<D, P, C> as Resource>::Artifact,
|
|
||||||
Self::Prerequisites,
|
|
||||||
) {
|
|
||||||
(
|
(
|
||||||
PathArtifact::from(Path::new("/etc/nginx/sites-enabled/").join(&resource.0)),
|
PathArtifact::from(Path::new("/etc/nginx/sites-enabled/").join(&resource.0)),
|
||||||
(),
|
(),
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,13 @@ impl<D> Resource for ServeCustom<D> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||||
pub struct ServePhp<D, P, C>(pub D, pub P, pub &'static str, pub String, pub C);
|
pub struct ServePhp<D, P, C>(
|
||||||
|
pub D,
|
||||||
|
pub P,
|
||||||
|
pub &'static str,
|
||||||
|
pub String,
|
||||||
|
pub C,
|
||||||
|
);
|
||||||
impl<D, P, C> Resource for ServePhp<D, P, C> {
|
impl<D, P, C> Resource for ServePhp<D, P, C> {
|
||||||
type Artifact = PathArtifact;
|
type Artifact = PathArtifact;
|
||||||
}
|
}
|
||||||
|
|
@ -313,18 +319,7 @@ default_resources!(
|
||||||
WordpressTranslation: WordpressTranslation<PathBuf>,
|
WordpressTranslation: WordpressTranslation<PathBuf>,
|
||||||
);
|
);
|
||||||
|
|
||||||
pub fn serve_php<D, P: Into<PathBuf>, C: Into<FpmPoolConfig>>(
|
pub fn serve_php<D, P: Into<PathBuf>, C: Into<FpmPoolConfig>>(domain: D, path: P, root_filename: &'static str, nginx_config: impl Into<String>, pool_config: C) -> ServePhp<D, PathBuf, FpmPoolConfig> {
|
||||||
domain: D,
|
|
||||||
path: P,
|
|
||||||
root_filename: &'static str,
|
|
||||||
nginx_config: impl Into<String>,
|
|
||||||
pool_config: C,
|
|
||||||
) -> ServePhp<D, PathBuf, FpmPoolConfig> {
|
|
||||||
ServePhp(
|
ServePhp(
|
||||||
domain,
|
domain, path.into(), root_filename, nginx_config.into(), pool_config.into())
|
||||||
path.into(),
|
|
||||||
root_filename,
|
|
||||||
nginx_config.into(),
|
|
||||||
pool_config.into(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,13 +21,13 @@ impl<'r, U, R> Cron<'r, String, U, R> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
impl<C: AsRef<[u8]>, U: AsRef<str>, R: CommandRunner> Symbol for Cron<'_, C, U, R> {
|
impl<C: AsRef<str>, U: AsRef<str>, R: CommandRunner> Symbol for Cron<'_, C, U, R> {
|
||||||
async fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
async fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||||
let tab = self
|
let tab = self
|
||||||
.command_runner
|
.command_runner
|
||||||
.get_output("crontab", args!["-l", "-u", self.user.as_ref()])
|
.get_output("crontab", args!["-l", "-u", self.user.as_ref()])
|
||||||
.await?;
|
.await?;
|
||||||
Ok(tab == self.content.as_ref())
|
Ok(tab == self.content.as_ref().as_bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn execute(&self) -> Result<(), Box<dyn Error>> {
|
async fn execute(&self) -> Result<(), Box<dyn Error>> {
|
||||||
|
|
|
||||||
|
|
@ -110,9 +110,9 @@ mod test {
|
||||||
}
|
}
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
impl CommandRunner for DummyCommandRunner {
|
impl CommandRunner for DummyCommandRunner {
|
||||||
async fn run(&self, program: &str, args: &[&OsStr], stdin: &[u8]) -> IoResult<Output> {
|
async fn run(&self, program: &str, args: &[&OsStr], stdin: &str) -> IoResult<Output> {
|
||||||
assert_eq!(program, "git");
|
assert_eq!(program, "git");
|
||||||
assert_eq!(stdin, b"");
|
assert_eq!(stdin, "");
|
||||||
sleep(Duration::from_millis(50)).await;
|
sleep(Duration::from_millis(50)).await;
|
||||||
self
|
self
|
||||||
.args
|
.args
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,7 @@ impl From<usize> for FpmPoolConfig {
|
||||||
|
|
||||||
impl FpmPoolConfig {
|
impl FpmPoolConfig {
|
||||||
pub fn new(max_children: usize, custom: impl Into<String>) -> Self {
|
pub fn new(max_children: usize, custom: impl Into<String>) -> Self {
|
||||||
Self {
|
Self { max_children, custom: Some(custom.into()) }
|
||||||
max_children,
|
|
||||||
custom: Some(custom.into()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue