From e8e2481428ddbeb71147b165c1b86f6f4093a615 Mon Sep 17 00:00:00 2001 From: kompotkot Date: Wed, 9 Nov 2022 11:47:55 +0000 Subject: [PATCH] Migrated deployment to checkenv --- backend/deploy/deploy.bash | 23 ++++++------------- ...onstreamapi.service => moonstream.service} | 8 ++++--- crawlers/deploy/deploy.bash | 10 +------- 3 files changed, 13 insertions(+), 28 deletions(-) rename backend/deploy/{moonstreamapi.service => moonstream.service} (78%) diff --git a/backend/deploy/deploy.bash b/backend/deploy/deploy.bash index 817a3d75..444c87d3 100755 --- a/backend/deploy/deploy.bash +++ b/backend/deploy/deploy.bash @@ -23,11 +23,9 @@ PIP="${PYTHON_ENV_DIR}/bin/pip" SCRIPT_DIR="$(realpath $(dirname $0))" SECRETS_DIR="${SECRETS_DIR:-/home/ubuntu/moonstream-secrets}" PARAMETERS_ENV_PATH="${SECRETS_DIR}/app.env" -AWS_SSM_PARAMETER_PATH="${AWS_SSM_PARAMETER_PATH:-/moonstream/prod}" -PARAMETERS_SCRIPT="${SCRIPT_DIR}/parameters.py" # API server service file -SERVICE_FILE="${SCRIPT_DIR}/moonstreamapi.service" +MOONSTREAM_API_SERVICE_FILE="${SCRIPT_DIR}/moonstream.service" set -eu @@ -41,12 +39,6 @@ echo echo -e "${PREFIX_INFO} Installing Python dependencies" "${PIP}" install -e "${APP_BACKEND_DIR}/" -echo -echo -echo -e "${PREFIX_INFO} Retrieving deployment parameters" -mkdir -p "${SECRETS_DIR}" -AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" "${PYTHON}" "${PARAMETERS_SCRIPT}" "${AWS_SSM_PARAMETER_PATH}" -o "${PARAMETERS_ENV_PATH}" - echo echo echo -e "${PREFIX_INFO} Install checkenv" @@ -55,13 +47,12 @@ HOME=/root /usr/local/go/bin/go install github.com/bugout-dev/checkenv@latest echo echo echo -e "${PREFIX_INFO} Retrieving addition deployment parameters" -AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" /root/go/bin/checkenv show aws_ssm+Product:moonstream >> "${PARAMETERS_ENV_PATH}" +AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" /root/go/bin/checkenv show aws_ssm+moonstream:true > "${PARAMETERS_ENV_PATH}" echo echo -echo -e "${PREFIX_INFO} Replacing existing Moonstream API service definition with ${SERVICE_FILE}" -chmod 644 "${SERVICE_FILE}" -cp "${SERVICE_FILE}" /etc/systemd/system/moonstreamapi.service -systemctl daemon-reload -systemctl restart moonstreamapi.service -systemctl status moonstreamapi.service +echo -e "${PREFIX_INFO} Replacing existing Moonstream API service definition with ${MOONSTREAM_API_SERVICE_FILE}" +chmod 644 "${SCRIPT_DIR}/${MOONSTREAM_API_SERVICE_FILE}" +cp "${SCRIPT_DIR}/${MOONSTREAM_API_SERVICE_FILE}" "/home/ubuntu/.config/systemd/user/${MOONSTREAM_API_SERVICE_FILE}" +XDG_RUNTIME_DIR="/run/user/$UID" systemctl --user daemon-reload +XDG_RUNTIME_DIR="/run/user/$UID" systemctl --user restart "${MOONSTREAM_API_SERVICE_FILE}" diff --git a/backend/deploy/moonstreamapi.service b/backend/deploy/moonstream.service similarity index 78% rename from backend/deploy/moonstreamapi.service rename to backend/deploy/moonstream.service index f34ea241..eb0f515d 100644 --- a/backend/deploy/moonstreamapi.service +++ b/backend/deploy/moonstream.service @@ -1,14 +1,16 @@ [Unit] Description=moonstreamapi-service After=network.target +StartLimitIntervalSec=300 +StartLimitBurst=3 [Service] -User=ubuntu -Group=www-data WorkingDirectory=/home/ubuntu/moonstream/backend EnvironmentFile=/home/ubuntu/moonstream-secrets/app.env +Restart=on-failure +RestartSec=15s ExecStart=/home/ubuntu/moonstream-env/bin/uvicorn --proxy-headers --forwarded-allow-ips='127.0.0.1' --host 127.0.0.1 --port 7481 --workers 8 moonstreamapi.api:app -SyslogIdentifier=moonstreamapi +SyslogIdentifier=moonstream [Install] WantedBy=multi-user.target diff --git a/crawlers/deploy/deploy.bash b/crawlers/deploy/deploy.bash index 68fd93c4..d1e94205 100755 --- a/crawlers/deploy/deploy.bash +++ b/crawlers/deploy/deploy.bash @@ -22,9 +22,7 @@ PYTHON="${PYTHON_ENV_DIR}/bin/python" PIP="${PYTHON_ENV_DIR}/bin/pip" SECRETS_DIR="${SECRETS_DIR:-/home/ubuntu/moonstream-secrets}" PARAMETERS_ENV_PATH="${SECRETS_DIR}/app.env" -AWS_SSM_PARAMETER_PATH="${AWS_SSM_PARAMETER_PATH:-/moonstream/prod}" SCRIPT_DIR="$(realpath $(dirname $0))" -PARAMETERS_SCRIPT="${SCRIPT_DIR}/parameters.py" # Service files MOONCRAWL_SERVICE_FILE="mooncrawl.service" @@ -86,12 +84,6 @@ echo echo -e "${PREFIX_INFO} Installing Python dependencies" "${PIP}" install -e "${APP_CRAWLERS_DIR}/mooncrawl/" -echo -echo -echo -e "${PREFIX_INFO} Retrieving deployment parameters" -mkdir -p "${SECRETS_DIR}" -AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" "${PYTHON}" "${PARAMETERS_SCRIPT}" extract -p "${AWS_SSM_PARAMETER_PATH}" -o "${PARAMETERS_ENV_PATH}" - echo echo echo -e "${PREFIX_INFO} Install checkenv" @@ -100,7 +92,7 @@ HOME=/root /usr/local/go/bin/go install github.com/bugout-dev/checkenv@latest echo echo echo -e "${PREFIX_INFO} Retrieving addition deployment parameters" -AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" /root/go/bin/checkenv show aws_ssm+Product:moonstream >> "${PARAMETERS_ENV_PATH}" +AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" /root/go/bin/checkenv show aws_ssm+moonstream:true > "${PARAMETERS_ENV_PATH}" echo echo