2024年8月8日木曜日

パラメータストア

# vi /etc/sysconfig/cxdnext/ssm-param-pre-exec.sh << __EOF__
#!/bin/bash
#----------------------------------------------
# パラメータストアからの環境取得
#----------------------------------------------
main(){
case "$1" in
"export" )
EVAL_COMMAND="echo export \${NAME##*/}=\$VALUE"
parameter_store
;;
*)
EVAL_COMMAND="systemctl set-environment \${NAME##*/}=\$VALUE"
parameter_store
;;
esac
}
parameter_store(){
# Load environmental variables
SSM_PARAMETER_STORE=$(aws ssm get-parameters-by-path --region ap-northeast-1 --path "/CXDNEXT/" --with-decryption)

echo ${SSM_PARAMETER_STORE} | jq -c '.Parameters[]' | while read i; do
NAME=$(echo $i | jq -r '.Name')
VALUE=$(echo $i | jq -r '.Value' | sed 's/\$/\\$/g')
eval $EVAL_COMMAND
done
}
main $@
__EOF__

※ 独自の環境変数を発生させる

#systemctl set-environment {NAME}={VALUE}
systemctl set-environment PARAMETER_STORE=ENABLE_DAYO

# cp -p /usr/lib/systemd/system/httpd.service  /etc/systemd/system/httpd.service

# vi /etc/systemd/system/httpd.service
ExecStartPre=/usr/bin/bash /etc/sysconfig/cxdnext/ssm-param-pre-exec.sh

systemctl stop httpd
systemctl disable httpd
systemctl enable httpd
systemctl start httpd

# systemctl status httpd
● httpd.service - The Apache HTTP Server
     Loaded: loaded (/etc/systemd/system/httpd.service; enabled; preset: disabled)


# vi /opt/tomcat/bin/setenv.sh  <<__EOF__
source <( sh /etc/sysconfig/cxdnext/ssm-param-pre-exec.sh export )
__EOF__













0 件のコメント:

コメントを投稿

zabbix7 amazon linux2023 インストール postgres15

【postgres】 dnf -y install postgresql15-server postgresql15-server-devel postgresql-setup initdb passwd postgres vi `find / -name pg_hba.con...