From 5981e12ac07648014bd12e1b5cff6a3665f4144d Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Mon, 14 Apr 2014 10:02:18 -0700 Subject: [PATCH] feat(unit): Allow user to control enabling units Fix #69 - A user may provide an `enable` attribute of a unit in their cloud config document. If true, coreos-cloudinit will instruct systemd to enable the associated unit. If false, the unit will not be enabled. Fix #71 - The default enable behavior has been changed from on to off. --- Documentation/cloud-config.md | 1 + initialize/config.go | 16 +++++++++------- system/systemd.go | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Documentation/cloud-config.md b/Documentation/cloud-config.md index 6c4b516..a9aaf4f 100644 --- a/Documentation/cloud-config.md +++ b/Documentation/cloud-config.md @@ -87,6 +87,7 @@ Arbitrary systemd units may be provided in the `coreos.units` attribute. - **name**: String representing unit's name. Required. - **runtime**: Boolean indicating whether or not to persist the unit across reboots. This is analagous to the `--runtime` argument to `systemd enable`. Default value is false. +- **enable**: Boolean indicating whether or not to handle the [Install] section of the unit file. This is similar to running `systemctl enable `. Default value is false. - **content**: Plaintext string representing entire unit file. If no value is provided, the unit is assumed to exist already. - **command**: Command to execute on unit: start, stop, reload, restart, try-restart, reload-or-restart, reload-or-try-restart. Default value is restart. diff --git a/initialize/config.go b/initialize/config.go index 6213207..a861cea 100644 --- a/initialize/config.go +++ b/initialize/config.go @@ -140,14 +140,16 @@ func Apply(cfg CloudConfig, env *Environment) error { } log.Printf("Placed unit %s at %s", unit.Name, dst) - if unit.Group() != "network" { - log.Printf("Enabling unit file %s", dst) - if err := system.EnableUnitFile(dst, unit.Runtime); err != nil { - return err + if unit.Enable { + if unit.Group() != "network" { + log.Printf("Enabling unit file %s", dst) + if err := system.EnableUnitFile(dst, unit.Runtime); err != nil { + return err + } + log.Printf("Enabled unit %s", unit.Name) + } else { + log.Printf("Skipping enable for network-like unit %s", unit.Name) } - log.Printf("Enabled unit %s", unit.Name) - } else { - log.Printf("Skipping enable for network-like unit %s", unit.Name) } } diff --git a/system/systemd.go b/system/systemd.go index dda28b2..8f4d99b 100644 --- a/system/systemd.go +++ b/system/systemd.go @@ -19,6 +19,7 @@ const fakeMachineID = "42000000000000000000000000000042" type Unit struct { Name string + Enable bool Runtime bool Content string Command string