Last active
August 30, 2022 04:48
-
-
Save 1206yaya/bd81f26b5cb96f5d324661a91aaf426c to your computer and use it in GitHub Desktop.
Osho Production Web
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# File Location /www/api/exec.sh | |
# exec.sh [japan | outside] に変更することでRDS環境を指定する | |
# SpringbootServiceがFailedになるときは手動でこのファイルを実行し、ログを確認する。serviceファイルはログに書き込むことができない。 | |
# 行頭のbashに -ex をつけて次を実行しデバッグ | |
# ./exec.sh outside >> /www/api/log.log 2>&1 | |
LOCATION=$1 | |
echo "引数に指定された値\"$LOCATION\"がLOCATIONに設定されました" | |
INSTANCE_ID=$(curl 169.254.169.254/latest/meta-data/instance-id) | |
ZONE=$(curl 169.254.169.254/latest/meta-data/placement/availability-zone) | |
REGION=$(echo ${ZONE/%?/}) | |
SSM_PARAMETER_STORE=$(aws ssm get-parameters-by-path --region $REGION --path /osho --with-decryption) | |
for PARAMS in $(echo ${SSM_PARAMETER_STORE} | /usr/local/bin/jq -r '.Parameters[] | .Name + "=" + .Value'); do | |
export ${PARAMS##*/} | |
done; | |
SSM_PARAMETER_STORE=$(aws ssm get-parameters-by-path --region $REGION --path /osho/production/$LOCATION --with-decryption) | |
for PARAMS in $(echo ${SSM_PARAMETER_STORE} | /usr/local/bin/jq -r '.Parameters[] | .Name + "=" + .Value'); do | |
export ${PARAMS##*/} | |
done; | |
JAR_PATH=/www/api/restapi.jar | |
sudo chmod +x ${JAR_PATH} | |
/bin/java -jar \ | |
-Dspring.profiles.active=production \ | |
-Dspring.datasource.username=postgres \ | |
-Dspring.datasource.password=${RDS_PW} \ | |
-Dspring.datasource.url=jdbc:postgresql://${RDS_URL}:5432/osho?reWriteBatchedInserts=true \ | |
${JAR_PATH} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# FilePath: /etc/nginx/conf.d/nginx.conf | |
# For more information on configuration, see: | |
# * Official English Documentation: http://nginx.org/en/docs/ | |
# * Official Russian Documentation: http://nginx.org/ru/docs/ | |
user nginx; | |
worker_processes auto; | |
error_log /var/log/nginx/error.log; | |
pid /run/nginx.pid; | |
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. | |
include /usr/share/nginx/modules/*.conf; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
access_log /var/log/nginx/access.log main; | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
keepalive_timeout 65; | |
types_hash_max_size 4096; | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
# Load modular configuration files from the /etc/nginx/conf.d directory. | |
# See http://nginx.org/en/docs/ngx_core_module.html#include | |
# for more information. | |
include /etc/nginx/conf.d/*.conf; | |
upstream springboot { | |
server localhost:8080; | |
} | |
server { | |
listen 3123; | |
server_name _; | |
location / { | |
root /www/html; | |
index index.html index.htm; | |
try_files $uri.html $uri $uri/ /index.html; | |
} | |
location /api { | |
# include uwsgi_params; | |
# uwsgi_pass api; | |
proxy_pass http://springboot; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Host $host; | |
proxy_set_header X-Forwarded-Server $host; | |
proxy_set_header X-Forwarded-Port $server_port; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File Location /etc/systemd/system/SpringbootService.service | |
[Unit] | |
Description=SpringbootService | |
[Service] | |
Type=simple | |
WorkingDirectory=/www/api | |
ExecStart=/www/api/exec.sh outside | |
ExecStop=/bin/kill -s QUIT $MAINPID | |
Restart=on-failure | |
User=root | |
Group=root | |
[Install] | |
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File Location /etc/systemd/system/SpringbootService.service | |
[Unit] | |
Description=SpringbootService | |
[Service] | |
Type=simple | |
WorkingDirectory=/www/api | |
ExecStart=/www/api/exec.sh inside | |
ExecStop=/bin/kill -s QUIT $MAINPID | |
Restart=on-failure | |
User=root | |
Group=root | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment