Skip to content

Commit

Permalink
detect and disable apache2 on initial install
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Jul 23, 2024
1 parent 6f904ce commit 7ed63a3
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "khost"
version = "0.0.6"
version = "0.0.7"
edition = "2021"
authors = ["Kaspa developers"]
license = "MIT OR Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ login kaspa
As `kaspa` user:

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
cargo install khost
khost
Expand Down
9 changes: 9 additions & 0 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ pub fn install(ctx: &Context, force: bool) -> Result<()> {
return Ok(());
}

if systemd::is_active("apache2").unwrap_or(false) {
log::warning("Detected conflicting apache2 service.")?;
step("Stopping apache2...", || {
sudo!("systemctl", "stop", "apache2").unchecked().run()?;
sudo!("systemctl", "disable", "apache2").unchecked().run()?;
Ok(())
})?;
}

log::remark(format!(
"Upgrading {}...",
ctx.system
Expand Down
4 changes: 2 additions & 2 deletions src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ pub fn reconfigure(ctx: &mut Context, _force: bool) -> Result<()> {
if !resolver::is_installed(ctx) {
resolver::install(ctx)?;
} else if config.enabled()
&& systemd::is_enabled(&config.service_name())?
&& systemd::is_active(&config.service_name())?
&& systemd::is_enabled(config.service_name())?
&& systemd::is_active(config.service_name())?
{
restart(ctx)?;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/systemd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ pub fn status<S: Service>(service: &S) -> Result<String> {
sudo!("systemctl", "status", service.service_name()).read()
}

pub fn is_active<S: Display>(service: &S) -> Result<bool> {
pub fn is_active<S: Display>(service: S) -> Result<bool> {
let output = sudo!("systemctl", "is-active", service.to_string())
.unchecked()
.read()?;
Ok(output.trim() == "active")
}

pub fn is_enabled<S: Display>(service: &S) -> Result<bool> {
pub fn is_enabled<S: Display>(service: S) -> Result<bool> {
let output = sudo!("systemctl", "is-enabled", service.to_string())
.unchecked()
.read()?;
Expand Down

0 comments on commit 7ed63a3

Please sign in to comment.