diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..3bde5a7c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,19 @@ +__pycache__ +db.sqlite3 +lndg/settings.py +frontend +node_modules +lndg-admin.txt +.vscode +.vs +gui/static/admin +gui/static/rest_framework +data/ +container +doc +scripts +.github +.git +!scripts/entrypoint.sh +!scripts/init.sh +!scripts/suinit.sh diff --git a/.env-example b/.env-example new file mode 100644 index 00000000..58b74d5a --- /dev/null +++ b/.env-example @@ -0,0 +1 @@ +IMAGE=you/lndg diff --git a/.gitignore b/.gitignore index 99dea3f7..5acb1658 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.env* +!.env-example __pycache__ db.sqlite3 lndg/settings.py @@ -8,4 +10,13 @@ lndg-admin.txt .vs gui/static/admin gui/static/rest_framework -data/ \ No newline at end of file +data/ +.DS_Store +container +doc +scripts +.github +.git +!scripts/entrypoint.sh +!scripts/init.sh +!scripts/suinit.sh diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index b3e04f34..00000000 --- a/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM python:3-alpine -ENV PYTHONUNBUFFERED 1 -RUN apk add git g++ linux-headers && git clone https://github.com/cryptosharks131/lndg /app -WORKDIR /app -RUN git checkout "master" -RUN pip install -r requirements.txt -RUN pip install supervisor whitenoise \ No newline at end of file diff --git a/README.md b/README.md index ace31eb2..b73f4649 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ services: lndg: build: . volumes: - - /home//.lnd:/root/.lnd:ro - - /home///lndg/data:/app/data:rw + - /home//.lnd:/lndg/.lnd:ro + - /home///lndg/data:/lndg/data:rw command: - sh - -c @@ -45,7 +45,7 @@ docker-compose up -d # Retrieve the admin password for login nano data/lndg-admin.txt ``` -- **This example configuration will host LNDg at http://0.0.0.0:8889. Use the machine IP to reach the LNDg instance.** +- **This example configuration will host LNDg at http://0.0.0.0:8889. Use the machine IP to reach the LNDg instance.** - **Log in to LNDg using the provided password and the username `lndg-admin`.** ### Updating @@ -121,7 +121,7 @@ To restart the uWSGI service, use the following command: ```bash sudo systemctl restart uwsgi.service -``` +``` ### Postgres Optionally, you may chose to run LNDg using a postgres database instead of the default sqlite3. @@ -173,7 +173,7 @@ LNDg will automatically act upon the suggestions it makes on the Suggests AR Act LNDg will listen for failure events in your htlc stream and record them to the dashboard when they occur. ### API Backend -The following data can be accessed at the /api endpoint: +The following data can be accessed at the /api endpoint: `payments` `paymenthops` `invoices` `forwards` `onchain` `peers` `channels` `rebalancer` `settings` `pendinghtlcs` `failedhtlcs` ### Peer Reconnection @@ -183,15 +183,15 @@ LNDg will automatically try to resolve any channels that are seen as inactive, n ### Here are some additional notes to help you get started using Auto-Fees (AF). LNDg can update your fees on a channel every 24 hours (default) if there is a suggestion listed on the fee rates page. You must make sure the `AF-Enabled` setting is set to `1` and that individual channels you want to be managed are also set to `enabled`. You can view a log of AF changes by opening the Autofees tab. -You can customize some settings of AF by updating the following settings: -`AF-FailedHTLCs` - The minimum daily failed HTLCs count in which we could trigger a fee increase (depending on flow) -`AF-Increment` - The increment size of our potential fee changes, all fee suggestions will be a multiple of this value -`AF-MaxRate` - The maximum fee rate in which we can adjust to -`AF-MinRate` - The minimum fee rate in which we can adjust to -`AF-Multiplier` - Multiplier to increase incremental movements, the larger the multiplier, the larger the incremental moves -`AF-UpdateHours` - Change the number of hours that must pass since the last fee rate change before AF may adjust the fee rate again -`AF-LowLiqLimit` - The liquidity (%) a channel must drop below before running the `Low Liquidity` fee algorithm -`AF-ExcessLimit` - The liquidity (%) a channel must go above before running the `Excess Liquidity` fee algorithm +You can customize some settings of AF by updating the following settings: +`AF-FailedHTLCs` - The minimum daily failed HTLCs count in which we could trigger a fee increase (depending on flow) +`AF-Increment` - The increment size of our potential fee changes, all fee suggestions will be a multiple of this value +`AF-MaxRate` - The maximum fee rate in which we can adjust to +`AF-MinRate` - The minimum fee rate in which we can adjust to +`AF-Multiplier` - Multiplier to increase incremental movements, the larger the multiplier, the larger the incremental moves +`AF-UpdateHours` - Change the number of hours that must pass since the last fee rate change before AF may adjust the fee rate again +`AF-LowLiqLimit` - The liquidity (%) a channel must drop below before running the `Low Liquidity` fee algorithm +`AF-ExcessLimit` - The liquidity (%) a channel must go above before running the `Excess Liquidity` fee algorithm AF Notes: 1. AF changes only trigger after `AF-UpdateHours` hours of no fee updates via LNDg @@ -225,20 +225,20 @@ Additional customization options: 6. `AR-Workers` - Define how many parallel rebalances to spin up at once. (default=1) #### Steps to start the Auto-Rebalancer: -1. Update Channel Specific Settings - a. Go to Active Channels section - b. Find the channels you would like to activate for rebalancing (this refills its outbound) - c. On far right column Click the Enable button to activate rebalancing - d. The dashboard will refresh and show AR-Target 100% - e. Adjust the AR-Target to desired % of liquidity you want to keep on remote INBOUND side. Example select 0.60 if you want 60% of the channel capacity on Remote/INBOUND side which would mean that there is 40% on Local/OUTBOUND side - f. Hit Enter - g. Dashboard will refresh in the browser - h. Make sure you enable all channels that are valuable outbound routes for you to ensure they are not used for filling up routes you have targeted (you can enable and target 100% in order to avoid any action on this channel from the rebalancer) - -2. Update Global Settings - a. Go to section Update Auto Rebalancer Settings - b. Select the global settings (sample below): - c. Click OK button to submit +1. Update Channel Specific Settings + a. Go to Active Channels section + b. Find the channels you would like to activate for rebalancing (this refills its outbound) + c. On far right column Click the Enable button to activate rebalancing + d. The dashboard will refresh and show AR-Target 100% + e. Adjust the AR-Target to desired % of liquidity you want to keep on remote INBOUND side. Example select 0.60 if you want 60% of the channel capacity on Remote/INBOUND side which would mean that there is 40% on Local/OUTBOUND side + f. Hit Enter + g. Dashboard will refresh in the browser + h. Make sure you enable all channels that are valuable outbound routes for you to ensure they are not used for filling up routes you have targeted (you can enable and target 100% in order to avoid any action on this channel from the rebalancer) + +2. Update Global Settings + a. Go to section Update Auto Rebalancer Settings + b. Select the global settings (sample below): + c. Click OK button to submit d. Once enabled is set to 1 in the global settings - the rebalancer will become active ``` Enabled: 1 @@ -248,9 +248,9 @@ Additional customization options: Global Max Fee Rate (ppm): 500 Max Cost (%): 0.6 ``` -3. Go to section Last 10 Rebalance Requests - that will show the list of the rebalancing queue and status. +3. Go to section Last 10 Rebalance Requests - that will show the list of the rebalancing queue and status. -If you want a channel not to be picked for rebalancing (i.e. it is already full with OUTBOUND capacity that you desire), enable the channel and set the AR-Target% to 100. The rebalancer will ignore the channel while selecting the channels for outbound candidates and since its INBOUND can never be above 100% it will never trigger a rebalance. +If you want a channel not to be picked for rebalancing (i.e. it is already full with OUTBOUND capacity that you desire), enable the channel and set the AR-Target% to 100. The rebalancer will ignore the channel while selecting the channels for outbound candidates and since its INBOUND can never be above 100% it will never trigger a rebalance. ## Preview Screens ### Main Dashboard @@ -283,4 +283,3 @@ If you want a channel not to be picked for rebalancing (i.e. it is already full ### View Keysend Messages (you can only receive these if you have `accept-keysend=true` in lnd.conf) ![image](https://user-images.githubusercontent.com/38626122/134045287-086d56e3-5959-4f5f-a06e-cb6d2ac4957c.png) - diff --git a/container/Dockerfile b/container/Dockerfile new file mode 100644 index 00000000..cae8d9b9 --- /dev/null +++ b/container/Dockerfile @@ -0,0 +1,31 @@ +FROM python:3-slim + +ARG LNDG_PORT=8000 +ARG SUPERVISOR=1 +ENV PYTHONUNBUFFERED 1 + +# Add group abnd user to run rootless +RUN addgroup -gid 1000 lndg && \ + useradd -r -m -s /bin/bash -g lndg -u 1000 lndg + +WORKDIR /lndg + +COPY . . + +ENV LNDG_PORT=$LNDG_PORT +ENV LNDG_SUPERVISOR=$SUPERVISOR + +RUN echo "Install pip deps" && \ + pip install --upgrade pip && \ + pip install -r requirements.txt && \ + pip install whitenoise + +RUN scripts/suinit.sh + +EXPOSE $LNDG_PORT + +VOLUME [ "/lnd", "/lndg/data" ] + +USER 1000 + +ENTRYPOINT [ "scripts/entrypoint.sh" ] diff --git a/docker-compose.yaml b/container/docker-compose.yaml similarity index 100% rename from docker-compose.yaml rename to container/docker-compose.yaml diff --git a/postgres.md b/doc/postgres.md similarity index 100% rename from postgres.md rename to doc/postgres.md diff --git a/quickstart.md b/doc/quickstart.md similarity index 100% rename from quickstart.md rename to doc/quickstart.md diff --git a/systemd.md b/doc/systemd.md similarity index 78% rename from systemd.md rename to doc/systemd.md index 4b4a52f1..12752dcd 100644 --- a/systemd.md +++ b/doc/systemd.md @@ -4,7 +4,7 @@ - **This assumes you have installed lndg on the home directory of the user. For example, user `mynode` will have a home directory of `/home/mynode/`.** ## Backend Controller Setup -Create a service file for `controller.py`, copying the contents below to the file and filling in the user you would like this to run under. +Create a service file for `controller.py`, copying the contents below to the file and filling in the user you would like this to run under. `nano /etc/systemd/system/lndg-controller.service` ``` [Unit] @@ -21,12 +21,12 @@ RestartSec=60s [Install] WantedBy=multi-user.target ``` -Enable and start the service to run the backend controller. -`sudo systemctl enable lndg-controller.service` +Enable and start the service to run the backend controller. +`sudo systemctl enable lndg-controller.service` `sudo systemctl start lndg-controller.service` ## Additional Commands -You can also check on the status, disable or stop the backend controller. -`sudo systemctl status lndg-controller.service` -`sudo systemctl disable lndg-controller.service` -`sudo systemctl stop lndg-controller.service` +You can also check on the status, disable or stop the backend controller. +`sudo systemctl status lndg-controller.service` +`sudo systemctl disable lndg-controller.service` +`sudo systemctl stop lndg-controller.service` diff --git a/gui/templates/action_list.html b/gui/templates/action_list.html index 591036c9..1d0a822e 100644 --- a/gui/templates/action_list.html +++ b/gui/templates/action_list.html @@ -61,4 +61,4 @@

