Skip to main content

Starting and stopping LND

Where we are now

At this point you should have four (4) windows open on your Ubuntu desktop.

  1. The TOR container running, showing logs.
  2. The Bitcoind container running, showing logs.
  3. The LND container running, showing logs.
  4. The pworker container running, showing logs.

If one of those containers isn't running, you should start it.

From now on, all of those 4 containers have to run 24/7. If you stop one by accident, start it again.


Should you run all these containers on startup?

Most Lightning Node guides, at this point, provide some suggestions on how to "schedule" our software to run automatically on boot.

But I personally do not recommend this.

For one thing, there are situations which, if your node loses data due to a hardware issue, and then restarts, you could lose funds. I will be covering this later in The Death Of A Routing Node.

But there's actually a much more simple reason that you should not try to run your node on startup.

Let's try starting and stopping our node, and the reason will become apparent.

Let's practice starting and stopping our node.

You should have four (4) Terminal windows open now on your Ubuntu desktop.

Press CNTRL-ALT-T to open a new window. This new window will be window #5.

In window #5, get onto the command line in your LND container using our script:

./exec-lncli.sh

Now, run this command:

lncli stop

When you do this, you should quickly see changes in the window (#3) where the LND container is running. You should see something like this:

lnd-lnd-1  | 2024-03-29 11:30:27.293 [INF] RPCS: Stopping PeersRPC Sub-RPC Server
lnd-lnd-1 | 2024-03-29 11:30:27.294 [INF] RPCS: Stopping SignRPC Sub-RPC Server
lnd-lnd-1 | 2024-03-29 11:30:27.294 [INF] RPCS: Stopping VersionRPC Sub-RPC Server
lnd-lnd-1 | 2024-03-29 11:30:27.294 [INF] TORC: Stopping tor controller
lnd-lnd-1 | 2024-03-29 11:30:27.295 [INF] LNWL: Stopping web API fee estimator
lnd-lnd-1 | 2024-03-29 11:30:27.296 [INF] LTND: Shutdown complete

You can see that this lncli stop command has done a few shutdown and cleanup steps.

It's important that you know that you should...

Only stop LND using this shutdown command.

For the future, if you need to shut down or restart your node, follow these rules:

  1. Don't just close the LND window.
  2. Don't press CNTRL-C in the LND window to kill it.
  3. Don't just restart the computer.

Every time you want to stop LND, you need to run lncli stop

This is important, because at the moment you want to shut down LND, it might be in the middle of important and complicated channel management processes, and you want it to shut down "gracefully".

Now, let's start LND again

Go back in the LND terminal window, and run our startup script.

./start-lnd.sh

You should see this:

 Waiting for wallet encryption password. Use `lncli create` to create a wallet, `lncli unlock` to unlock an existing wallet, or `lncli changepassword` to change the password of an existing wallet and unlock it.

So. LND is actually refusing to start until you enter the password!

To enter the password, go back to window #5, and run these commands:

./exec-lncli.sh
lncli unlock

... Then enter your password.

So, you can see even if you did set up these containers to run on boot, you could never boot the computer on an unattended basis, because you won't be there to enter the password!

Does this seem crazy to you?

If you have experience working with web services, you might know that many managed-platform providers actually auto-restart all applications once every 24 hours. For example, on Heroku:

Dynos are also restarted (cycled) at least once per day to help maintain the health of applications running on Heroku.

You see, web applications like Django or Wordpress or Ruby On Rails or Next.js have certain qualities which allow them to be restarted with very little downtime:

  1. Web applications tend to boot very quickly
  2. Web applications don't need to constantly sync a blockchain
  3. You can run multiple instances of Web application, and while one instance restarts, the other instances can respond to requests

A Lightning node is completely different:

  1. You can't run multiple instances of a Lightning node
  2. Lightning nodes need to be online 24/7 to sync the blockchain and forward payments
  3. You should not store your Lightning node password on the computer, so the only safe way to provide the password is to type it in manually

This is just my advice, you can disagree with me

In other tutorials, you will see a systemd script which boots LND automatically on startup. You could do something similar for our Docker setup by scheduling the Docker containers to run on boot (I would actually do this without systemd, just with Ubuntu startup scripts instead), but again, I don't recommend this. You would have to store the password on disk (similar to what I recommend for a Watchtower node), and if someone steals your computer, all they have to do it plug it in, and they can access your funds...