raspiblitz/home.admin/config.scripts/cl.install-service.sh
/rootzoll 75171c09e3
merge prepare v1.9.0rc5 (#3824)
* extend sd card before fatpack (#3783)
* Fatpack sd card expand (#3784)
* extend sd card before fatpack
* fix expansion detection
* Bump lnbits to 0.10.5 and add path to poetry in systemd script (#3787)
* fix: don't reinstall same CLN version + fmt (#3796)
* fix: lnd check for rpcmiddleware (#3804)
* fix: joininbox update, hide jm api error from lcd (#3801)
* fix: hide jm api error from lcd
* joininbox update to v0.7.8
* fix: remove lnbits user when off, improve checks (#3798)
* reduce bitcoind memory usage w  MALLOC_ARENA_MAX=1 (#3780)
* Misc fixed towards v1.9.0 (#3808)
* get web api info
* #3772 increase curl timeout
* #3805 change "Please Login"
* #3807 fix cln jrpc socket access (#3815)
* Btcpay 193 (#3812)
* Update BTCPay v1.9.3
* btcpay verify with web-flow
* lnbits 0.10.6 update (#3814)
* Fatpack: LCD on & cl-plugin.cln-grpc OFF (#3817)
* make sure fatpack is LCD activated
* remove cl-plugin.cln-grpc.sh by default
* #3793 fix socket jrpc
* lndmanage 0.15.0 (#3818)

---------

Co-authored-by: Stephan Oeste <emzy@emzy.de>
Co-authored-by: openoms <43343391+openoms@users.noreply.github.com>
2023-05-11 17:12:28 +02:00

109 lines
3.6 KiB
Bash

#!/bin/bash
# help
if [ "$1" = "-h" ]||[ "$1" = "--help" ];then
echo
echo "Script to set up or update the Core Lightning systemd service"
echo "Usage:"
echo "/home/admin/config.scripts/cl.install-service.sh <mainnet|testnet|signet>"
echo
exit 1
fi
# source <(/home/admin/config.scripts/network.aliases.sh getvars cl <mainnet|testnet|signet>)
source <(/home/admin/config.scripts/network.aliases.sh getvars cl $1)
if [ $(sudo -u bitcoin cat ${CLCONF} | grep -c "^sparko") -gt 0 ];then
if [ ! -f /home/bitcoin/${netprefix}cl-plugins-enabled/sparko ];then
echo "# The Sparko plugin is not present but in config"
/home/admin/config.scripts/cl-plugin.sparko.sh on $CHAIN norestart
fi
fi
if [ $(sudo -u bitcoin cat ${CLCONF} | grep -c "^http-pass") -gt 0 ];then
if [ ! -f /home/bitcoin/cl-plugins-enabled/c-lightning-http-plugin ]; then
echo "# The clHTTPplugin is not present but in config"
/home/admin/config.scripts/cl-plugin.http.sh on norestart
fi
fi
if [ $(sudo -u bitcoin cat ${CLCONF} | grep -c "^feeadjuster") -gt 0 ];then
if [ ! -f /home/bitcoin/${netprefix}cl-plugins-enabled/feeadjuster.py ];then
echo "# The feeadjuster plugin is not present but in config"
/home/admin/config.scripts/cl-plugin.feeadjuster.sh on $CHAIN norestart
fi
fi
if grep -Eq "${netprefix}clEncryptedHSM=on" /mnt/hdd/raspiblitz.conf;then
if grep -Eq "${netprefix}clAutoUnlock=on" /mnt/hdd/raspiblitz.conf;then
passwordFile=/home/bitcoin/.${netprefix}cl.pw
else
passwordFile=/dev/shm/.${netprefix}cl.pw
fi
passwordInput="(cat $passwordFile;echo;cat $passwordFile) | "
encryptedHSMoption="--encrypted-hsm"
else
passwordInput=""
encryptedHSMoption=""
fi
sudo systemctl stop ${netprefix}lightningd
sudo systemctl disable ${netprefix}lightningd
# based on https://github.com/ElementsProject/lightning/blob/master/contrib/init/lightningd.service
echo "# Create /etc/systemd/system/${netprefix}lightningd.service"
echo "
[Unit]
Description=c-lightning daemon on $CHAIN
Requires=${netprefix}bitcoind.service
After=${netprefix}bitcoind.service
Wants=network-online.target
After=network-online.target
[Service]
ExecStartPre=-/home/admin/config.scripts/cl.check.sh prestart $CHAIN
ExecStart=/bin/sh -c '${passwordInput}/usr/local/bin/lightningd --conf=${CLCONF} ${encryptedHSMoption} --pid-file=/run/lightningd/${netprefix}lightningd.pid --rpc-file-mode 0660'
ExecStartPost=-/home/admin/config.scripts/cl.check.sh poststart $CHAIN
# Creates /run/lightningd owned by bitcoin
RuntimeDirectory=lightningd
User=bitcoin
Group=bitcoin
# Type=forking hangs on restart
Type=simple
PIDFile=/run/lightningd/${netprefix}lightningd.pid
Restart=on-failure
TimeoutSec=240
RestartSec=30
StandardOutput=null
StandardError=journal
# Hardening measures
####################
# Provide a private /tmp and /var/tmp.
PrivateTmp=true
# Mount /usr, /boot/ and /etc read-only for the process.
ProtectSystem=full
# Disallow the process and all of its children to gain
# new privileges through execve().
NoNewPrivileges=true
# Use a new /dev namespace only populated with API pseudo devices
# such as /dev/null, /dev/zero and /dev/random.
PrivateDevices=true
# Deny the creation of writable and executable memory mappings.
MemoryDenyWriteExecute=true
[Install]
WantedBy=multi-user.target
" | sudo tee /etc/systemd/system/${netprefix}lightningd.service
sudo systemctl daemon-reload
sudo systemctl enable ${netprefix}lightningd
echo "# Enabled the ${netprefix}lightningd.service"
source <(/home/admin/_cache.sh get state)
if [ "${state}" == "ready" ]; then
sudo systemctl start ${netprefix}lightningd
echo "# Started the ${netprefix}lightningd.service"
fi