Commit 48918bcb authored by Adam Lewenberg's avatar Adam Lewenberg
Browse files

add systemd service file when installing

parent b8d96a46
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
[Install]
WantedBy=multi-user.target

[Unit]
Description=run the GCP Cloud SQL Proxy service
Wants=network-online.target
After=network-online.target
Documentation=https://code.stanford.edu/debian-public/cloudsql-proxy

[Service]
Type=simple
ExecStart=/usr/bin/cloudsql-proxy.sh

# Restart on any failure after 5 seconds
Restart=on-failure
RestartSec=5s
+33 −0
Original line number Diff line number Diff line
#!/bin/bash

# A wrapper around /usr/bin/cloud_sql_proxy so we can pass options in a
# configuration file.

# Read the configuration file. This file should have the following
# format:
#
# dir=/run/cloudsql
# credential_file=/root/cloudsql.json
# instances=uit-acs-linux:us-west1:acs-linux-mysql-1=tcp:3306
#
# The "instances" option is MANDATORY. The others are OPTIONAL.
#
# These are passed as command line options to /usr/bin/cloud_sql_proxy

. /etc/cloudsql-proxy/options

if [[ -z "$dir" ]]; then
    dir="/run/cloudsql"
fi

if [[ -z "$credential_file" ]]; then
    echo "missing credentials file"
    exit 1
fi

if [[ -z "$instances" ]]; then
    echo "missing instances setting"
    exit 1
fi

/usr/bin/cloud_sql_proxy -dir=$dir -credential_file=$credential_file -instances=$instances
+7 −13
Original line number Diff line number Diff line
@@ -26,12 +26,6 @@ define gcp_cloudsql_proxy(
    }
  }

  # Make sure the cloudsql-proxy service is running.
  service { 'cloudsql-proxy':
    ensure  => running,
    require => Package['cloudsql-proxy'],
  }

  # Configure the options file. If the options file changes, restart the
  # service.
  file { '/etc/cloudsql-proxy/options':
+37 −6
Original line number Diff line number Diff line
class gcp_cloudsql_proxy::package {

  # Install the cloudsql-proxy package. This package contains the binary
  # cloud_sql_proxy packaged here at Stanford to make it more convenient
  # to install. It also contains a systemd service to manage the Cloud SQL
  # Proxy server. See also
  # https://code.stanford.edu/debian-public/cloudsql-proxy
  # Install the cloudsql-proxy package. This is now the "official"
  # Debian package. However, it does not contain the service component
  # (althought is _does_ contain examples of the service). So we also
  # install the service component.
  package { 'cloudsql-proxy':
    ensure => installed
    ensure  => installed,
    require => [
      File['/lib/systemd/system/cloudsql-proxy.service'],
      File['/usr/bin/cloudsql-proxy.sh'],
    ]
  }

  # The service file.
  file { '/lib/systemd/system/cloudsql-proxy.service':
    ensure => present,
    source => 'puppet:///modules/gcp_cloudsql_proxy/lib/systemd/system/cloudsql-proxy.service',
    notify => Exec['cloud-sql-proxy-systemctl-daemon-reload'],
  }

  exec { 'cloud-sql-proxy-systemctl-daemon-reload':
    command     => '/bin/systemctl daemon-reload',
    refreshonly => true,
    notify      => Service['cloudsql-proxy'],
  }

  # The shell script wrapper that the above service calls when starting.
  file { '/usr/bin/cloudsql-proxy.sh':
    ensure => present,
    source => 'puppet:///modules/gcp_cloudsql_proxy/usr/bin/cloudsql-proxy.sh',
    mode   => '0755',
  }

  # Make sure the cloudsql-proxy service is running.
  service { 'cloudsql-proxy':
    ensure    => running,
    require   => Package['cloudsql-proxy'],
    subscribe => File['/lib/systemd/system/cloudsql-proxy.service'],
  }


}