Skip to content

Commit f903ec8

Browse files
only start funding sources for active funding source
1 parent cd8bd04 commit f903ec8

4 files changed

Lines changed: 52 additions & 10 deletions

File tree

nixos/admin-app/app.py

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@
214214
{"key": "admin", "label": "Admin App", "unit": "lnbitspi-admin.service"},
215215
]
216216
LOG_SERVICE_BY_KEY = {entry["key"]: entry for entry in LOG_SERVICE_OPTIONS}
217+
FUNDING_LOG_KEYS = {"spark", "ark", "phoenixd"}
217218

218219

219220
def _read_key_value_file(path: Path) -> dict[str, str]:
@@ -371,6 +372,10 @@ def _selected_funding_service() -> str | None:
371372
return source.get("service") or None
372373

373374

375+
def _is_selected_funding_service(service: str) -> bool:
376+
return service == _selected_funding_service()
377+
378+
374379
def _default_log_service_key() -> str:
375380
selected = _read_selected_funding_source()
376381
if selected == "phoenixd":
@@ -380,6 +385,17 @@ def _default_log_service_key() -> str:
380385
return "lnbits"
381386

382387

388+
def _visible_log_services() -> list[dict[str, str | None]]:
389+
active_funding = _read_selected_funding_source()
390+
services: list[dict[str, str | None]] = []
391+
for service in LOG_SERVICE_OPTIONS:
392+
key = str(service["key"])
393+
if key in FUNDING_LOG_KEYS and key != active_funding:
394+
continue
395+
services.append(service)
396+
return services
397+
398+
383399
def _json_response(*, data: dict[str, Any] | None = None, status_code: int = 200, **payload):
384400
body = dict(payload)
385401
if data is not None:
@@ -1778,7 +1794,7 @@ def advanced_page():
17781794
page_key="advanced",
17791795
page_title="Advanced",
17801796
include_tunnel_status=True,
1781-
log_services=LOG_SERVICE_OPTIONS,
1797+
log_services=_visible_log_services(),
17821798
default_log_service=_default_log_service_key(),
17831799
visible_services=visible_services,
17841800
)
@@ -1984,14 +2000,26 @@ def api_update_spark_seed():
19842000

19852001
if DEV_MODE:
19862002
_write_spark_mnemonic(new_mnemonic)
2003+
if _is_selected_funding_service("spark-sidecar"):
2004+
return _json_response(
2005+
status="ok",
2006+
message="Spark seed phrase updated successfully. Spark is restarting now.",
2007+
data={"service": "spark-sidecar", "action": "restart"},
2008+
)
19872009
return _json_response(
19882010
status="ok",
1989-
message="Spark seed phrase updated successfully. Spark is restarting now.",
1990-
data={"service": "spark-sidecar", "action": "restart"},
2011+
message="Spark seed phrase saved. Spark remains stopped because it is not the active funding source.",
2012+
data={"service": "spark-sidecar", "action": "none"},
19912013
)
19922014

