feat: implement LibConductor::health for nginx conductor
This commit is contained in:
parent
158ec03aab
commit
bfaf077c02
5 changed files with 1184 additions and 0 deletions
1
env/nginx_bind_le/.gitignore
vendored
Normal file
1
env/nginx_bind_le/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
target/
|
1069
env/nginx_bind_le/Cargo.lock
generated
vendored
Normal file
1069
env/nginx_bind_le/Cargo.lock
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
20
env/nginx_bind_le/Cargo.toml
vendored
Normal file
20
env/nginx_bind_le/Cargo.toml
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
[package]
|
||||
name = "nginx_bind_le"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1", features=["derive"]}
|
||||
serde_json = { version ="1", features = ["raw_value"]}
|
||||
async-trait = "0.1.57"
|
||||
tokio = { version = "1.23.0", features = ["process"] }
|
||||
tera = "1.17.1"
|
||||
|
||||
[dependencies.libconductor]
|
||||
path = "../libconductor"
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { version = "1.23.0", features = ["rt-multi-thread", "macros", "rt"] }
|
61
env/nginx_bind_le/src/lib.rs
vendored
Normal file
61
env/nginx_bind_le/src/lib.rs
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
use async_trait::async_trait;
|
||||
use tokio::process::Command;
|
||||
|
||||
use libconductor::*;
|
||||
|
||||
mod nginx;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct NginxBindLEConductor;
|
||||
|
||||
const CONDUCTOR_NAME: &str = "NGINX_BIND_LE_CONDUCTOR";
|
||||
|
||||
#[async_trait]
|
||||
impl Conductor for NginxBindLEConductor {
|
||||
async fn process(&self, event: EventType) {
|
||||
match event {
|
||||
EventType::NewSite {
|
||||
hostname,
|
||||
path,
|
||||
branch,
|
||||
} => unimplemented!(),
|
||||
EventType::Config { data } => unimplemented!(),
|
||||
EventType::DeleteSite { hostname } => unimplemented!(),
|
||||
};
|
||||
}
|
||||
fn name(&self) -> &'static str {
|
||||
CONDUCTOR_NAME
|
||||
}
|
||||
|
||||
async fn health(&self) -> bool {
|
||||
nginx::Nginx::status().await
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn all_good() {
|
||||
let c = NginxBindLEConductor {};
|
||||
assert_eq!(c.name(), CONDUCTOR_NAME);
|
||||
assert!(c.health().await);
|
||||
}
|
||||
}
|
33
env/nginx_bind_le/src/nginx.rs
vendored
Normal file
33
env/nginx_bind_le/src/nginx.rs
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
use tokio::process::Command;
|
||||
|
||||
pub struct Nginx;
|
||||
|
||||
impl Nginx {
|
||||
pub async fn status() -> bool {
|
||||
async fn run_async_cmd(cmd: &mut Command) -> bool {
|
||||
if let Ok(mut child) = cmd.spawn() {
|
||||
if let Ok(res) = child.wait().await {
|
||||
return res.success();
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
run_async_cmd(Command::new("sudo").arg("nginx").arg("-t")).await
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue