mirror of
https://github.com/Retropex/apolloapi-v2.git
synced 2025-05-15 20:50:48 +02:00
Updated services
This commit is contained in:
parent
e89ab0714f
commit
56588c1385
234
backend/image_install
Normal file
234
backend/image_install
Normal file
@ -0,0 +1,234 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Apollo Core Services Image Installer
|
||||||
|
|
||||||
|
#### SETUP ####
|
||||||
|
#########################
|
||||||
|
# Set colors
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
# Check if script is being run as root
|
||||||
|
if [ "$EUID" -ne 0 ]
|
||||||
|
then echo -e "${RED}Install script must be run by root or with sudo${NC}"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
#### SYSTEM PACKAGES ####
|
||||||
|
#########################
|
||||||
|
echo -e "${YELLOW} ---> Installing and upgrading required system packages${NC}"
|
||||||
|
|
||||||
|
# Install required system packages
|
||||||
|
apt-get update
|
||||||
|
apt-get -y upgrade
|
||||||
|
|
||||||
|
DEBIAN_FRONTEND=noninteractive apt-get -y -q install tor sqlite3 htop net-tools iputils-ping zip unzip whois traceroute vim openssh-server curl git libvips-dev libssl-dev libxslt-dev libxml2-dev imagemagick libmagickwand-dev libreadline-dev zlib1g-dev libsqlite3-dev libpq-dev libxml2-dev yasm libzmq3-dev build-essential libxslt1-dev python2-dev python-dev-is-python3 vim git sudo iptables network-manager
|
||||||
|
|
||||||
|
#### SYSTEM SETUP ####
|
||||||
|
#########################
|
||||||
|
# Define the APOLLO_DIR variable
|
||||||
|
APOLLO_DIR=/opt/apolloapi
|
||||||
|
APOLLO_UI_DIR=/opt/apolloapi/apolloui-v2
|
||||||
|
|
||||||
|
echo -e "${YELLOW} ---> Adding futurebit user${NC}"
|
||||||
|
|
||||||
|
# Add the futurebit user
|
||||||
|
adduser -q --disabled-password --gecos "" futurebit
|
||||||
|
|
||||||
|
# Add futurebit to the sudoers file
|
||||||
|
grep -qxF 'futurebit ALL=(ALL) NOPASSWD:ALL' /etc/sudoers || echo 'futurebit ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
||||||
|
|
||||||
|
#### APP SETUP ####
|
||||||
|
#########################
|
||||||
|
# Clone the Apollo app
|
||||||
|
echo -e "${YELLOW} ---> Cloning Apollo app${NC}"
|
||||||
|
|
||||||
|
mkdir -p $APOLLO_DIR
|
||||||
|
|
||||||
|
if [ "$1" = "dev" ]; then
|
||||||
|
echo -e "${YELLOW} ---> Using DEV branch${NC}"
|
||||||
|
git clone --single-branch --branch dev https://github.com/jstefanop/apolloapi-v2.git $APOLLO_DIR
|
||||||
|
rm -rf $APOLLO_DIR/apolloui
|
||||||
|
git clone --single-branch --branch dev https://github.com/jstefanop/apolloui-v2.git $APOLLO_UI_DIR
|
||||||
|
else
|
||||||
|
echo -e "${YELLOW} ---> Using PRODUCTION branch${NC}"
|
||||||
|
git clone --single-branch --branch main https://github.com/jstefanop/apolloapi-v2.git $APOLLO_DIR
|
||||||
|
rm -rf $APOLLO_DIR/apolloui
|
||||||
|
git clone --single-branch --branch main https://github.com/jstefanop/apolloui-v2.git $APOLLO_UI_DIR
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Navigate to the /opt/apolloapi directory
|
||||||
|
cd $APOLLO_DIR
|
||||||
|
|
||||||
|
#### NVM SETUP ####
|
||||||
|
#########################
|
||||||
|
# Install NVM
|
||||||
|
echo -e "${YELLOW} ---> Installing NVM${NC}"
|
||||||
|
|
||||||
|
mkdir /usr/local/nvm
|
||||||
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | NVM_DIR=/usr/local/nvm bash
|
||||||
|
|
||||||
|
. /usr/local/nvm/nvm.sh
|
||||||
|
|
||||||
|
# Define the NVM_DIR variable
|
||||||
|
NVM_DIR_LINE='export NVM_DIR="/usr/local/nvm"'
|
||||||
|
|
||||||
|
# Define the NVM sourcing line
|
||||||
|
NVM_SOURCE_LINE='[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm'
|
||||||
|
|
||||||
|
# Add the lines to the user's ~/.bashrc file
|
||||||
|
echo "$NVM_DIR_LINE" >> /home/futurebit/.bashrc
|
||||||
|
echo "$NVM_SOURCE_LINE" >> /home/futurebit/.bashrc
|
||||||
|
|
||||||
|
echo -e "${GREEN} ---> Lines added to /home/futurebit/.bashrc${NC}"
|
||||||
|
|
||||||
|
# Enable nvm for the current shell session
|
||||||
|
eval "$NVM_DIR_LINE"
|
||||||
|
eval "$NVM_SOURCE_LINE"
|
||||||
|
|
||||||
|
# Change ownership of /usr/local/nvm to user "futurebit"
|
||||||
|
chown -R futurebit /usr/local/nvm
|
||||||
|
echo -e "${GREEN} ---> Changed ownership of /usr/local/nvm to futurebit${NC}"
|
||||||
|
|
||||||
|
# Install Node.js version 21 using nvm
|
||||||
|
nvm install 21.6.2
|
||||||
|
echo -e "${GREEN} ---> Node.js version 21 installed${NC}"
|
||||||
|
|
||||||
|
# Install yarn globally
|
||||||
|
nvm use 21.6.2
|
||||||
|
npm i -g yarn
|
||||||
|
echo -e "${GREEN} ---> Yarn installed globally${NC}"
|
||||||
|
|
||||||
|
#### APOLLO SETUP ####
|
||||||
|
# Install API dependencies
|
||||||
|
# Navigate to the /opt/apolloapi directory
|
||||||
|
echo -e "${YELLOW} ---> Installing API dependencies${NC}"
|
||||||
|
cd $APOLLO_DIR
|
||||||
|
|
||||||
|
# Generate a random string for APP_SECRET
|
||||||
|
APP_SECRET=$(openssl rand -hex 16)
|
||||||
|
|
||||||
|
# Create the .env file with the specified content
|
||||||
|
echo "APP_SECRET=$APP_SECRET" > .env
|
||||||
|
echo "DATABASE_URL=$APOLLO_DIR/futurebit.sqlite" >> .env
|
||||||
|
|
||||||
|
echo -e "${GREEN} ---> .env file created with random APP_SECRET${NC}"
|
||||||
|
|
||||||
|
# Install project dependencies using yarn
|
||||||
|
yarn cache clean
|
||||||
|
yarn
|
||||||
|
echo -e "${GREEN} ---> Project API dependencies installed using yarn${NC}"
|
||||||
|
|
||||||
|
# Install UI dependencies
|
||||||
|
# Navigate to the /opt/apolloui directory
|
||||||
|
echo -e "${YELLOW} ---> Installing UI dependencies${NC}"
|
||||||
|
cd $APOLLO_UI_DIR
|
||||||
|
|
||||||
|
# Generate a random string for NEXTAUTH_SECRET
|
||||||
|
NEXTAUTH_SECRET=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)
|
||||||
|
|
||||||
|
# Create the .env file with the specified content
|
||||||
|
echo "NEXT_PUBLIC_POLLING_TIME=5000" >> .env
|
||||||
|
echo "NEXT_PUBLIC_POLLING_TIME_NODE=30000" >> .env
|
||||||
|
echo "NEXTAUTH_SECRET='$NEXTAUTH_SECRET'" >> .env
|
||||||
|
|
||||||
|
echo -e "${GREEN} ---> .env file created with random NEXTAUTH_SECRET${NC}"
|
||||||
|
#increase timeout for sd card installs
|
||||||
|
yarn install --network-timeout 600000
|
||||||
|
# Install project dependencies using yarn
|
||||||
|
yarn cache clean
|
||||||
|
yarn
|
||||||
|
echo -e "${GREEN} ---> Project UI dependencies installed using yarn${NC}"
|
||||||
|
|
||||||
|
# Build the project
|
||||||
|
yarn build
|
||||||
|
echo -e "${GREEN} ---> Project built using yarn${NC}"
|
||||||
|
|
||||||
|
|
||||||
|
### FIREWALL ###
|
||||||
|
#########################
|
||||||
|
echo -e "${YELLOW} ---> Starting firewall${NC}"
|
||||||
|
|
||||||
|
bash $APOLLO_DIR/backend/firewall
|
||||||
|
|
||||||
|
#### MINER SETUP ####
|
||||||
|
#########################
|
||||||
|
echo -e "${YELLOW} ---> Installing miner binaries${NC}"
|
||||||
|
|
||||||
|
arch=$(uname -m)
|
||||||
|
|
||||||
|
cp $APOLLO_DIR/backend/apollo-miner/bin/$arch/apollo-miner $APOLLO_DIR/backend/apollo-miner/futurebit-miner
|
||||||
|
cp $APOLLO_DIR/backend/apollo-miner/bin/$arch/apollo-miner-v2 $APOLLO_DIR/backend/apollo-miner/futurebit-miner-v2
|
||||||
|
cp $APOLLO_DIR/backend/apollo-miner/bin/$arch/apollo-helper $APOLLO_DIR/backend/apollo-miner/
|
||||||
|
|
||||||
|
### Bitcoind ###
|
||||||
|
#########################
|
||||||
|
cp $APOLLO_DIR/backend/node/bin/$arch/bitcoind $APOLLO_DIR/backend/node/bitcoind
|
||||||
|
cp $APOLLO_DIR/backend/default-configs/bitcoin.conf $APOLLO_DIR/backend/node/
|
||||||
|
|
||||||
|
### ckpool ###
|
||||||
|
#########################
|
||||||
|
#cp $APOLLO_DIR/backend/ckpool/bin/$arch/ckpool $APOLLO_DIR/backend/ckpool/ TODO UPDATE BINARIES
|
||||||
|
cp $APOLLO_DIR/backend/default-configs/ckpool.conf $APOLLO_DIR/backend/ckpool/
|
||||||
|
|
||||||
|
### TOR ###
|
||||||
|
#########################
|
||||||
|
usermod -a -G debian-tor futurebit
|
||||||
|
cp $APOLLO_DIR/backend/torrc /etc/tor/torrc
|
||||||
|
|
||||||
|
# Change ownership of /opt/apolloapi to user "futurebit"
|
||||||
|
chown -R futurebit $APOLLO_DIR
|
||||||
|
|
||||||
|
#### SYSTEMD SETUP ####
|
||||||
|
#########################
|
||||||
|
# Setting up systemd services
|
||||||
|
echo -e "${YELLOW} ---> Setting up systemd services${NC}"
|
||||||
|
|
||||||
|
# Copy the apollo-api.service file to /etc/systemd/system
|
||||||
|
cp $APOLLO_DIR/backend/systemd/apollo-api.service /etc/systemd/system/
|
||||||
|
|
||||||
|
# Copy the apollo-ui.service file to /etc/systemd/system
|
||||||
|
cp $APOLLO_DIR/backend/systemd/apollo-ui-v2.service /etc/systemd/system/
|
||||||
|
|
||||||
|
# Copy the node.service file to /etc/systemd/system
|
||||||
|
cp $APOLLO_DIR/backend/systemd/node.service /etc/systemd/system/
|
||||||
|
|
||||||
|
# Copy the ckpool.service file to /etc/systemd/system
|
||||||
|
cp $APOLLO_DIR/backend/systemd/ckpool.service /etc/systemd/system/
|
||||||
|
cp $APOLLO_DIR/backend/default-configs/ckpool.conf $APOLLO_DIR/backend/ckpool/
|
||||||
|
|
||||||
|
# Copy the apollo-miner.service file to /etc/systemd/system
|
||||||
|
cp $APOLLO_DIR/backend/systemd/apollo-miner.service /etc/systemd/system/
|
||||||
|
|
||||||
|
#SWAP
|
||||||
|
cp $APOLLO_DIR/backend/systemd/swap.service /etc/systemd/system/
|
||||||
|
|
||||||
|
#RC LOCAL
|
||||||
|
cp $APOLLO_DIR/backend/rc.local /etc/
|
||||||
|
chmod +x /etc/rc.local
|
||||||
|
cp $APOLLO_DIR/backend/systemd/rc-local.service /etc/systemd/system/
|
||||||
|
|
||||||
|
echo -e "${GREEN} ---> Copied apollo-api.service, apollo-ui-v2.service and ckpool.service to /etc/systemd/system${NC}"
|
||||||
|
|
||||||
|
# Reload systemd daemon to recognize the new service
|
||||||
|
systemctl daemon-reload
|
||||||
|
|
||||||
|
echo -e "${GREEN} ---> Reloaded systemd daemon${NC}"
|
||||||
|
|
||||||
|
# Enable and start the services
|
||||||
|
systemctl enable apollo-api.service
|
||||||
|
systemctl enable apollo-ui-v2.service
|
||||||
|
systemctl enable swap.service
|
||||||
|
systemctl enable rc-local.service
|
||||||
|
systemctl enable apollo-miner.service
|
||||||
|
systemctl enable node.service
|
||||||
|
systemctl enable ckpool.service
|
||||||
|
|
||||||
|
systemctl disable serial-getty@ttyS2.service
|
||||||
|
|
||||||
|
echo -e "${GREEN} ---> Enabled apollo services${NC}"
|
||||||
|
|
||||||
|
echo -e "${GREEN} ---> Installation complete${NC}"
|
@ -1,4 +1,15 @@
|
|||||||
#MCU Image rc.local
|
#!/bin/sh -e
|
||||||
|
#
|
||||||
|
# rc.local
|
||||||
|
#
|
||||||
|
# This script is executed at the end of each multiuser runlevel.
|
||||||
|
# Make sure that the script will "exit 0" on success or any other
|
||||||
|
# value on error.
|
||||||
|
#
|
||||||
|
# In order to enable or disable this script just change the execution
|
||||||
|
# bits.
|
||||||
|
#
|
||||||
|
# By default this script does nothing.
|
||||||
|
|
||||||
/opt/apolloapi/backend/firewall
|
/opt/apolloapi/backend/firewall
|
||||||
#configure gpios
|
#configure gpios
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
DEVICE=/dev/nvme0n1p1
|
DEVICE=/dev/nvme0n1p1
|
||||||
|
SWAPFILE=/media/nvme/swapfile
|
||||||
|
|
||||||
if [ -b "$DEVICE" ]; then
|
if [ -b "$DEVICE" ]; then
|
||||||
|
if [ ! -f "$SWAPFILE" ]; then
|
||||||
|
fallocate -l 3G $SWAPFILE
|
||||||
|
chmod 600 $SWAPFILE
|
||||||
|
mkswap $SWAPFILE
|
||||||
|
fi
|
||||||
swapon /media/nvme/swapfile
|
swapon /media/nvme/swapfile
|
||||||
else
|
else
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=swap
|
|
||||||
After=multi-user.target rc-local.service
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=simple
|
|
||||||
User=root
|
|
||||||
#Start:
|
|
||||||
ExecStart=/opt/apolloapi/backend/start_swap.sh
|
|
||||||
WorkingDirectory=/media/nvme
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
@ -2,6 +2,7 @@
|
|||||||
Description=Apollo App
|
Description=Apollo App
|
||||||
Documentation=https://nextjs.org/
|
Documentation=https://nextjs.org/
|
||||||
After=network.target
|
After=network.target
|
||||||
|
After=apollo-api.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Apollo API & UI app
|
|
||||||
After=network.target
|
|
||||||
After=rc-local.service
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Environment=NODE_ENV=production
|
|
||||||
Type=simple
|
|
||||||
User=futurebit
|
|
||||||
ExecStart=/usr/local/nvm/versions/node/v14.16.1/bin/node /opt/apolloapi/src/init.js
|
|
||||||
WorkingDirectory=/opt/apolloapi
|
|
||||||
Restart=on-failure
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
@ -1,6 +1,7 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=ckpool
|
Description=ckpool
|
||||||
After=multi-user.target
|
After=multi-user.target
|
||||||
|
After=node.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=forking
|
Type=forking
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=node
|
Description=node
|
||||||
After=multi-user.target
|
After=multi-user.target
|
||||||
After=apollo-ui.service
|
After=apollo-ui-v2.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=forking
|
Type=forking
|
||||||
|
14
backend/systemd/rc-local.service
Executable file
14
backend/systemd/rc-local.service
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=/etc/rc.local Compatibility
|
||||||
|
ConditionPathExists=/etc/rc.local
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=forking
|
||||||
|
ExecStart=/etc/rc.local start
|
||||||
|
TimeoutSec=0
|
||||||
|
StandardOutput=tty
|
||||||
|
RemainAfterExit=yes
|
||||||
|
SysVStartPriority=99
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
@ -1,14 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
DEVICE=/dev/nvme0n1p1
|
|
||||||
SWAPFILE=/media/nvme/swapfile
|
|
||||||
|
|
||||||
if [ -b "$DEVICE" ]; then
|
|
||||||
if [ ! -f "$SWAPFILE" ]; then
|
|
||||||
fallocate -l 2G $SWAPFILE
|
|
||||||
chmod 600 $SWAPFILE
|
|
||||||
mkswap $SWAPFILE
|
|
||||||
fi
|
|
||||||
swapon /media/nvme/swapfile
|
|
||||||
else
|
|
||||||
exit 0
|
|
||||||
fi
|
|
Loading…
Reference in New Issue
Block a user