Skip to content

Commit

Permalink
update config rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Jul 21, 2024
1 parent 8d5e284 commit eda7bd3
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 16 deletions.
7 changes: 0 additions & 7 deletions src/actions/advanced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use crate::imports::*;
pub enum Advanced {
#[describe("Back")]
Back,
#[describe("Rebuild configuration")]
Rebuild,
#[describe("Configure Git")]
Git,
#[describe("Full installation")]
Expand All @@ -23,11 +21,6 @@ impl Action for Advanced {
fn main(&self, ctx: &mut Context) -> Result<bool> {
match self {
Advanced::Back => Ok(false),
Advanced::Rebuild => {
kaspad::reconfigure(ctx, true)?;
nginx::reconfigure(ctx)?;
Ok(true)
}
Advanced::PurgeData => {
let mut folders = HashMap::new();
for config in ctx.config.kaspad.iter() {
Expand Down
8 changes: 8 additions & 0 deletions src/actions/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub enum Configure {
Enable,
#[describe("Configure SSL certificates")]
Tls,
#[describe("Rebuild configuration")]
Rebuild,
#[describe("View configuration files")]
View,
}
Expand Down Expand Up @@ -168,6 +170,12 @@ impl Action for Configure {

Ok(true)
}
Configure::Rebuild => {
kaspad::reconfigure(ctx, true)?;
resolver::reconfigure(ctx, true)?;
nginx::reconfigure(ctx)?;
Ok(true)
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ impl Context {
})
}

pub fn proxy_configs(&self) -> Vec<ProxyConfig> {
pub fn proxy_configs(&self, ctx: &Context) -> Vec<ProxyConfig> {
let mut services = self
.config
.kaspad
.iter()
.map(|config| config.proxy_config())
.map(|config| config.proxy_config(ctx))
.collect::<Vec<_>>();
services.push(self.config.resolver.proxy_config());
services.push(self.config.resolver.proxy_config(ctx));
services.into_iter().flatten().flatten().collect::<Vec<_>>()
}

Expand Down
4 changes: 2 additions & 2 deletions src/kaspad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Service for Config {
true
}

fn proxy_config(&self) -> Option<Vec<ProxyConfig>> {
fn proxy_config(&self, _ctx: &Context) -> Option<Vec<ProxyConfig>> {
let mut proxy_configs = Vec::new();

if let Some(iface) = self.wrpc_borsh.as_ref() {
Expand Down Expand Up @@ -90,7 +90,7 @@ impl Config {
data_folder: None,
enable_upnp: false,
outgoing_peers: Some(32),
max_incoming_peers: Some(1024),
max_incoming_peers: Some(256),
grpc: Some(Interface::Local(grpc)),
wrpc_borsh: Some(Interface::Local(wrpc_borsh)),
wrpc_json: Some(Interface::Local(wrpc_json)),
Expand Down
4 changes: 2 additions & 2 deletions src/nginx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Service for Config {
false
}

fn proxy_config(&self) -> Option<Vec<ProxyConfig>> {
fn proxy_config(&self, _ctx: &Context) -> Option<Vec<ProxyConfig>> {
None
}
}
Expand Down Expand Up @@ -327,7 +327,7 @@ pub fn remove() -> Result<()> {
pub fn reconfigure(ctx: &Context) -> Result<()> {
step("Updating NGINX configuration...", || {
let server_kind = ServerKind::new(&ctx.config.nginx.certs).with_fqdn(fqdn::get());
let proxy_configs = ctx.proxy_configs();
let proxy_configs = ctx.proxy_configs(ctx);
store(NginxConfig::new(server_kind, proxy_configs))?;
reload()
})
Expand Down
8 changes: 7 additions & 1 deletion src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Service for Config {
true
}

fn proxy_config(&self) -> Option<Vec<ProxyConfig>> {
fn proxy_config(&self, _ctx: &Context) -> Option<Vec<ProxyConfig>> {
let proxy_kind = ProxyKind::http(8989);
let proxy_config = ProxyConfig::new(
format!("{} ({})", self.service_title(), self.service_name()),
Expand Down Expand Up @@ -305,6 +305,12 @@ pub fn check_for_updates(ctx: &Context) -> Result<()> {
Ok(())
}

pub fn reconfigure(_ctx: &Context, _force: bool) -> Result<()> {
// let mut reconfigure_systemd = false;

Ok(())
}

// ---

pub fn resolver_config_folder() -> PathBuf {
Expand Down
2 changes: 1 addition & 1 deletion src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub trait Service {
fn origin(&self) -> Option<Origin>;
fn enabled(&self) -> bool;
fn managed(&self) -> bool;
fn proxy_config(&self) -> Option<Vec<ProxyConfig>>;
fn proxy_config(&self, ctx: &Context) -> Option<Vec<ProxyConfig>>;

fn service_detail(&self) -> ServiceDetail {
ServiceDetail::new(
Expand Down
4 changes: 4 additions & 0 deletions src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ impl System {
sha256.update(some_id.as_bytes());
Some(sha256.finalize().to_vec())
}

pub fn system_id_as_hex(&self) -> String {
format!("{:016x}", self.system_id.unwrap_or_default())
}
}

#[derive(Debug)]
Expand Down

0 comments on commit eda7bd3

Please sign in to comment.