Skip to content

Commit

Permalink
Removes the creation of the juju-clean-shutdown service on machines
Browse files Browse the repository at this point in the history
using systemd as the init system.

This does not work on systems with netplan and is not necessary for
ensuring that DHCP leases are relinquished.
  • Loading branch information
manadart committed Jun 16, 2020
1 parent 4da958b commit 067b21a
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 37 deletions.
3 changes: 0 additions & 3 deletions cloudconfig/userdatacfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,6 @@ rm \$bin/tools\.tar\.gz && rm \$bin/juju1\.2\.3-quantal-amd64\.sha256
upgradedToVersion: "1.2.3",
expectScripts: `
set -xe
install -D -m 644 /dev/null '/etc/systemd/system/juju-clean-shutdown\.service'
printf '%s\\n' '\\n\[Unit\]\\n.*Stop all network interfaces.*WantedBy=final\.target\\n' > '/etc/systemd.*'
/bin/systemctl enable '/etc/systemd/system/juju-clean-shutdown\.service'
install -D -m 644 /dev/null '/var/lib/juju/nonce.txt'
printf '%s\\n' 'FAKE_NONCE' > '/var/lib/juju/nonce.txt'
.*
Expand Down
9 changes: 2 additions & 7 deletions cloudconfig/userdatacfg_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/juju/juju/environs/simplestreams"
"github.com/juju/juju/juju/osenv"
"github.com/juju/juju/service"
"github.com/juju/juju/service/systemd"
"github.com/juju/juju/service/upstart"
)

Expand Down Expand Up @@ -221,12 +220,8 @@ func (w *unixConfigure) ConfigureBasic() error {
func (w *unixConfigure) addCleanShutdownJob(initSystem string) {
switch initSystem {
case service.InitSystemUpstart:
path, contents := upstart.CleanShutdownJobPath, upstart.CleanShutdownJob
w.conf.AddRunTextFile(path, contents, 0644)
case service.InitSystemSystemd:
path, contents := systemd.CleanShutdownServicePath, systemd.CleanShutdownService
w.conf.AddRunTextFile(path, contents, 0644)
w.conf.AddScripts(fmt.Sprintf("/bin/systemctl enable '%s'", path))
p, contents := upstart.CleanShutdownJobPath, upstart.CleanShutdownJob
w.conf.AddRunTextFile(p, contents, 0644)
}
}

Expand Down
2 changes: 0 additions & 2 deletions provider/ec2/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,6 @@ func (t *localServerSuite) TestSystemdBootstrapInstanceUserDataAndState(c *gc.C)
c.Assert(keys, jc.SameContents, []string{"output", "users", "runcmd", "ssh_keys"})
c.Assert(userDataMap["runcmd"], jc.DeepEquals, []interface{}{
"set -xe",
"install -D -m 644 /dev/null '/etc/systemd/system/juju-clean-shutdown.service'",
"printf '%s\\n' '\n[Unit]\nDescription=Stop all network interfaces on shutdown\nDefaultDependencies=false\nAfter=final.target\n\n[Service]\nType=oneshot\nExecStart=/sbin/ifdown -a -v --force\nStandardOutput=tty\nStandardError=tty\n\n[Install]\nWantedBy=final.target\n' > '/etc/systemd/system/juju-clean-shutdown.service'", "/bin/systemctl enable '/etc/systemd/system/juju-clean-shutdown.service'",
"install -D -m 644 /dev/null '/var/lib/juju/nonce.txt'",
"printf '%s\\n' 'user-admin:bootstrap' > '/var/lib/juju/nonce.txt'",
})
Expand Down
26 changes: 1 addition & 25 deletions service/systemd/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import (
"strconv"
"strings"

"github.com/juju/juju/core/paths"

"github.com/coreos/go-systemd/v22/unit"
"github.com/juju/errors"
"github.com/juju/utils/shell"

"github.com/juju/juju/core/paths"
"github.com/juju/juju/service/common"
)

Expand Down Expand Up @@ -344,26 +343,3 @@ func deserializeOptions(opts []*unit.UnitOption, renderer shell.Renderer) (commo
err := validate("<>", conf, renderer)
return conf, errors.Trace(err)
}

// CleanShutdownService is added to machines to ensure DHCP-assigned
// IP addresses are released on shutdown, reboot, or halt. See bug
// http://pad.lv/1348663 for more info.
const CleanShutdownService = `
[Unit]
Description=Stop all network interfaces on shutdown
DefaultDependencies=false
After=final.target
[Service]
Type=oneshot
ExecStart=/sbin/ifdown -a -v --force
StandardOutput=tty
StandardError=tty
[Install]
WantedBy=final.target
`

// CleanShutdownServicePath is the full file path where
// CleanShutdownService is created.
const CleanShutdownServicePath = "/etc/systemd/system/juju-clean-shutdown.service"

0 comments on commit 067b21a

Please sign in to comment.