19932015
try:
19942016
_write_spark_mnemonic(new_mnemonic)
2017+
if not _is_selected_funding_service("spark-sidecar"):
2018+
return _json_response(
2019+
status="ok",
2020+
message="Spark seed phrase saved. Spark remains stopped because it is not the active funding source.",
2021+
data={"service": "spark-sidecar", "action": "none"},
2022+
)
19952023
subprocess.run(
19962024
["systemctl", "restart", "spark-sidecar.service"],
19972025
check=True,
@@ -2031,14 +2059,26 @@ def api_update_arkade_seed():
20312059

20322060
if DEV_MODE:
20332061
_write_arkade_mnemonic(new_mnemonic)
2062+
if _is_selected_funding_service("arkade-sidecar"):
2063+
return _json_response(
2064+
status="ok",
2065+
message="Ark seed phrase updated successfully. Arkade is restarting now.",
2066+
data={"service": "arkade-sidecar", "action": "restart"},
2067+
)
20342068
return _json_response(
20352069
status="ok",
2036-
message="Ark seed phrase updated successfully. Arkade is restarting now.",
2037-
data={"service": "arkade-sidecar", "action": "restart"},
2070+
message="Ark seed phrase saved. Arkade remains stopped because it is not the active funding source.",
2071+
data={"service": "arkade-sidecar", "action": "none"},
20382072
)
20392073

20402074
try:
20412075
_write_arkade_mnemonic(new_mnemonic)
2076+
if not _is_selected_funding_service("arkade-sidecar"):
2077+
return _json_response(
2078+
status="ok",
2079+
message="Ark seed phrase saved. Arkade remains stopped because it is not the active funding source.",
2080+
data={"service": "arkade-sidecar", "action": "none"},
2081+
)
20422082
subprocess.run(
20432083
["systemctl", "restart", "arkade-sidecar.service"],
20442084
check=True,

nixos/arkade-sidecar-service.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ in
1818
after = [ "network-online.target" ];
1919
wants = [ "network-online.target" ];
2020
wantedBy = [ "multi-user.target" ];
21+
path = [ pkgs.coreutils pkgs.gnugrep ];
2122

2223
unitConfig = {
2324
ConditionPathExists = "/var/lib/lnbits/.configured";
@@ -29,7 +30,7 @@ in
2930
Group = "arkade-sidecar";
3031
StateDirectory = "arkade-sidecar";
3132
StateDirectoryMode = "0750";
32-
ExecCondition = "${pkgs.bash}/bin/bash -c 'test ! -f ${selectedFundingSourceFile} || grep -qx ark ${selectedFundingSourceFile}'";
33+
ExecCondition = "${pkgs.bash}/bin/bash -c 'test ! -f ${selectedFundingSourceFile} || ${pkgs.gnugrep}/bin/grep -qx ark ${selectedFundingSourceFile}'";
3334

3435
Environment = [
3536
"ARKADE_MNEMONIC_FILE=${mnemonicFile}"
@@ -44,7 +45,7 @@ in
4445
"ARKADE_SWAP_STORAGE_PATH=${stateDir}/arkade-swaps.sqlite"
4546
];
4647

47-
EnvironmentFile = "${stateDir}/api-key.env";
48+
EnvironmentFile = "-${stateDir}/api-key.env";
4849

4950
ExecStart = "${arkadePkg}/bin/arkade-sidecar";
5051

nixos/phoenixd-service.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ EOF
6363
User = "phoenixd";
6464
Group = "phoenixd";
6565
WorkingDirectory = homeDir;
66-
ExecCondition = "${pkgs.bash}/bin/bash -c 'test -f ${selectedFundingSourceFile} && grep -qx phoenixd ${selectedFundingSourceFile}'";
66+
ExecCondition = "${pkgs.bash}/bin/bash -c 'test -f ${selectedFundingSourceFile} && ${pkgs.gnugrep}/bin/grep -qx phoenixd ${selectedFundingSourceFile}'";
6767
ExecStart = "${pkgs.bash}/bin/bash -c 'printf \"I understand\\nI understand\\n\" | exec ${phoenixdPkg}/bin/phoenixd'";
6868
Restart = "on-failure";
6969
RestartSec = 5;

nixos/spark-sidecar-service.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ in
2424
after = [ "network-online.target" ];
2525
wants = [ "network-online.target" ];
2626
wantedBy = [ "multi-user.target" ];
27+
path = [ pkgs.coreutils pkgs.gnugrep ];
2728

2829
# Only start if the system has been configured
2930
unitConfig = {
@@ -34,7 +35,7 @@ in
3435
Type = "simple";
3536
User = "spark-sidecar";
3637
Group = "spark-sidecar";
37-
ExecCondition = "${pkgs.bash}/bin/bash -c 'test ! -f ${selectedFundingSourceFile} || grep -qx spark ${selectedFundingSourceFile}'";
38+
ExecCondition = "${pkgs.bash}/bin/bash -c 'test ! -f ${selectedFundingSourceFile} || ${pkgs.gnugrep}/bin/grep -qx spark ${selectedFundingSourceFile}'";
3839

3940
# Environment variables for Spark sidecar
4041
Environment = [
@@ -46,7 +47,7 @@ in
4647
];
4748

4849
# API key written by the configurator during first-run setup
49-
EnvironmentFile = "${stateDir}/api-key.env";
50+
EnvironmentFile = "-${stateDir}/api-key.env";
5051

5152
ExecStart = "${sparkPkg}/bin/spark-sidecar";
5253

0 commit comments

Comments
 (0)