2021-08-04 00:18:30 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-09-22 16:06:37 +01:00
|
|
|
# help
|
|
|
|
if [ "$1" = "-h" ]||[ "$1" = "--help" ];then
|
|
|
|
echo
|
2022-07-27 08:37:36 +02:00
|
|
|
echo "Script to set up or update the Core Lightning systemd service"
|
2021-09-22 16:06:37 +01:00
|
|
|
echo "Usage:"
|
2021-09-26 10:30:09 +01:00
|
|
|
echo "/home/admin/config.scripts/cl.install-service.sh <mainnet|testnet|signet>"
|
2021-09-22 16:06:37 +01:00
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-08-04 00:18:30 +02:00
|
|
|
|
2021-09-26 10:30:09 +01:00
|
|
|
# source <(/home/admin/config.scripts/network.aliases.sh getvars cl <mainnet|testnet|signet>)
|
|
|
|
source <(/home/admin/config.scripts/network.aliases.sh getvars cl $1)
|
2021-08-04 00:18:30 +02:00
|
|
|
|
2021-09-26 10:30:09 +01:00
|
|
|
if [ $(sudo -u bitcoin cat ${CLCONF} | grep -c "^sparko") -gt 0 ];then
|
|
|
|
if [ ! -f /home/bitcoin/${netprefix}cl-plugins-enabled/sparko ];then
|
2021-08-04 00:18:30 +02:00
|
|
|
echo "# The Sparko plugin is not present but in config"
|
2021-09-27 11:12:06 +01:00
|
|
|
/home/admin/config.scripts/cl-plugin.sparko.sh on $CHAIN norestart
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-10-08 16:12:43 +01:00
|
|
|
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
|
|
|
|
|
2021-09-27 11:12:06 +01:00
|
|
|
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
|
2021-08-04 00:18:30 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-09-26 10:30:09 +01:00
|
|
|
if grep -Eq "${netprefix}clEncryptedHSM=on" /mnt/hdd/raspiblitz.conf;then
|
|
|
|
if grep -Eq "${netprefix}clAutoUnlock=on" /mnt/hdd/raspiblitz.conf;then
|
2021-12-18 02:29:57 +00:00
|
|
|
passwordFile=/home/bitcoin/.${netprefix}cl.pw
|
2021-08-04 00:18:30 +02:00
|
|
|
else
|
2021-09-26 10:30:09 +01:00
|
|
|
passwordFile=/dev/shm/.${netprefix}cl.pw
|
2021-08-04 00:18:30 +02:00
|
|
|
fi
|
|
|
|
passwordInput="(cat $passwordFile;echo;cat $passwordFile) | "
|
|
|
|
encryptedHSMoption="--encrypted-hsm"
|
|
|
|
else
|
|
|
|
passwordInput=""
|
|
|
|
encryptedHSMoption=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
sudo systemctl stop ${netprefix}lightningd
|
|
|
|
sudo systemctl disable ${netprefix}lightningd
|
2021-12-20 15:07:39 +00:00
|
|
|
# based on https://github.com/ElementsProject/lightning/blob/master/contrib/init/lightningd.service
|
2021-08-04 00:18:30 +02:00
|
|
|
echo "# Create /etc/systemd/system/${netprefix}lightningd.service"
|
|
|
|
echo "
|
|
|
|
[Unit]
|
|
|
|
Description=c-lightning daemon on $CHAIN
|
2021-12-20 15:07:39 +00:00
|
|
|
Requires=${netprefix}bitcoind.service
|
|
|
|
After=${netprefix}bitcoind.service
|
|
|
|
Wants=network-online.target
|
|
|
|
After=network-online.target
|
2021-08-04 00:18:30 +02:00
|
|
|
|
|
|
|
[Service]
|
2021-09-27 11:12:06 +01:00
|
|
|
ExecStartPre=-/home/admin/config.scripts/cl.check.sh prestart $CHAIN
|
2021-12-20 15:07:39 +00:00
|
|
|
ExecStart=/bin/sh -c '${passwordInput}/usr/local/bin/lightningd \\
|
|
|
|
--conf=${CLCONF} ${encryptedHSMoption} \\
|
|
|
|
--pid-file=/run/lightningd/${netprefix}lightningd.pid'
|
|
|
|
|
|
|
|
# Creates /run/lightningd owned by bitcoin
|
|
|
|
RuntimeDirectory=lightningd
|
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
User=bitcoin
|
|
|
|
Group=bitcoin
|
2021-12-20 16:41:36 +00:00
|
|
|
# Type=forking hangs on restart
|
|
|
|
Type=simple
|
2021-12-20 15:07:39 +00:00
|
|
|
PIDFile=/run/lightningd/${netprefix}lightningd.pid
|
|
|
|
Restart=on-failure
|
|
|
|
|
2021-12-16 22:22:29 +00:00
|
|
|
TimeoutSec=240
|
2021-08-04 00:18:30 +02:00
|
|
|
RestartSec=30
|
|
|
|
StandardOutput=null
|
|
|
|
StandardError=journal
|
|
|
|
|
|
|
|
# Hardening measures
|
2021-12-20 15:07:39 +00:00
|
|
|
####################
|
|
|
|
# Provide a private /tmp and /var/tmp.
|
2021-08-04 00:18:30 +02:00
|
|
|
PrivateTmp=true
|
2021-12-20 15:07:39 +00:00
|
|
|
# Mount /usr, /boot/ and /etc read-only for the process.
|
2021-08-04 00:18:30 +02:00
|
|
|
ProtectSystem=full
|
2021-12-20 15:07:39 +00:00
|
|
|
# Disallow the process and all of its children to gain
|
|
|
|
# new privileges through execve().
|
2021-08-04 00:18:30 +02:00
|
|
|
NoNewPrivileges=true
|
2021-12-20 15:07:39 +00:00
|
|
|
# Use a new /dev namespace only populated with API pseudo devices
|
|
|
|
# such as /dev/null, /dev/zero and /dev/random.
|
2021-09-16 00:41:23 +02:00
|
|
|
PrivateDevices=true
|
2021-12-20 15:07:39 +00:00
|
|
|
# Deny the creation of writable and executable memory mappings.
|
|
|
|
MemoryDenyWriteExecute=true
|
2021-08-04 00:18:30 +02:00
|
|
|
|
|
|
|
[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"
|
|
|
|
|
2021-12-14 23:34:35 +01:00
|
|
|
source <(/home/admin/_cache.sh get state)
|
2021-09-16 22:15:54 +01:00
|
|
|
if [ "${state}" == "ready" ]; then
|
|
|
|
sudo systemctl start ${netprefix}lightningd
|
|
|
|
echo "# Started the ${netprefix}lightningd.service"
|
2021-12-16 22:22:29 +00:00
|
|
|
fi
|