Suggested Action List

Nothing to see here! Great job!

{% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/gui/templates/addresses.html b/gui/templates/addresses.html index 32dfa62e..24ed0b1c 100644 --- a/gui/templates/addresses.html +++ b/gui/templates/addresses.html @@ -27,4 +27,4 @@

{% if addresses.address_type == 1 %}Legacy{% elif addresses.address_type ==

You dont have any addresses yet.

{% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/gui/templates/advanced.html b/gui/templates/advanced.html index f0431f9f..482884d0 100644 --- a/gui/templates/advanced.html +++ b/gui/templates/advanced.html @@ -265,4 +265,4 @@

Advanced Channel Settings

} }) -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/gui/templates/channel.html b/gui/templates/channel.html index bf9cb9b8..fa0e5ad6 100644 --- a/gui/templates/channel.html +++ b/gui/templates/channel.html @@ -8,14 +8,14 @@

{{ chan_id }} {{ channel.short_chan_id }}

- {% if peer_info %}📍{{ peer_info.address }} | - Channel Updates: {{ channel.num_updates|intcomma }} | + {% if peer_info %}📍{{ peer_info.address }} | + Channel Updates: {{ channel.num_updates|intcomma }} | {% if not channel.is_open %}❌ Closed:{% elif channel.is_active %}Uptime:{% else %}Downtime:{% endif %} {{ channel.last_update|naturaltime|slice:":-4" }} since {{ channel.last_update }}{% endif %} {%if channel.private %}🕶️{%else%}🌐{%endif%}
⛓️ Channel Point: {{ channel.funding_txid }}:{{ channel.output_index }} | - Opened In: {{ channel.open_block|intcomma }} | + Opened In: {{ channel.open_block|intcomma }} | Opener: {% if channel.initiator == True %}Local{% else %}Remote{% endif %}
@@ -570,7 +570,7 @@

