Hi, after some fiddling into how to do this properly on Ubuntu 15.10 images I was able to pull this solution. It could be easier but it's good enough for me and needs no startup scripts.
@israelfaria You don't need the daemon package at all. Systemd already provides the same functionality. Here is my unit file:
[Install]
WantedBy=multi-user.target
[Unit]
Description=Google Cloud Compute Engine SQL Proxy
Requires=networking.service
After=networking.service
[Service]
Type=simple
WorkingDirectory=/run/cloudsql
ExecStart=/usr/local/bin/cloud_sql_proxy -dir=/run/cloudsql -instances=...
Restart=always
StandardOutput=journal
User=root
@emilv I had to change the WorkingDirectory to /usr/local/bin/ to make it work
Hi all,
Here is my working systemd service tested in Centos 7 :
/usr/lib/systemd/system/cloud_sql_proxy.service
[Unit]
Description=GCP CloudSQL Proxy
After=network.target
[Service]
User=root
Group=root
WorkingDirectory=/usr/bin
Type=forking
RemainAfterExit=yes
ExecStart=/bin/sh -c '/usr/bin/nohup /usr/local/cloud_sql_proxy -instances=${INSTANCE_CONNECTION_NAME} -credential_file=${CREDENTIAL_FILE} &'
StandardOutput=journal
KillMode=process
[Install]
WantedBy=multi-user.target
/usr/lib/systemd/system/cloud_sql_proxy.service.d/settings.conf
[Service]
Environment=INSTANCE_CONNECTION_NAME=[YOUR CONNECTION NAME]
Environment=CREDENTIAL_FILE=[PATH TO YOUR CREDENTIAL FILE]
BR
/Ouss
This is what works for me on CentOS 8:
[Unit]
Description=Cloud SQL Proxy service
Wants=network-online.target
After=network-online.target
[Service]
WorkingDirectory=/usr/bin
ExecStart=/usr/bin/cloud_sql_proxy -instances=...=tcp:3306
Restart=always
Type=simple
StandardError=syslog
StandardOutput=journal
KillMode=process
[Install]
WantedBy=multi-user.target
It would be good if a service unit is provided upstream, but apparently this has not happened in the past almost 5 years.
I recently had to fall back to using the root user instead of a system user and I cannot figure out why. Proxy was reporting:
2021/03/05 19:31:43 GcloudConfig: error reading config: exit status 1; stderr was:
WARNING: Could not setup log file in /bin/.config/gcloud/logs, (Error: Could not create directory [/bin/.config/gcloud/logs/2021.03.05]: Permission denied.
Please verify that you have permissions to write to the parent directory.)
ERROR: (gcloud.config.config-helper) Failed to create the default configuration. Ensure your have the correct permissions on: [/bin/.config/gcloud/configurations].
Could not create directory [/bin/.config/gcloud/configurations]: Permission denied.
Please verify that you have permissions to write to the parent directory.
2021/03/05 19:31:44 GcloudConfig: error reading config: exit status 1; stderr was:
WARNING: Could not setup log file in /bin/.config/gcloud/logs, (Error: Could not create directory [/bin/.config/gcloud/logs/2021.03.05]: Permission denied.
Please verify that you have permissions to write to the parent directory.)
ERROR: (gcloud.config.config-helper) Failed to create the default configuration. Ensure your have the correct permissions on: [/bin/.config/gcloud/configurations].
Could not create directory [/bin/.config/gcloud/configurations]: Permission denied.
My systemd script is very similar to everyone else's with the exception of a non-root system user I was using. Everything was working fine for years.
Most helpful comment
Hi all,
Here is my working systemd service tested in
Centos 7:/usr/lib/systemd/system/cloud_sql_proxy.service/
usr/lib/systemd/system/cloud_sql_proxy.service.d/settings.confBR
/Ouss