func shutdownInitCommands(initSystem, series string) ([]string, error) { shutdownCmd := "/sbin/shutdown -h now" name := "juju-template-restart" desc := "juju shutdown job" execStart := shutdownCmd conf := common.Conf{ Desc: desc, Transient: true, AfterStopped: "cloud-final", ExecStart: execStart, } // systemd uses targets for synchronization of services if initSystem == service.InitSystemSystemd { conf.AfterStopped = "cloud-config.target" } svc, err := service.NewService(name, conf, series) if err != nil { return nil, errors.Trace(err) } cmds, err := svc.InstallCommands() if err != nil { return nil, errors.Trace(err) } startCommands, err := svc.StartCommands() if err != nil { return nil, errors.Trace(err) } cmds = append(cmds, startCommands...) return cmds, nil }
func shutdownInitCommands(initSystem, series string) ([]string, error) { // These files are removed just before the template shuts down. cleanupOnShutdown := []string{ // We remove any dhclient lease files so there's no chance a // clone to reuse a lease from the template it was cloned // from. "/var/lib/dhcp/dhclient*", // Both of these sets of files below are recreated on boot and // if we leave them in the template's rootfs boot logs coming // from cloned containers will be appended. It's better to // keep clean logs for diagnosing issues / debugging. "/var/log/cloud-init*.log", } // Using EOC below as the template shutdown script is itself // passed through cat > ... < EOF. replaceNetConfCmd := fmt.Sprintf( "/bin/cat > /etc/network/interfaces << EOC%sEOC\n ", defaultEtcNetworkInterfaces, ) paths := strings.Join(cleanupOnShutdown, " ") removeCmd := fmt.Sprintf("/bin/rm -fr %s\n ", paths) shutdownCmd := "/sbin/shutdown -h now" name := "juju-template-restart" desc := "juju shutdown job" execStart := shutdownCmd if environs.AddressAllocationEnabled() { // Only do the cleanup and replacement of /e/n/i when address // allocation feature flag is enabled. execStart = replaceNetConfCmd + removeCmd + shutdownCmd } conf := common.Conf{ Desc: desc, Transient: true, AfterStopped: "cloud-final", ExecStart: execStart, } // systemd uses targets for synchronization of services if initSystem == service.InitSystemSystemd { conf.AfterStopped = "cloud-config.target" } svc, err := service.NewService(name, conf, series) if err != nil { return nil, errors.Trace(err) } cmds, err := svc.InstallCommands() if err != nil { return nil, errors.Trace(err) } startCommands, err := svc.StartCommands() if err != nil { return nil, errors.Trace(err) } cmds = append(cmds, startCommands...) return cmds, nil }