Created
September 29, 2022 19:05
-
-
Save mscribellito/319d8679a6d9e6cbf5e83f6d5953d1e5 to your computer and use it in GitHub Desktop.
cloud sql
This file contains hidden or 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 | |
# update package list and install PostgreSQL client | |
apt-get update -y | |
apt-get install postgresql-client -y | |
# download Cloud SQL Auth proxy | |
proxyPath=/usr/local/bin/cloud_sql_proxy | |
wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O $proxyPath | |
chmod +x $proxyPath | |
# configure service to persist proxy | |
echo " | |
[Unit] | |
Description=GCP Cloud SQL Auth proxy | |
Requires=network.target | |
[Service] | |
User=root | |
WorkingDirectory=/usr/local/bin | |
Type=simple | |
ExecStartPre=/bin/sleep 60 | |
ExecStart=/usr/bin/nohup $proxyPath -dir=/var/run/cloud-sql-proxy -instances=${INSTANCE_CONNECTION_NAME}=tcp:5432 & | |
Restart=always | |
StandardOutput=journal | |
[Install] | |
WantedBy=multi-user.target | |
" > /etc/systemd/system/cloud-sql-proxy.service | |
systemctl daemon-reload | |
systemctl enable cloud-sql-proxy | |
systemctl start cloud-sql-proxy.service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment