func (s *discoverySuite) TestVersionInitSystem(c *gc.C) { for _, test := range discoveryTests { test.log(c) initSystem, err := service.VersionInitSystem(test.series) test.checkInitSystem(c, initSystem, err) } }
// TemplateUserData returns a minimal user data necessary for the template. // This should have the authorized keys, base packages, the cloud archive if // necessary, initial apt proxy config, and it should do the apt-get // update/upgrade initially. func TemplateUserData( series string, authorizedKeys string, aptProxy proxy.Settings, aptMirror string, enablePackageUpdates bool, enableOSUpgrades bool, networkConfig *container.NetworkConfig, ) ([]byte, error) { var config cloudinit.CloudConfig var err error if networkConfig != nil { config, err = newCloudInitConfigWithNetworks(series, networkConfig) if err != nil { return nil, errors.Trace(err) } } else { config, err = cloudinit.New(series) if err != nil { return nil, errors.Trace(err) } } cloudconfig.SetUbuntuUser(config, authorizedKeys) config.AddScripts( "set -xe", // ensure we run all the scripts or abort. ) // For LTS series which need support for the cloud-tools archive, // we need to enable apt-get update regardless of the environ // setting, otherwise provisioning will fail. if series == "precise" && !enablePackageUpdates { logger.Warningf("series %q requires cloud-tools archive: enabling updates", series) enablePackageUpdates = true } if enablePackageUpdates && config.RequiresCloudArchiveCloudTools() { config.AddCloudArchiveCloudTools() } config.AddPackageCommands(aptProxy, aptMirror, enablePackageUpdates, enableOSUpgrades) initSystem, err := service.VersionInitSystem(series) if err != nil { return nil, errors.Trace(err) } cmds, err := shutdownInitCommands(initSystem, series) if err != nil { return nil, errors.Trace(err) } config.AddScripts(strings.Join(cmds, "\n")) data, err := config.RenderYAML() if err != nil { return nil, err } return data, nil }
func (s *discoverySuite) TestVersionInitSystemNoLegacyUpstart(c *gc.C) { s.unsetLegacyUpstart(c) test := discoveryTest{ os: jujuos.Ubuntu, series: "vivid", expected: service.InitSystemSystemd, } vers := test.setVersion(s) initSystem, err := service.VersionInitSystem(vers.Series) test.checkInitSystem(c, initSystem, err) }
// ConfigureBasic updates the provided cloudinit.Config with // basic configuration to initialise an OS image, such that it can // be connected to via SSH, and log to a standard location. // // Any potentially failing operation should not be added to the // configuration, but should instead be done in ConfigureJuju. // // Note: we don't do apt update/upgrade here so as not to have to wait on // apt to finish when performing the second half of image initialisation. // Doing it later brings the benefit of feedback in the face of errors, // but adds to the running time of initialisation due to lack of activity // between image bringup and start of agent installation. func (w *unixConfigure) ConfigureBasic() error { w.conf.AddScripts( "set -xe", // ensure we run all the scripts or abort. ) switch w.os { case os.Ubuntu: w.conf.AddSSHAuthorizedKeys(w.icfg.AuthorizedKeys) if w.icfg.Tools != nil { initSystem, err := service.VersionInitSystem(w.icfg.Series) if err != nil { return errors.Trace(err) } w.addCleanShutdownJob(initSystem) } // On unix systems that are not ubuntu we create an ubuntu user so that we // are able to ssh in the machine and have all the functionality dependant // on having an ubuntu user there. // Hopefully in the future we are going to move all the distirbutions to // having a "juju" user case os.CentOS: w.conf.AddScripts( fmt.Sprintf(initUbuntuScript, utils.ShQuote(w.icfg.AuthorizedKeys)), // Mask and stop firewalld, if enabled, so it cannot start. See // http://pad.lv/1492066. firewalld might be missing, in which case // is-enabled and is-active prints an error, which is why the output // is surpressed. "systemctl is-enabled firewalld &> /dev/null && systemctl mask firewalld || true", "systemctl is-active firewalld &> /dev/null && systemctl stop firewalld || true", `sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers`, ) w.addCleanShutdownJob(service.InitSystemSystemd) } w.conf.SetOutput(cloudinit.OutAll, "| tee -a "+w.icfg.CloudInitOutputLog, "") // Create a file in a well-defined location containing the machine's // nonce. The presence and contents of this file will be verified // during bootstrap. // // Note: this must be the last runcmd we do in ConfigureBasic, as // the presence of the nonce file is used to gate the remainder // of synchronous bootstrap. noncefile := path.Join(w.icfg.DataDir, NonceFile) w.conf.AddRunTextFile(noncefile, w.icfg.MachineNonce, 0644) return nil }
// ConfigureBasic updates the provided cloudinit.Config with // basic configuration to initialise an OS image, such that it can // be connected to via SSH, and log to a standard location. // // Any potentially failing operation should not be added to the // configuration, but should instead be done in ConfigureJuju. // // Note: we don't do apt update/upgrade here so as not to have to wait on // apt to finish when performing the second half of image initialisation. // Doing it later brings the benefit of feedback in the face of errors, // but adds to the running time of initialisation due to lack of activity // between image bringup and start of agent installation. func (w *unixConfigure) ConfigureBasic() error { w.conf.AddScripts( "set -xe", // ensure we run all the scripts or abort. ) switch w.os { case os.Ubuntu: if (w.icfg.AgentVersion() != version.Binary{}) { initSystem, err := service.VersionInitSystem(w.icfg.Series) if err != nil { return errors.Trace(err) } w.addCleanShutdownJob(initSystem) } case os.CentOS: w.conf.AddScripts( // Mask and stop firewalld, if enabled, so it cannot start. See // http://pad.lv/1492066. firewalld might be missing, in which case // is-enabled and is-active prints an error, which is why the output // is surpressed. "systemctl is-enabled firewalld &> /dev/null && systemctl mask firewalld || true", "systemctl is-active firewalld &> /dev/null && systemctl stop firewalld || true", `sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers`, ) w.addCleanShutdownJob(service.InitSystemSystemd) } SetUbuntuUser(w.conf, w.icfg.AuthorizedKeys) w.conf.SetOutput(cloudinit.OutAll, "| tee -a "+w.icfg.CloudInitOutputLog, "") // Create a file in a well-defined location containing the machine's // nonce. The presence and contents of this file will be verified // during bootstrap. // // Note: this must be the last runcmd we do in ConfigureBasic, as // the presence of the nonce file is used to gate the remainder // of synchronous bootstrap. noncefile := path.Join(w.icfg.DataDir, NonceFile) w.conf.AddRunTextFile(noncefile, w.icfg.MachineNonce, 0644) return nil }
func (s *discoverySuite) TestDiscoverServiceLocalHost(c *gc.C) { var localInitSystem string var err error switch runtime.GOOS { case "windows": localInitSystem = service.InitSystemWindows case "linux": localInitSystem, err = service.VersionInitSystem(series.HostSeries()) } c.Assert(err, gc.IsNil) test := discoveryTest{ os: jujuos.HostOS(), series: series.HostSeries(), expected: localInitSystem, } test.disableVersionDiscovery(s) svc, err := service.DiscoverService(s.name, s.conf) c.Assert(err, jc.ErrorIsNil) test.checkService(c, svc, err, s.name, s.conf) }