refactor
This commit is contained in:
@@ -882,96 +882,39 @@ void ui_server::start() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto should_launch{true};
|
|
||||||
|
|
||||||
lock_data ui_lock(provider_type::unknown, "ui");
|
lock_data ui_lock(provider_type::unknown, "ui");
|
||||||
auto res = ui_lock.grab_lock(1U);
|
auto res = ui_lock.grab_lock(1U);
|
||||||
if (res == lock_result::success) {
|
if (res != lock_result::success) {
|
||||||
auto deadline{std::chrono::steady_clock::now() + 30s};
|
notify_and_unlock(nonce_lock);
|
||||||
std::string host{"127.0.0.1"};
|
launch_ui();
|
||||||
auto desired_port{config_->get_api_port()};
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto success{false};
|
auto deadline{std::chrono::steady_clock::now() + 30s};
|
||||||
while (not success && std::chrono::steady_clock::now() < deadline) {
|
std::string host{"127.0.0.1"};
|
||||||
success = server_.bind_to_port(host, desired_port);
|
auto desired_port{config_->get_api_port()};
|
||||||
if (success) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
utils::error::raise_error(function_name,
|
|
||||||
utils::error::create_error_message({
|
|
||||||
"failed to bind",
|
|
||||||
"host",
|
|
||||||
host,
|
|
||||||
"port",
|
|
||||||
std::to_string(desired_port),
|
|
||||||
"error",
|
|
||||||
std::to_string(get_last_net_error()),
|
|
||||||
}));
|
|
||||||
std::this_thread::sleep_for(250ms);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
auto success{false};
|
||||||
|
while (not success && std::chrono::steady_clock::now() < deadline) {
|
||||||
|
success = server_.bind_to_port(host, desired_port);
|
||||||
if (success) {
|
if (success) {
|
||||||
std::thread([this]() {
|
break;
|
||||||
for (const auto &[prov, names] : config_->get_auto_start_list()) {
|
|
||||||
for (const auto &name : names) {
|
|
||||||
try {
|
|
||||||
auto location = config_->get_mount_location(prov, name);
|
|
||||||
if (location.empty()) {
|
|
||||||
utils::error::raise_error(function_name,
|
|
||||||
utils::error::create_error_message({
|
|
||||||
"failed to auto-mount",
|
|
||||||
"provider",
|
|
||||||
provider_type_to_string(prov),
|
|
||||||
"name",
|
|
||||||
name,
|
|
||||||
"location is empty",
|
|
||||||
}));
|
|
||||||
} else if (not mount(prov, name, location)) {
|
|
||||||
utils::error::raise_error(function_name,
|
|
||||||
utils::error::create_error_message({
|
|
||||||
"failed to auto-mount",
|
|
||||||
"provider",
|
|
||||||
provider_type_to_string(prov),
|
|
||||||
"name",
|
|
||||||
name,
|
|
||||||
"mount failed",
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
} catch (const std::exception &e) {
|
|
||||||
utils::error::raise_error(function_name, e,
|
|
||||||
utils::error::create_error_message({
|
|
||||||
"failed to auto-mount",
|
|
||||||
"provider",
|
|
||||||
provider_type_to_string(prov),
|
|
||||||
"name",
|
|
||||||
name,
|
|
||||||
}));
|
|
||||||
} catch (...) {
|
|
||||||
utils::error::raise_error(function_name, "unknown error",
|
|
||||||
utils::error::create_error_message({
|
|
||||||
"failed to auto-mount",
|
|
||||||
"provider",
|
|
||||||
provider_type_to_string(prov),
|
|
||||||
"name",
|
|
||||||
name,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).join();
|
|
||||||
|
|
||||||
notify_and_unlock(nonce_lock);
|
|
||||||
|
|
||||||
if (should_launch) {
|
|
||||||
launch_ui();
|
|
||||||
should_launch = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
server_.listen_after_bind();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
utils::error::raise_error(function_name,
|
||||||
|
utils::error::create_error_message({
|
||||||
|
"failed to bind",
|
||||||
|
"host",
|
||||||
|
host,
|
||||||
|
"port",
|
||||||
|
std::to_string(desired_port),
|
||||||
|
"error",
|
||||||
|
std::to_string(get_last_net_error()),
|
||||||
|
}));
|
||||||
|
std::this_thread::sleep_for(250ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not success) {
|
||||||
utils::error::raise_error(function_name,
|
utils::error::raise_error(function_name,
|
||||||
utils::error::create_error_message({
|
utils::error::create_error_message({
|
||||||
"bind timeout (port in use)",
|
"bind timeout (port in use)",
|
||||||
@@ -980,15 +923,63 @@ void ui_server::start() {
|
|||||||
"port",
|
"port",
|
||||||
std::to_string(desired_port),
|
std::to_string(desired_port),
|
||||||
}));
|
}));
|
||||||
should_launch = false;
|
notify_and_unlock(nonce_lock);
|
||||||
}
|
|
||||||
|
|
||||||
notify_and_unlock(nonce_lock);
|
|
||||||
if (not should_launch) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notify_and_unlock(nonce_lock);
|
||||||
|
|
||||||
|
std::thread([this]() {
|
||||||
|
for (const auto &[prov, names] : config_->get_auto_start_list()) {
|
||||||
|
for (const auto &name : names) {
|
||||||
|
try {
|
||||||
|
auto location = config_->get_mount_location(prov, name);
|
||||||
|
if (location.empty()) {
|
||||||
|
utils::error::raise_error(function_name,
|
||||||
|
utils::error::create_error_message({
|
||||||
|
"failed to auto-mount",
|
||||||
|
"provider",
|
||||||
|
provider_type_to_string(prov),
|
||||||
|
"name",
|
||||||
|
name,
|
||||||
|
"location is empty",
|
||||||
|
}));
|
||||||
|
} else if (not mount(prov, name, location)) {
|
||||||
|
utils::error::raise_error(function_name,
|
||||||
|
utils::error::create_error_message({
|
||||||
|
"failed to auto-mount",
|
||||||
|
"provider",
|
||||||
|
provider_type_to_string(prov),
|
||||||
|
"name",
|
||||||
|
name,
|
||||||
|
"mount failed",
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
utils::error::raise_error(function_name, e,
|
||||||
|
utils::error::create_error_message({
|
||||||
|
"failed to auto-mount",
|
||||||
|
"provider",
|
||||||
|
provider_type_to_string(prov),
|
||||||
|
"name",
|
||||||
|
name,
|
||||||
|
}));
|
||||||
|
} catch (...) {
|
||||||
|
utils::error::raise_error(function_name, "unknown error",
|
||||||
|
utils::error::create_error_message({
|
||||||
|
"failed to auto-mount",
|
||||||
|
"provider",
|
||||||
|
provider_type_to_string(prov),
|
||||||
|
"name",
|
||||||
|
name,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).join();
|
||||||
|
|
||||||
launch_ui();
|
launch_ui();
|
||||||
|
server_.listen_after_bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_server::stop() {
|
void ui_server::stop() {
|
||||||
|
Reference in New Issue
Block a user