Skip to content

Commit

Permalink
fix: docker, log when exec fails and avoid double mounting initial de…
Browse files Browse the repository at this point in the history
…vices
  • Loading branch information
ABeltramo committed Feb 4, 2024
1 parent 8440fad commit 8bef26f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docker/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
set -e

# Update fake-udev if missing from the path
cp /wolf/fake-udev $WOLF_CFG_FOLDER/fake-udev
cp /wolf/fake-udev $WOLF_DOCKER_FAKE_UDEV_PATH

exec /wolf/wolf
2 changes: 1 addition & 1 deletion docker/wolf.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ ENV XDG_RUNTIME_DIR=/tmp/sockets \
WOLF_DOCKER_SOCKET=/var/run/docker.sock \
RUST_BACKTRACE=full \
HOST_APPS_STATE_FOLDER=/etc/wolf \
WOLF_DOCKER_FAKE_UDEV_PATH=/etc/wolf/fake-udev \
WOLF_DOCKER_FAKE_UDEV_PATH=$HOST_APPS_STATE_FOLDER/fake-udev \
GST_DEBUG=2 \
PUID=0 \
PGID=0 \
Expand Down
16 changes: 14 additions & 2 deletions src/core/src/platforms/all/docker/docker/docker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,20 @@ bool DockerAPI::exec(std::string_view id, const std::vector<std::string_view> &c
json_payload = json::serialize(post_params);
raw_msg = req(conn.value().get(), POST, api_url, json_payload);
if (raw_msg && raw_msg->first == 200) {
// Exec request completed, return
return true;
auto console = raw_msg->second;
// Exec request completed, inspect the results
api_url = fmt::format("http://localhost/{}/exec/{}/json", DOCKER_API_VERSION, exec_id);
raw_msg = req(conn.value().get(), GET, api_url);
if (raw_msg && raw_msg->first == 200) {
json = parse(raw_msg->second);
auto exit_code = json.at("ExitCode").as_int64();
if (exit_code != 0) {
logs::log(logs::warning, "Docker exec failed ({}), {}", exit_code, console);
return false;
} else {
return true;
}
}
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/moonlight-server/runners/docker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ void RunDocker::run(std::size_t session_id,
// Fake udev
auto udev_base_path = std::filesystem::path(app_state_folder) / "udev";
auto hw_db_path = udev_base_path / "data";
auto fake_udev_cli_path = std::string(utils::get_env("WOLF_DOCKER_FAKE_UDEV_PATH"));
bool use_fake_udev = !fake_udev_cli_path.empty();
auto fake_udev_cli_path = std::string(utils::get_env("WOLF_DOCKER_FAKE_UDEV_PATH", ""));
bool use_fake_udev = !fake_udev_cli_path.empty() || std::filesystem::exists(fake_udev_cli_path);
if (use_fake_udev) {
logs::log(logs::debug, "[DOCKER] Using fake-udev, creating {}", hw_db_path.string());
std::filesystem::create_directories(hw_db_path);

// Check if /run/udev/control exists
Expand All @@ -178,6 +179,10 @@ void RunDocker::run(std::size_t session_id,
}
mounts.push_back(MountPoint{.source = udev_base_path.string(), .destination = "/run/udev/", .mode = "rw"});
mounts.push_back(MountPoint{.source = fake_udev_cli_path, .destination = "/usr/bin/fake-udev", .mode = "ro"});
} else {
logs::log(logs::warning,
"[DOCKER] Unable to use fake-udev, check the env variable WOLF_DOCKER_FAKE_UDEV_PATH and the file at {}",
fake_udev_cli_path);
}
Container new_container = {.id = "",
.name = fmt::format("{}_{}", this->container.name, session_id),
Expand Down Expand Up @@ -233,7 +238,7 @@ void RunDocker::run(std::size_t session_id,
if (udev_ev.count("DEVNAME") == 0) {
cmd = fmt::format("fake-udev -m {}", udev_msg);
} else {
cmd = fmt::format("mknod {} c {} {} && chmod 777 {} && fake-udev -m {}",
cmd = fmt::format("mkdir -p /dev/input && mknod {} c {} {} && chmod 777 {} && fake-udev -m {}",
udev_ev["DEVNAME"],
udev_ev["MAJOR"],
udev_ev["MINOR"],
Expand Down
1 change: 0 additions & 1 deletion src/moonlight-server/wolf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ auto setup_sessions_handlers(const immer::box<state::AppState> &app_state,
auto input_nodes = immer::array_transient<std::string>();
std::copy(mouse_nodes.begin(), mouse_nodes.end(), std::back_inserter(input_nodes));
std::copy(kb_nodes.begin(), kb_nodes.end(), std::back_inserter(input_nodes));
std::copy(input_nodes.begin(), input_nodes.end(), std::back_inserter(all_devices));

auto wl_state = virtual_display::create_wayland_display(input_nodes.persistent(), render_node);
virtual_display::set_resolution(
Expand Down

0 comments on commit 8bef26f

Please sign in to comment.