[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 <ndavidson@chef.io>
This commit is contained in:
Nolan Davidson 2018-02-13 15:11:59 -05:00 committed by Clint
parent 52f6abf47b
commit 848375b9a6
2 changed files with 12 additions and 4 deletions

View File

@ -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)
}

View File

@ -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)