talaia-labs / rust-teos

The Eye of Satoshi - Lightning Watchtower
https://talaia.watch
MIT License
128 stars 62 forks source link

Make `teosd.service` wait for `bitcoind.service` #187

Closed sr-gi closed 1 year ago

sr-gi commented 1 year ago

teosd.service currently has a static wait before starting to give bitcoind some time to bootstrap. This is not optimal, we should find a better solution for it.

Notice that not waiting for bitcoind will make us hit:

ubuntu@ip-172-31-49-181:~$ systemctl status teosd
○ teosd.service - The Eye of Satoshi daemon
     Loaded: loaded (/etc/systemd/system/teosd.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Sat 2023-01-28 00:51:13 UTC; 19s ago
    Process: 556 ExecStart=/home/teos/.cargo/bin/teosd (code=exited, status=0/SUCCESS)
   Main PID: 556 (code=exited, status=0/SUCCESS)
        CPU: 27ms

Jan 28 00:51:12 ip-172-31-49-181 systemd[1]: Started The Eye of Satoshi daemon.
Jan 28 00:51:13 ip-172-31-49-181 teos[556]: 2023-01-28T00:51:13.271Z INFO  [teosd] Loading configuration from file
Jan 28 00:51:13 ip-172-31-49-181 teos[556]: 2023-01-28T00:51:13.332Z INFO  [teosd] tower_id: 02c424dad8d8a2e688dcb013df14c182ade2450f7a0828435a524199318431b78a
Jan 28 00:51:13 ip-172-31-49-181 teos[556]: 2023-01-28T00:51:13.492Z ERROR [teosd] Failed to connect to bitcoind. Error: Loading wallet…
Jan 28 00:51:13 ip-172-31-49-181 systemd[1]: teosd.service: Deactivated successfully.

See https://github.com/talaia-labs/rust-teos/pull/183#issuecomment-1418826258 for more context.

mariocynicys commented 1 year ago

If set to on-failure, the service will be restarted when the process exits with a non-zero exit code, is terminated by a signal (including on core dump, but excluding the aforementioned four signals), when an operation (such as service reload) times out, and when the configured watchdog timeout is triggered.

source: systemd docs

A restart isn't triggered because systemd thinks that teosd exited successfully (Main PID: 556 (code=exited, status=0/SUCCESS)). Exiting with a non-zero exit code on bitcoind-related errors should trigger a restart.

sr-gi commented 1 year ago

Ohhh, I see...

https://github.com/talaia-labs/rust-teos/blob/master/teos/src/main.rs#L161

PS: Gave this a try, and changing return by std::process::exit(1) does the trick