Home

Awesome

Lightning Azure


THIS REPOSITORY IS OUTDATED, PLEASE USE BTCPAYSERVER ONE CLICK DEPLOYMENT TO HAVE AN EASY TO USE CLIGHTNING SERVER (https://bitcoinshirt.co/how-to-create-store-accept-bitcoin/)

Instructions to deploy Lightning Server in production environment hosted in Microsoft Azure. It included: Bitcoin Core, C-Lightning, Charged, and Let's encrypt.

The following instructions assume you have Microsoft Azure subscription.

You can see the showcase video:

Lightning Charge - One Click Setup

Deploy via Microsoft Azure Portal

Click on this button and follow instructions:

Deploy to Azure

Deploy with PowerShell

Step 1: Download and install Azure PowerShell

You can do it by using PowerShell command line or manually via Web Platform Installer or MSI.

Step 2: Authenticate to Azure

In PowerShell, you first need to authenticate to azure:

# This will popup a windows to authenticate to azure
Login-AzureRmAccount 

If you have multiple subscriptions, select the one you want:

# List your subscriptions
Get-AzureRmSubscription

# Select the one you want
Get-AzureRmSubscription –SubscriptionId "your subscription" | Select-AzureRmSubscription

Step 3: Run the deployment

Create a new C-Lightning server instance:

.\deployOnAzure.ps1 -ResourceGroupName "myawesomelightning" -Network "mainnet"

Valid Network values are:

For ResourceGroupName, use only alphabetic lower case.

This might take around 5 minutes.

It will print you the DNS name of your server myawesomelightning.southcentralus.cloudapp.azure.com, you can browse to it to enjoy your lightning instance.

Deploy on Linux

TODO: Write shell scripts using Az tool, other link, other link, best link.

How to change the domain name

By default, you will have a domain name assigned ending with xxx.cloudapp.azure.com. Because Let's Encrypt does not allow us to get HTTPS certificate for the azure.com domain, you need your own domain.

Then, add a CNAME record in your name server pointing to xxx.cloudapp.azure.com.

Connect then with SSH to your VM and run

sudo su -
changedomain.sh blah.example.com

This will change the settings of Lightning and NGinx to use your domain. Upon restart, a new certificate for your domain will be requested by Let's encrypt.

How to update

Just pull the latest changes of the docker-compose and restart the docker service.

sudo su -
lightning-update.sh

How to restart

Reboot docker:

sudo su -
lightning-restart.sh

Or reboot the server:

sudo su -
reboot

How to use lightning

lightning-cli.sh is a bash file which will run lightning-cli from inside the lightning charged container.

Please check the c-lightning project or type the following command to get help.

sudo su -
lightning-cli.sh help

How to use Bitcoin

bitcoin-cli.sh is a bash file which will run bitcoin-cli from inside the bitcoind container.

You can type the following command to get help.

sudo su -
bitcoin-cli.sh help

How to connect to charged

lightning-show.sh is a bash file which will return you the credential and URL to use to connect to your lightning charge instance.

Please, check the lightning charged project for documentation on this API.

sudo su -
lightning-show.sh

Under the hood

Here are the step on provisioning done by Azure (so you can do it yourelf):

Example of /etc/environment:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
AZURE_DNS="dwoiqdwqb.westeurope.cloudapp.azure.com"
LIGHTNING_DOCKER_COMPOSE="/var/lib/waagent/custom-script/download/0/lightning-charge-azure/Production/docker-compose.btc-ltc.yml"
LIGHTNING_ENV_FILE="/var/lib/waagent/custom-script/download/0/.env"
DOWNLOAD_ROOT="/var/lib/waagent/custom-script/download/0"

Example of /etc/profile.d/lightning-env.sh:

export AZURE_DNS="dwoiqdwqb.westeurope.cloudapp.azure.com"
export LIGHTNING_DOCKER_COMPOSE="/var/lib/waagent/custom-script/download/0/lightning-charge-azure/Production/docker-compose.btc-ltc.yml"
export DOWNLOAD_ROOT="/var/lib/waagent/custom-script/download/0"
export LIGHTNING_ENV_FILE="/var/lib/waagent/custom-script/download/0/.env"

Example of .env file:

CHARGED_HOST=test-btc-ltc.forkbitpay.ninja
ACME_CA_URI=https://acme-v01.api.letsencrypt.org/directory
NBITCOIN_NETWORK=testnet
LETSENCRYPT_EMAIL=me@example.com
CHARGED_API_TOKEN=Ajz5AbE5nOy18I2o5dTZr4NyUCxqVpOY
CHARGED_IP=1.2.3.4

Example of /etc/init/start_containers.conf file:

# File is saved under /etc/init/start_containers.conf
# After file is modified, update config with : $ initctl reload-configuration

description     "Start containers (see http://askubuntu.com/a/22105 and http://askubuntu.com/questions/612928/how-to-run-docker-compose-at-bootup)"

start on filesystem and started docker
stop on runlevel [!2345]

# if you want it to automatically restart if it crashes, leave the next line in
# respawn # might cause over charge

script
    . /etc/profile.d/lightning-env.sh
    cd "`dirname $LIGHTNING_ENV_FILE`"
    docker-compose -f "$LIGHTNING_DOCKER_COMPOSE" up -d
end script

Note that AZURE_DNS is not really used anywhere except for debugging purpose. When you want to start/stop docker, for the environment variables in .env to be taken into account, you need to start from its folder:

cd "`dirname $LIGHTNING_ENV_FILE`"
docker-compose -f "$LIGHTNING_DOCKER_COMPOSE" up