From 21101f460c5d2136c8d28f5be95efaafb707581e Mon Sep 17 00:00:00 2001 From: wiz Date: Wed, 26 Feb 2020 20:16:26 +0900 Subject: [PATCH] Add pricenode one-command installer script, systemd service, README (#3997) * Add pricenode one-command installer script, systemd service, README * Update pricenode/bisq-pricenode.service Co-Authored-By: Florian Reimair * Update pricenode/install_pricenode_debian.sh Co-Authored-By: Florian Reimair Co-authored-by: Florian Reimair --- monitor/install_collectd_debian.sh | 15 ++++- pricenode/README.md | 61 ++++++++---------- pricenode/bisq-pricenode.env | 3 + pricenode/bisq-pricenode.service | 21 +++++++ pricenode/install_pricenode_debian.sh | 90 +++++++++++++++++++++++++++ 5 files changed, 151 insertions(+), 39 deletions(-) create mode 100644 pricenode/bisq-pricenode.env create mode 100644 pricenode/bisq-pricenode.service create mode 100755 pricenode/install_pricenode_debian.sh diff --git a/monitor/install_collectd_debian.sh b/monitor/install_collectd_debian.sh index 91f1ad8d1b..bf8448e5e6 100755 --- a/monitor/install_collectd_debian.sh +++ b/monitor/install_collectd_debian.sh @@ -29,8 +29,13 @@ sudo -H -i -u "${ROOT_USER}" DEBIAN_FRONTEND=noninteractive apt-get install -qq echo "[*] Preparing Bisq init script for monitoring" # remove stuff it it is there already -sudo -H -i -u "${ROOT_USER}" sed -i -e 's/-Dcom.sun.management.jmxremote //g' -e 's/-Dcom.sun.management.jmxremote.local.only=true//g' -e 's/ -Dcom.sun.management.jmxremote.host=127.0.0.1//g' -e 's/ -Dcom.sun.management.jmxremote.port=6969//g' -e 's/ -Dcom.sun.management.jmxremote.rmi.port=6969//g' -e 's/ -Dcom.sun.management.jmxremote.ssl=false//g' -e 's/ -Dcom.sun.management.jmxremote.authenticate=false//g' "${SYSTEMD_ENV_HOME}/bisq.env" -sudo -H -i -u "${ROOT_USER}" sed -i -e '/JAVA_OPTS/ s/"$/ -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=true -Dcom.sun.management.jmxremote.port=6969 -Dcom.sun.management.jmxremote.rmi.port=6969 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"/' "${SYSTEMD_ENV_HOME}/bisq.env" +for file in "${SYSTEMD_ENV_HOME}/bisq.env" "${SYSTEMD_ENV_HOME}/bisq-pricenode.env" +do + if [ -f "$file" ];then + sudo -H -i -u "${ROOT_USER}" sed -i -e 's/-Dcom.sun.management.jmxremote //g' -e 's/-Dcom.sun.management.jmxremote.local.only=true//g' -e 's/ -Dcom.sun.management.jmxremote.host=127.0.0.1//g' -e 's/ -Dcom.sun.management.jmxremote.port=6969//g' -e 's/ -Dcom.sun.management.jmxremote.rmi.port=6969//g' -e 's/ -Dcom.sun.management.jmxremote.ssl=false//g' -e 's/ -Dcom.sun.management.jmxremote.authenticate=false//g' "${file}" + sudo -H -i -u "${ROOT_USER}" sed -i -e '/JAVA_OPTS/ s/"$/ -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=true -Dcom.sun.management.jmxremote.port=6969 -Dcom.sun.management.jmxremote.rmi.port=6969 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"/' "${file}" + fi +done echo "[*] Seeding entropy from /dev/urandom" sudo -H -i -u "${ROOT_USER}" /bin/sh -c "head -1500 /dev/urandom > ${ROOT_HOME}/.rnd" @@ -50,7 +55,11 @@ sudo -H -i -u "${ROOT_USER}" systemctl enable nginx.service sudo -H -i -u "${ROOT_USER}" systemctl enable collectd.service echo "[*] Restarting services" -sudo -H -i -u "${ROOT_USER}" systemctl restart bisq.service +set +e +service bisq status >/dev/null 2>&1 +[ $? != 4 ] && sudo -H -i -u "${ROOT_USER}" systemctl restart bisq.service +service bisq-pricenode status >/dev/null 2>&1 +[ $? != 4 ] && sudo -H -i -u "${ROOT_USER}" systemctl restart bisq-pricenode.service sudo -H -i -u "${ROOT_USER}" systemctl restart nginx.service sudo -H -i -u "${ROOT_USER}" systemctl restart collectd.service diff --git a/pricenode/README.md b/pricenode/README.md index 6e62e2dbed..e8ecf576d2 100644 --- a/pricenode/README.md +++ b/pricenode/README.md @@ -28,55 +28,44 @@ To run a pricenode, you will need: - JDK 8 if you want to build and run a node locally. - The `tor` binary (e.g. `brew install tor`) if you want to run a hidden service locally. +## How to deploy for production -## How to deploy locally +### Install -### Configure +Run the one-command installer: -Export the following properties as environment variables, e.g.: +```bash +curl -s https://raw.githubusercontent.com/bisq-network/bisq/master/pricenode/install_pricenode_debian.sh | sudo bash +``` - $ export BITCOIN_AVG_PUBKEY=[your pubkey] - $ export BITCOIN_AVG_PRIVKEY=[your privkey] +At the end of the installer script, it should print your Tor onion hostname. -Or add them to your `bisq.properties` config file, e.g.: +### Setting your BitcoinAverage API keys - $ echo BITCOIN_AVG_PUBKEY=[your pubkey] >> $HOME/.config/bisq.properties - $ echo BITCOIN_AVG_PRIVKEY=[your privkey] >> $HOME/.config/bisq.properties +Open `/etc/default/bisq-pricenode.env` in a text editor and look for these lines: +```bash +BITCOIN_AVG_PUBKEY=foo +BITCOIN_AVG_PRIVKEY=bar +``` -> TIP: Using the `bisq.properties` config file has the advantage of not needing to specify environment variables in your IDE. Running the app and running tests will "just work" regardless where and how you run them. +Add your pubkey and privkey and then reload/restart bisq-pricenode service: -### Build - - ./gradlew assemble - -### Run - - java -jar ./build/libs/bisq-pricenode.jar [max-blocks] [request-interval-mins] +```bash +systemctl daemon-reload +systemctl restart bisq-pricenode +``` ### Test To manually test endpoints, run each of the following: - curl http://localhost:8080/getAllMarketPrices - curl http://localhost:8080/getFees - curl http://localhost:8080/getParams - curl http://localhost:8080/getVersion - curl http://localhost:8080/info - -### Run as Tor hidden service - -With your pricenode running at localhost:8080, run: - - tor -f torrc - -Wait for the process to report that it is "100% bootstrapped", then copy your newly-generated .onion address: - - export PRICENODE_ONION=$(cat build/tor-hidden-service/hostname) - -Test the endpoints of your hidden service via curl with the --socks5-proxy option: - - curl --socks5-hostname 127.0.0.1:9050 http://$PRICENODE_ONION/getAllMarketPrices - +``` bash +curl http://localhost:8080/getAllMarketPrices +curl http://localhost:8080/getFees +curl http://localhost:8080/getParams +curl http://localhost:8080/getVersion +curl http://localhost:8080/info +``` ## How to deploy elsewhere diff --git a/pricenode/bisq-pricenode.env b/pricenode/bisq-pricenode.env new file mode 100644 index 0000000000..56a5fe3453 --- /dev/null +++ b/pricenode/bisq-pricenode.env @@ -0,0 +1,3 @@ +BITCOIN_AVG_PUBKEY=foo +BITCOIN_AVG_PRIVKEY=bar +JAVA_OPTS="" diff --git a/pricenode/bisq-pricenode.service b/pricenode/bisq-pricenode.service new file mode 100644 index 0000000000..d18118be39 --- /dev/null +++ b/pricenode/bisq-pricenode.service @@ -0,0 +1,21 @@ +[Unit] +Description=Bisq Price Node +After=network.target + +[Service] +EnvironmentFile=/etc/default/bisq-pricenode.env +ExecStart=/bisq/bisq/bisq-pricenode 2 2 +ExecStop=/bin/kill -TERM ${MAINPID} +Restart=on-failure + +User=bisq +Group=bisq + +PrivateTmp=true +ProtectSystem=full +NoNewPrivileges=true +PrivateDevices=true +MemoryDenyWriteExecute=false + +[Install] +WantedBy=multi-user.target diff --git a/pricenode/install_pricenode_debian.sh b/pricenode/install_pricenode_debian.sh new file mode 100755 index 0000000000..7cad2a86d5 --- /dev/null +++ b/pricenode/install_pricenode_debian.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash +set -e + +echo "[*] Bisq bisq-pricenode installation script" + +##### change as necessary for your system + +SYSTEMD_SERVICE_HOME=/etc/systemd/system +SYSTEMD_ENV_HOME=/etc/default + +ROOT_USER=root +ROOT_GROUP=root +#ROOT_HOME=/root + +BISQ_USER=bisq +BISQ_GROUP=bisq +BISQ_HOME=/bisq + +BISQ_REPO_URL=https://github.com/bisq-network/bisq +BISQ_REPO_NAME=bisq +BISQ_REPO_TAG=master +BISQ_LATEST_RELEASE=$(curl -s https://api.github.com/repos/bisq-network/bisq/releases/latest|grep tag_name|head -1|cut -d '"' -f4) +BISQ_TORHS=pricenode + +TOR_PKG="tor" +#TOR_USER=debian-tor +TOR_GROUP=debian-tor +TOR_CONF=/etc/tor/torrc +TOR_RESOURCES=/var/lib/tor + +##### + +echo "[*] Upgrading apt packages" +sudo -H -i -u "${ROOT_USER}" DEBIAN_FRONTEND=noninteractive apt-get update -q +sudo -H -i -u "${ROOT_USER}" DEBIAN_FRONTEND=noninteractive apt-get upgrade -qq -y + +echo "[*] Installing Tor" +sudo -H -i -u "${ROOT_USER}" DEBIAN_FRONTEND=noninteractive apt-get install -qq -y "${TOR_PKG}" + +echo "[*] Adding Tor configuration" +if ! grep "${BISQ_TORHS}" /etc/tor/torrc >/dev/null 2>&1;then + sudo -H -i -u "${ROOT_USER}" sh -c "echo HiddenServiceDir ${TOR_RESOURCES}/${BISQ_TORHS}/ >> ${TOR_CONF}" + sudo -H -i -u "${ROOT_USER}" sh -c "echo HiddenServicePort 80 127.0.0.1:8080 >> ${TOR_CONF}" + sudo -H -i -u "${ROOT_USER}" sh -c "echo HiddenServiceVersion 2 >> ${TOR_CONF}" +fi + +echo "[*] Creating Bisq user with Tor access" +sudo -H -i -u "${ROOT_USER}" useradd -d "${BISQ_HOME}" -G "${TOR_GROUP}" "${BISQ_USER}" + +echo "[*] Creating Bisq homedir" +sudo -H -i -u "${ROOT_USER}" mkdir -p "${BISQ_HOME}" +sudo -H -i -u "${ROOT_USER}" chown "${BISQ_USER}":"${BISQ_GROUP}" ${BISQ_HOME} + +echo "[*] Cloning Bisq repo" +sudo -H -i -u "${BISQ_USER}" git config --global advice.detachedHead false +sudo -H -i -u "${BISQ_USER}" git clone --branch "${BISQ_REPO_TAG}" "${BISQ_REPO_URL}" "${BISQ_HOME}/${BISQ_REPO_NAME}" + +echo "[*] Installing OpenJDK 10.0.2 from Bisq repo" +sudo -H -i -u "${ROOT_USER}" "${BISQ_HOME}/${BISQ_REPO_NAME}/scripts/install_java.sh" + +echo "[*] Checking out Bisq ${BISQ_LATEST_RELEASE}" +sudo -H -i -u "${BISQ_USER}" sh -c "cd ${BISQ_HOME}/${BISQ_REPO_NAME} && git checkout ${BISQ_LATEST_RELEASE}" + +echo "[*] Building Bisq from source" +sudo -H -i -u "${BISQ_USER}" sh -c "cd ${BISQ_HOME}/${BISQ_REPO_NAME} && ./gradlew :pricenode:installDist -x test < /dev/null" # redirect from /dev/null is necessary to workaround gradlew non-interactive shell hanging issue + +echo "[*] Installing bisq-pricenode systemd service" +sudo -H -i -u "${ROOT_USER}" install -c -o "${ROOT_USER}" -g "${ROOT_GROUP}" -m 644 "${BISQ_HOME}/${BISQ_REPO_NAME}/pricenode/bisq-pricenode.service" "${SYSTEMD_SERVICE_HOME}" +sudo -H -i -u "${ROOT_USER}" install -c -o "${ROOT_USER}" -g "${ROOT_GROUP}" -m 644 "${BISQ_HOME}/${BISQ_REPO_NAME}/pricenode/bisq-pricenode.env" "${SYSTEMD_ENV_HOME}" + +echo "[*] Reloading systemd daemon configuration" +sudo -H -i -u "${ROOT_USER}" systemctl daemon-reload + +echo "[*] Enabling bisq-pricenode service" +sudo -H -i -u "${ROOT_USER}" systemctl enable bisq-pricenode.service + +echo "[*] Starting bisq-pricenode service" +sudo -H -i -u "${ROOT_USER}" systemctl start bisq-pricenode.service +sleep 5 +sudo -H -i -u "${ROOT_USER}" journalctl --no-pager --unit bisq-pricenode + +echo "[*] Restarting Tor" +sudo -H -i -u "${ROOT_USER}" service tor restart +sleep 5 + +echo '[*] Done!' +echo -n '[*] Access your pricenode at http://' +cat "${TOR_RESOURCES}/${BISQ_TORHS}/hostname" + +exit 0