From 848375b9a6507b1ab5278a86ff8bd4f441b3d67a Mon Sep 17 00:00:00 2001 From: Nolan Davidson Date: Tue, 13 Feb 2018 15:11:59 -0500 Subject: [PATCH] [provisioner-habitat] Allow custom service name (#17196) This change allows the Habitat supervisor service name to be configurable. Currently it is hard coded to `hab-supervisor`. Signed-off-by: Nolan Davidson --- .../provisioners/habitat/resource_provisioner.go | 15 +++++++++++---- website/docs/provisioners/habitat.html.markdown | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/builtin/provisioners/habitat/resource_provisioner.go b/builtin/provisioners/habitat/resource_provisioner.go index 2db068bf9..14a98db9f 100644 --- a/builtin/provisioners/habitat/resource_provisioner.go +++ b/builtin/provisioners/habitat/resource_provisioner.go @@ -54,6 +54,7 @@ type provisioner struct { SkipInstall bool UseSudo bool ServiceType string + ServiceName string URL string Channel string Events string @@ -79,6 +80,11 @@ func Provisioner() terraform.ResourceProvisioner { Optional: true, Default: "systemd", }, + "service_name": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Default: "hab-supervisor", + }, "use_sudo": &schema.Schema{ Type: schema.TypeBool, Optional: true, @@ -344,6 +350,7 @@ func decodeConfig(d *schema.ResourceData) (*provisioner, error) { Services: getServices(d.Get("service").(*schema.Set).List()), UseSudo: d.Get("use_sudo").(bool), ServiceType: d.Get("service_type").(string), + ServiceName: d.Get("service_name").(string), RingKey: d.Get("ring_key").(string), RingKeyContent: d.Get("ring_key_content").(string), PermanentPeer: d.Get("permanent_peer").(bool), @@ -569,9 +576,9 @@ func (p *provisioner) startHabSystemd(o terraform.UIOutput, comm communicator.Co var command string if p.UseSudo { - command = fmt.Sprintf("sudo echo '%s' | sudo tee /etc/systemd/system/hab-supervisor.service > /dev/null", &buf) + command = fmt.Sprintf("sudo echo '%s' | sudo tee /etc/systemd/system/%s.service > /dev/null", &buf, p.ServiceName) } else { - command = fmt.Sprintf("echo '%s' | tee /etc/systemd/system/hab-supervisor.service > /dev/null", &buf) + command = fmt.Sprintf("echo '%s' | tee /etc/systemd/system/%s.service > /dev/null", &buf, p.ServiceName) } if err := p.runCommand(o, comm, command); err != nil { @@ -579,9 +586,9 @@ func (p *provisioner) startHabSystemd(o terraform.UIOutput, comm communicator.Co } if p.UseSudo { - command = fmt.Sprintf("sudo systemctl start hab-supervisor") + command = fmt.Sprintf("sudo systemctl start %s", p.ServiceName) } else { - command = fmt.Sprintf("systemctl start hab-supervisor") + command = fmt.Sprintf("systemctl start %s", p.ServiceName) } return p.runCommand(o, comm, command) } diff --git a/website/docs/provisioners/habitat.html.markdown b/website/docs/provisioners/habitat.html.markdown index 23c084086..55ac2232b 100644 --- a/website/docs/provisioners/habitat.html.markdown +++ b/website/docs/provisioners/habitat.html.markdown @@ -49,6 +49,7 @@ There are 2 configuration levels, `supervisor` and `service`. Configuration pla * `version (string)` - (Optional) The Habitat version to install on the remote machine. If not specified, the latest available version is used. * `use_sudo (bool)` - (Optional) Use `sudo` when executing remote commands. Required when the user specified in the `connection` block is not `root`. (Defaults to `true`) * `service_type (string)` - (Optional) Method used to run the Habitat supervisor. Valid options are `unmanaged` and `systemd`. (Defaults to `systemd`) +* `service_name (string)` - (Optional) The name of the Habitat supervisor service, if using an init system such as `systemd`. (Defaults to `hab-supervisor`) * `peer (string)` - (Optional) IP or FQDN of a supervisor instance to peer with. (Defaults to none) * `permanent_peer (bool)` - (Optional) Marks this supervisor as a permanent peer. (Defaults to false) * `listen_gossip (string)` - (Optional) The listen address for the gossip system (Defaults to 0.0.0.0:9638)