From 3f469bb92298fd8766ab993a6e3f38e9b91738bc Mon Sep 17 00:00:00 2001 From: RMcTn Date: Mon, 18 Sep 2023 11:21:36 +0100 Subject: [PATCH] Add new server setup to makefile --- Makefile | 48 ++++++++++++++++++++++++++++++++---- services/geckodriver.service | 10 ++++++++ services/whatbin.service | 11 +++++++++ 3 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 services/geckodriver.service create mode 100644 services/whatbin.service diff --git a/Makefile b/Makefile index f034791..ba6895f 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,52 @@ USER = root +APP_FOLDER = ~/what-bin-is-it + +# TODO: DB backup +# TODO: DB setup on fresh server build-for-server: cargo zigbuild --target x86_64-unknown-linux-gnu --release deploy-to-prod: + make upload-to-prod + ssh ${USER}@${WHAT_BIN_HOST} "systemctl restart whatbin" + +upload-to-prod: @if [ -z ${WHAT_BIN_HOST} ]; then\ echo "WHAT_BIN_HOST must be set" && exit 1;\ fi - ssh ${USER}@${WHAT_BIN_HOST} "mkdir -p /root/what-bin-is-it/archive" - scp -r ./target/x86_64-unknown-linux-gnu/release/server ${USER}@${WHAT_BIN_HOST}:/root/what-bin-is-it/server-new - ssh ${USER}@${WHAT_BIN_HOST} "mv /root/what-bin-is-it/server /root/what-bin-is-it/archive/server_$(date +"%Y%m%d%H%M%S")" - ssh ${USER}@${WHAT_BIN_HOST} "mv /root/what-bin-is-it/server-new /root/what-bin-is-it/server" - ssh ${USER}@${WHAT_BIN_HOST} "systemctl restart whatbin" + ssh ${USER}@${WHAT_BIN_HOST} "mkdir -p ${APP_FOLDER}/archive" + scp -r ./target/x86_64-unknown-linux-gnu/release/server ${USER}@${WHAT_BIN_HOST}:${APP_FOLDER}/server-new + ssh ${USER}@${WHAT_BIN_HOST} "if [ -f ${APP_FOLDER}/server ]; then mv ${APP_FOLDER}/server ${APP_FOLDER}/archive/server_$$(date +"%Y%m%d%H%M%S"); fi" + ssh ${USER}@${WHAT_BIN_HOST} "mv ${APP_FOLDER}/server-new ${APP_FOLDER}/server" + +setup-server: + @if [ -z ${WHAT_BIN_HOST} ]; then\ + echo "WHAT_BIN_HOST must be set" && exit 1;\ + fi + # APT STUFF + ssh ${USER}@${WHAT_BIN_HOST} "apt update" + ssh ${USER}@${WHAT_BIN_HOST} "apt -y install build-essential pkg-config libssl-dev" + ssh ${USER}@${WHAT_BIN_HOST} "apt -y install lnav" # For journalctl logs + # GECKODRIVER + ssh ${USER}@${WHAT_BIN_HOST} "wget https://github.com/mozilla/geckodriver/releases/download/v0.33.0/geckodriver-v0.33.0-linux64.tar.gz " + ssh ${USER}@${WHAT_BIN_HOST} "tar -xzvf geckodriver-v0.33.0-linux64.tar.gz" + ssh ${USER}@${WHAT_BIN_HOST} "mv geckodriver /bin" + # FIREFOX + ssh ${USER}@${WHAT_BIN_HOST} "wget 'https://download-installer.cdn.mozilla.net/pub/firefox/releases/115.0.3/linux-x86_64/en-GB/firefox-115.0.3.tar.bz2'" + ssh ${USER}@${WHAT_BIN_HOST} "tar -xjvf firefox-115.0.3.tar.bz2" + ssh ${USER}@${WHAT_BIN_HOST} "mv firefox /bin" + # UPLOAD + make upload-to-prod + # SYSTEMD + make services-setup + +BIN_SERVICE=whatbin.service +GECKODRIVER_SERVICE=geckodriver.service +services-setup: + scp -r ./services/${BIN_SERVICE} ${USER}@${WHAT_BIN_HOST}:/lib/systemd/system/${BIN_SERVICE} + scp -r ./services/${GECKODRIVER_SERVICE} ${USER}@${WHAT_BIN_HOST}:/lib/systemd/system/${GECKODRIVER_SERVICE} + ssh ${USER}@${WHAT_BIN_HOST} "systemctl daemon-reload" + ssh ${USER}@${WHAT_BIN_HOST} "systemctl enable ${GECKODRIVER_SERVICE}" + ssh ${USER}@${WHAT_BIN_HOST} "systemctl restart ${GECKODRIVER_SERVICE}" + ssh ${USER}@${WHAT_BIN_HOST} "systemctl enable ${BIN_SERVICE}" diff --git a/services/geckodriver.service b/services/geckodriver.service new file mode 100644 index 0000000..69e20e9 --- /dev/null +++ b/services/geckodriver.service @@ -0,0 +1,10 @@ +[Unit] +Description=Gecko driver +After=network.target + +[Service] +Type=simple +ExecStart=geckodriver --profile-root /root/geckodriver-profiles + +[Install] +WantedBy=multi-user.target diff --git a/services/whatbin.service b/services/whatbin.service new file mode 100644 index 0000000..c1c8f4d --- /dev/null +++ b/services/whatbin.service @@ -0,0 +1,11 @@ +[Unit] +Description=What bin is it server binary +After=network.target + +[Service] +Type=simple +EnvironmentFile=/root/what-bin-is-it/.env +ExecStart=/root/what-bin-is-it/server + +[Install] +WantedBy=multi-user.target