Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions 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 devolutions-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async-trait = "0.1"
base64 = "0.23"
bytes = "1"
camino = { version = "1.1", features = ["serde1"] }
ceviche = "0.7"
ceviche = "0.8"
ctrlc = "3.5"
devolutions-agent-shared = { path = "../crates/devolutions-agent-shared" }
devolutions-gateway-task = { path = "../crates/devolutions-gateway-task" }
Expand Down
16 changes: 12 additions & 4 deletions devolutions-agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ use devolutions_agent::enrollment::parse_enrollment_jwt;

use self::service::{AgentService, DESCRIPTION, DISPLAY_NAME, SERVICE_NAME};

const BAD_CONFIG_ERR_CODE: u32 = 1;
const START_FAILED_ERR_CODE: u32 = 2;
const BAD_CONFIG_ERR_CODE: u8 = 1;
const START_FAILED_ERR_CODE: u8 = 2;

#[derive(Debug, PartialEq, Eq)]
struct UpCommand {
Expand All @@ -69,7 +69,7 @@ fn agent_service_main(
_tx: mpsc::Sender<AgentServiceEvent>,
_args: Vec<String>,
_standalone_mode: bool,
) -> u32 {
) -> u8 {
Comment thread
CBenoit marked this conversation as resolved.
let Ok(conf_handle) = ConfHandle::init() else {
// At this point, the logger is not yet initialized.
return BAD_CONFIG_ERR_CODE;
Expand Down Expand Up @@ -318,7 +318,15 @@ fn main() {
}
}
} else {
let _result = controller.register(service_main_wrapper);
// Propagate the service exit code so that service managers (e.g.: systemd) see failures.
match controller.register(service_main_wrapper) {
Ok(0) => {}
Ok(exit_code) => std::process::exit(i32::from(exit_code)),
Err(error) => {
eprintln!("[ERROR] Failed to register service: {error}");
std::process::exit(1);
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion devolutions-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ironrdp-rdcleanpath = "0.2"
ironrdp-tokio = "0.10"
ironrdp-connector = "0.10"
ironrdp-acceptor = "0.10"
ceviche = "0.7"
ceviche = "0.8"
picky-krb = "0.12"
kdc = "0.1"

Expand Down
21 changes: 13 additions & 8 deletions devolutions-gateway/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ extern crate tracing;

mod service;

use std::process::ExitCode;
use std::sync::mpsc;

use anyhow::Context;
Expand All @@ -76,8 +77,8 @@ use tap::prelude::*;

use crate::service::{DESCRIPTION, DISPLAY_NAME, GatewayService, SERVICE_NAME};

fn main() -> anyhow::Result<()> {
run().inspect_err(write_boot_stacktrace)
fn main() -> anyhow::Result<ExitCode> {
run().map(ExitCode::from).inspect_err(write_boot_stacktrace)
}

fn write_boot_stacktrace(error: &anyhow::Error) {
Expand All @@ -94,7 +95,8 @@ fn write_boot_stacktrace(error: &anyhow::Error) {
}
}

fn run() -> anyhow::Result<()> {
/// Returns the process exit code.
fn run() -> anyhow::Result<u8> {
let (executable, cli_args) = parse_args_from_env()?;

// Set the DGATEWAY_CONFIG_PATH if --config-path was provided.
Expand Down Expand Up @@ -139,9 +141,12 @@ fn run() -> anyhow::Result<()> {
devolutions_gateway::tls::install_default_crypto_provider();

if service_mode {
service_controller()
// Propagate the service exit code so that service managers (e.g.: systemd) see failures.
let exit_code = service_controller()
.register(service_main_wrapper)
.context("failed to register service")?;

return Ok(exit_code);
} else {
let conf_handle = ConfHandle::init().context("unable to initialize configuration")?;
let mut service = GatewayService::load(conf_handle).context("service loading failed")?;
Expand All @@ -162,7 +167,7 @@ fn run() -> anyhow::Result<()> {
}
}

Ok(())
Ok(0)
}

fn service_controller() -> Controller {
Expand All @@ -171,15 +176,15 @@ fn service_controller() -> Controller {

enum GatewayServiceEvent {}

const BAD_CONFIG_ERR_CODE: u32 = 1;
const START_FAILED_ERR_CODE: u32 = 2;
const BAD_CONFIG_ERR_CODE: u8 = 1;
const START_FAILED_ERR_CODE: u8 = 2;

fn gateway_service_main(
rx: mpsc::Receiver<ServiceEvent<GatewayServiceEvent>>,
_tx: mpsc::Sender<ServiceEvent<GatewayServiceEvent>>,
_args: Vec<String>,
_standalone_mode: bool,
) -> u32 {
) -> u8 {
Comment thread
CBenoit marked this conversation as resolved.
let conf_handle = match ConfHandle::init() {
Ok(conf_handle) => conf_handle,
Err(error) => {
Expand Down
Loading