[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 SkipInstall bool
UseSudo bool UseSudo bool
ServiceType string ServiceType string
ServiceName string
URL string URL string
Channel string Channel string
Events string Events string
@ -79,6 +80,11 @@ func Provisioner() terraform.ResourceProvisioner {
Optional: true, Optional: true,
Default: "systemd", Default: "systemd",
}, },
"service_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "hab-supervisor",
},
"use_sudo": &schema.Schema{ "use_sudo": &schema.Schema{
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
@ -344,6 +350,7 @@ func decodeConfig(d *schema.ResourceData) (*provisioner, error) {
Services: getServices(d.Get("service").(*schema.Set).List()), Services: getServices(d.Get("service").(*schema.Set).List()),
UseSudo: d.Get("use_sudo").(bool), UseSudo: d.Get("use_sudo").(bool),
ServiceType: d.Get("service_type").(string), ServiceType: d.Get("service_type").(string),
ServiceName: d.Get("service_name").(string),
RingKey: d.Get("ring_key").(string), RingKey: d.Get("ring_key").(string),
RingKeyContent: d.Get("ring_key_content").(string), RingKeyContent: d.Get("ring_key_content").(string),
PermanentPeer: d.Get("permanent_peer").(bool), PermanentPeer: d.Get("permanent_peer").(bool),
@ -569,9 +576,9 @@ func (p *provisioner) startHabSystemd(o terraform.UIOutput, comm communicator.Co
var command string var command string
if p.UseSudo { 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 { } 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 { 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 { if p.UseSudo {
command = fmt.Sprintf("sudo systemctl start hab-supervisor") command = fmt.Sprintf("sudo systemctl start %s", p.ServiceName)
} else { } else {
command = fmt.Sprintf("systemctl start hab-supervisor") command = fmt.Sprintf("systemctl start %s", p.ServiceName)
} }
return p.runCommand(o, comm, command) 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. * `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`) * `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_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) * `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) * `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) * `listen_gossip (string)` - (Optional) The listen address for the gossip system (Defaults to 0.0.0.0:9638)