Channel Notes

let next_failed_htlcs = (await failedhtlcs_task).results if(next_failed_htlcs.length<5){ byId("loadMoreFailedHTLCs").style.display = "none" - } + } if(next_failed_htlcs.length==0){ return } diff --git a/gui/templates/channels.html b/gui/templates/channels.html index d394b6e1..0ab519a3 100644 --- a/gui/templates/channels.html +++ b/gui/templates/channels.html @@ -56,4 +56,4 @@

Channel Performance

You dont have any channels to analyze yet!

{% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/gui/templates/fee_rates.html b/gui/templates/fee_rates.html index c549b3cd..0ce4fc77 100644 --- a/gui/templates/fee_rates.html +++ b/gui/templates/fee_rates.html @@ -87,4 +87,4 @@

Suggested Fee Rates

{% if local_settings %} {% include 'local_settings.html' with settings=local_settings title='Auto-Fees' postURL='update_setting' %} {% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/gui/templates/home.html b/gui/templates/home.html index 0ecb7c70..a73b1946 100644 --- a/gui/templates/home.html +++ b/gui/templates/home.html @@ -45,7 +45,7 @@ - Addresses: + Addresses: {% for addr in node_info.uris %}
{{ addr }} @@ -138,10 +138,10 @@
\ No newline at end of file + diff --git a/gui/templates/peers.html b/gui/templates/peers.html index d9e0e138..e0a4f4cc 100644 --- a/gui/templates/peers.html +++ b/gui/templates/peers.html @@ -46,4 +46,4 @@

Peers List {% if status == 2 %}Successful{% elif status == 0 %}Pending{% elif status = const response = await POST('rebalancer', {body: new_rebal}) const table = input.parentElement.parentElement.parentElement table.prepend(use(transformations).render(response)) - } + } } else { input.innerHTML = "❌" - input.title="Cancel this request" + input.title="Cancel this request" input.onclick = async function(){ const response = await PUT(`rebalancer/${rebalance.id}`, {body: {status: 499}}) - + const table = input.parentElement.parentElement.parentElement const index = input.parentElement.parentElement.rowIndex -1 table.deleteRow(index) use(transformations).render(response, table.insertRow(index)) } - } + } return {innerHTML: input} - } + } }; async function buildTable(){ const res = await GET('rebalancer', {data: {limit: '{{count}}', status: '{{status}}', payment_hash: '{{payment_hash}}', last_hop_pubkey: '{% if last_hop_pubkey %}{{last_hop_pubkey}}{%else%}{{request.GET.last_hop_pubkey}}{%endif%}' }}) diff --git a/gui/templates/rebalancing.html b/gui/templates/rebalancing.html index dc981b72..82710752 100644 --- a/gui/templates/rebalancing.html +++ b/gui/templates/rebalancing.html @@ -71,7 +71,7 @@
Manual Rebalance R updateCols(['rebalance'], this, new_value) } }), - "ar_max_cost": ch => ({innerHTML: ``, + "ar_max_cost": ch => ({innerHTML: ``, changed: function(new_value){ updateCols(['ar_max_cost', 'fee_ratio'], this, new_value) } @@ -143,7 +143,7 @@
Manual Rebalance R ch.fee_check = parseInt(ch.fee_ratio*100/ch.ar_max_cost) ch.steps = parseInt(ch.inbound_can < 1 ? 0 : ((ch.percent_inbound - ch.ar_in_target)/(ch.ar_amt_target*100/ch.capacity)+0.999)) - ch.elegible = ch.inbound_can >= 1 && ch.fee_check < 100 && ch.auto_rebalance, + ch.elegible = ch.inbound_can >= 1 && ch.fee_check < 100 && ch.auto_rebalance, ch.available = ch.is_active && !ch.auto_rebalance && ch.percent_outbound / ch.ar_out_target >=1 return ch } @@ -174,7 +174,7 @@
Manual Rebalance R return ch1.percent_outbound - ch2.percent_outbound }) .forEach(ch => rebal_table.append(template.render(ch, 'chan_id'))) - + update_stats(await rebal_stats, rebal_table) }) function update_stats(stats, rebal_table){ diff --git a/gui/templates/resolutions.html b/gui/templates/resolutions.html index 123e2a48..f9c357e0 100644 --- a/gui/templates/resolutions.html +++ b/gui/templates/resolutions.html @@ -30,4 +30,4 @@

Resolutions For Channel: {{ chan_id }}

No resolutions were found for this channel!

{% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/initialize.py b/initialize.py index b2ff07ec..b57f8a7f 100644 --- a/initialize.py +++ b/initialize.py @@ -218,11 +218,11 @@ def write_supervisord_settings(sduser): stdout_logfile_maxbytes = 150MB stdout_logfile_backups = 15 ''' % (sduser, supervisord_secret, supervisord_secret, BASE_DIR) - if Path("/usr/local/supervisord.conf").exists(): + if Path("supervisord.conf").exists(): print('A supervisord settings file already exist, skipping creation...') return try: - with open("/usr/local/supervisord.conf", "w") as f: + with open("supervisord.conf", "w") as f: f.write(supervisord_settings_file) except Exception as e: print('Error creating the settings file: ', str(e)) @@ -253,7 +253,7 @@ def initialize_django(adminuser, adminpw): 'rest_framework', 'gui', ], - STATIC_URL = 'static/', + STATIC_URL = 'static/', STATIC_ROOT = os.path.join(BASE_DIR, 'gui/static/') ) django.setup() @@ -290,7 +290,7 @@ def main(): parser.add_argument('-rpc', '--rpcserver', help = 'Server address to use for rpc communications with LND', default='localhost:10009') parser.add_argument('-maxmsg', '--maxmessage', help = 'Maximum message size for grpc communications (MB)', default='35') parser.add_argument('-sd', '--supervisord', help = 'Setup supervisord to run jobs/rebalancer background processes', action='store_true') - parser.add_argument('-sdu', '--sduser', help = 'Configure supervisord with a non-root user', default='root') + parser.add_argument('-sdu', '--sduser', help = 'Configure supervisord with a non-root user', default='lndg') parser.add_argument('-wn', '--whitenoise', help = 'Add whitenoise middleware (docker requirement for static files)', action='store_true') parser.add_argument('-d', '--docker', help = 'Single option for docker container setup (supervisord + whitenoise)', action='store_true') parser.add_argument('-dx', '--debug', help = 'Setup the django site in debug mode', action='store_true') @@ -333,4 +333,4 @@ def main(): initialize_django(adminuser, adminpw) if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/justfile b/justfile new file mode 100644 index 00000000..c096200a --- /dev/null +++ b/justfile @@ -0,0 +1,24 @@ +build_image: + #!/usr/bin/env bash + IMAGE=${IMAGE:-cryptosharks131/lndg} + + # Hacky but the version does not seem to be extracted elsewhere... + VERSION=$(cat gui/templates/base.html | sed -nE 's/.*LNDg v([0-9]+\.[0-9]+\.[0-9]+).*/\1/p') + echo "Building image $IMAGE:$VERSION" + + docker build \ + --progress=plain \ + -t $IMAGE:$VERSION \ + -t $IMAGE:latest \ + --build-arg SUPERVISOR=1 \ + -f container/Dockerfile \ + . + docker images | grep lndg + +push_image: + #!/usr/bin/env bash + IMAGE=${IMAGE:-cryptosharks131/lndg} + # Hacky but the version does not seem to be extracted elsewhere... + VERSION=$(cat gui/templates/base.html | sed -nE 's/.*LNDg v([0-9]+\.[0-9]+\.[0-9]+).*/\1/p') + docker push $IMAGE:latest + docker push $IMAGE:$VERSION diff --git a/p2p.py b/p2p.py index e09abe5e..69139305 100644 --- a/p2p.py +++ b/p2p.py @@ -43,8 +43,8 @@ def main(): finally: if 'p2p_thread' in locals() and p2p_thread.is_alive(): print(f"{datetime.now().strftime('%c')} : [P2P] : Removing any remaining processes...") - p2p_thread.terminate() + p2p_thread.terminate() sleep(20) if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/rebalancer.py b/rebalancer.py index b7be43cb..e153aa4e 100644 --- a/rebalancer.py +++ b/rebalancer.py @@ -203,11 +203,11 @@ def auto_schedule() -> List[Rebalancer]: enabled = 0 if enabled == 0: return [] - + auto_rebalance_channels = Channels.objects.filter(is_active=True, is_open=True, private=False).annotate(percent_outbound=((Sum('local_balance')+Sum('pending_outbound'))*100)/Sum('capacity')).annotate(inbound_can=(((Sum('remote_balance')+Sum('pending_inbound'))*100)/Sum('capacity'))/Sum('ar_in_target')) if len(auto_rebalance_channels) == 0: return [] - + if not LocalSettings.objects.filter(key='AR-Outbound%').exists(): LocalSettings(key='AR-Outbound%', value='75').save() if not LocalSettings.objects.filter(key='AR-Inbound%').exists(): @@ -217,7 +217,7 @@ def auto_schedule() -> List[Rebalancer]: inbound_cans = auto_rebalance_channels.filter(auto_rebalance=True, inbound_can__gte=1).exclude(remote_pubkey__in=already_scheduled).order_by('-inbound_can') if len(inbound_cans) == 0 or len(outbound_cans) == 0: return [] - + if LocalSettings.objects.filter(key='AR-MaxFeeRate').exists(): max_fee_rate = int(LocalSettings.objects.filter(key='AR-MaxFeeRate')[0].value) else: @@ -244,7 +244,7 @@ def auto_schedule() -> List[Rebalancer]: target_fee = round(target_fee_rate*target_value*0.000001, 3) if target_fee_rate <= max_fee_rate else round(max_fee_rate*target_value*0.000001, 3) if target_fee == 0: continue - + if LocalSettings.objects.filter(key='AR-Time').exists(): target_time = int(LocalSettings.objects.filter(key='AR-Time')[0].value) else: @@ -354,7 +354,7 @@ async def async_queue_manager(rebalancer_queue): scheduled_rebalances.append(rebalance.id) await rebalancer_queue.put(rebalance) elif rebalancer_queue.qsize() == 0 and len(active_rebalances) == 0: - print(f"{datetime.now().strftime('%c')} : [Rebalancer] : Queue is still empty, stoping the rebalancer...") + print(f"{datetime.now().strftime('%c')} : [Rebalancer] : Queue is still empty, stopping the rebalancer...") shutdown_rebalancer = True return await asyncio.sleep(30) diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh new file mode 100755 index 00000000..c03b9ea1 --- /dev/null +++ b/scripts/entrypoint.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -e + +LNDG_SUPERVISOR=${LNDG_SUPERVISOR:-1} +LNDG_LISTEN=${LNDG_LISTEN:-0.0.0.0} +LNDG_PORT=${LNDG_PORT:-8000} + +scripts/init.sh + +if [ "$LNDG_SUPERVISOR" -eq "1" ]; then + echo "Starting supervisor" + supervisord +else + echo "Supervisor disabled, you need to setup an alternate method to run controller.py" +fi + +echo "Starting lndg server" +python manage.py runserver $LNDG_LISTEN:$LNDG_PORT diff --git a/scripts/init.sh b/scripts/init.sh new file mode 100755 index 00000000..b4052f87 --- /dev/null +++ b/scripts/init.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# This init script runs when the container start, as rootless + +LNDG_SUPERVISOR=${LNDG_SUPERVISOR:-1} +LNDG_NETWORK=${LNDG_NETWORK:-mainnet} +LNDG_SERVER=${LNDG_SERVER:-localhost:10009} + +echo "Initializing lndg for $LNDG_NETWORK network running on docker" + +if [ "$LNDG_SUPERVISOR" -eq "1" ]; then + echo "Initializing with supervisor running as lndg user" + python initialize.py \ + -net $LNDG_NETWORK \ + -rpc $LNDG_SERVER \ + --docker \ + --supervisord \ + --sduser lndg +else + echo "Initializing without supervisor" + python initialize.py \ + -net $LNDG_NETWORK \ + -rpc $LNDG_SERVER \ + --docker +fi diff --git a/nginx.sh b/scripts/nginx.sh similarity index 100% rename from nginx.sh rename to scripts/nginx.sh diff --git a/scripts/suinit.sh b/scripts/suinit.sh new file mode 100755 index 00000000..29ce0d41 --- /dev/null +++ b/scripts/suinit.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +LNDG_SUPERVISOR=${LNDG_SUPERVISOR:-1} + +# This init script runs when the image is created, as root +touch /var/log/supervisord.log +chown lndg /var/log/supervisord.log + +mkdir -p /lndg/data/ +chown -R lndg /lndg + +if [ "$LNDG_SUPERVISOR" -eq "1" ]; then + pip install supervisor + chgrp lndg /usr/local/etc + chmod g+rw /usr/local/etc +else + echo "Supervisor disabled, you need to setup an alternate method to run controller.py" +fi diff --git a/systemd.sh b/scripts/systemd.sh similarity index 100% rename from systemd.sh rename to scripts/systemd.sh