fix(singbox): preserve cache.db across restarts and ensure parent directory
This commit is contained in:
@@ -923,9 +923,6 @@ function stop_main() {
|
||||
if (module_success(NFT_UC, [ "tproxy-route6-present", RT_TABLE_NAME ]))
|
||||
command_success_from_args([ "ip", "-6", "route", "flush", "table", RT_TABLE_NAME ]);
|
||||
|
||||
let cache_path = uci_core.get(CONFIG_NAME + ".settings.cache_path") || "/tmp/sing-box/cache.db";
|
||||
remove_file(cache_path);
|
||||
|
||||
let sing_box_status = command_status_from_args([ "/etc/init.d/sing-box", "stop" ]);
|
||||
command_success_from_args([ "killall", "-q", "-9", "sing-box" ]);
|
||||
if (sing_box_status != 0)
|
||||
|
||||
@@ -773,10 +773,9 @@ function heal_proxy_connectivity(ev) {
|
||||
let incident = {
|
||||
type: "proxy",
|
||||
description: "Зависание или неполный отклик прокси-порту sing-box (" + proxy_addr + ")",
|
||||
resolution: "Очищена база cache.db и выполнен перезапуск sing-box"
|
||||
resolution: "Выполнен перезапуск sing-box"
|
||||
};
|
||||
|
||||
remove_file("/tmp/sing-box/cache.db");
|
||||
// Reporting used to happen here, before the restart, so a rate-limited
|
||||
// attempt still announced a repair that never ran.
|
||||
if (!safe_proxy_restart("proxy_connectivity")) {
|
||||
|
||||
@@ -394,6 +394,10 @@ function base_config(settings, service_address, runtime_context) {
|
||||
let rewrite_ttl = int_option(settings, "dns_rewrite_ttl", "60");
|
||||
let turbo_cache = bool_option(settings, "dns_turbo_cache", false);
|
||||
let cache_path = option(settings, "cache_path", turbo_cache ? "/etc/sing-box/cache.db" : "/tmp/sing-box/cache.db");
|
||||
let cache_dir = replace(cache_path, /\/[^\/]+$/, "");
|
||||
if (cache_dir != "" && cache_dir != cache_path) {
|
||||
try { fs.mkdir(cache_dir, 0755); } catch(e) {}
|
||||
}
|
||||
let dns_config = runtime_dns.config(settings);
|
||||
if (dns_config.unsupported)
|
||||
runtime_generate_unsupported(dns_config.unsupported);
|
||||
|
||||
Reference in New Issue
Block a user