diff --git a/cmd/mosctl/boot.go b/cmd/mosctl/boot.go new file mode 100644 index 0000000..0190dfd --- /dev/null +++ b/cmd/mosctl/boot.go @@ -0,0 +1,28 @@ +package main + +import ( + "github.com/pkg/errors" + "github.com/project-machine/mos/pkg/mosconfig" + "github.com/urfave/cli" +) + +var bootCmd = cli.Command{ + Name: "boot", + Usage: "start all services listed in mos manifest", + Action: doBootCmd, +} + +func doBootCmd(ctx *cli.Context) error { + opts := mosconfig.DefaultMosOptions() + mos, err := mosconfig.OpenMos(opts) + if err != nil { + return errors.Wrapf(err, "Failed opening mos") + } + + err = mos.Boot() + if err != nil { + return errors.Wrapf(err, "Failed to boot") + } + + return nil +} diff --git a/cmd/mosctl/main.go b/cmd/mosctl/main.go index 206abb0..7bf157f 100644 --- a/cmd/mosctl/main.go +++ b/cmd/mosctl/main.go @@ -17,6 +17,7 @@ func main() { app.Commands = []cli.Command{ createBootFsCmd, activateCmd, + bootCmd, installCmd, mountCmd, updateCmd, diff --git a/layers/install/mos-boot-setup.service b/layers/install/mos-boot-setup.service new file mode 100644 index 0000000..b04da00 --- /dev/null +++ b/layers/install/mos-boot-setup.service @@ -0,0 +1,18 @@ +[Unit] +Description=mos-boot-setup +After=local-fs.target +After=systemd-journal-flush.service logs.mount +Requires=local-fs.target +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/bin/mosctl boot +StandardOutput=journal+console +StandardError=journal+console + +# Journal namespaces implementation also affects the mount namespaces. +# Assigning a separate journal namespace to Atomix process hides mount points +# like /config and /tmp from the "main" user namespace. +# LogNamespace=atomix +[Install] +WantedBy=multi-user.target diff --git a/layers/install/stacker.yaml b/layers/install/stacker.yaml index 84e1b68..ec9e533 100644 --- a/layers/install/stacker.yaml +++ b/layers/install/stacker.yaml @@ -62,6 +62,7 @@ demo-target-rootfs: - ../provision/console-helper - load-mos-modules - mos-modules.service + - mos-boot-setup.service run: | #!/bin/sh -ex writefile() { @@ -95,6 +96,8 @@ demo-target-rootfs: chmod 755 /usr/bin/load-mos-modules cp /stacker/imports/mos-modules.service /etc/systemd/system/ systemctl enable mos-modules.service + cp /stacker/imports/mos-boot-setup.service /etc/systemd/system + systemctl enable mos-boot-setup.service echo root:passw0rd | chpasswd systemctl enable serial-getty@ttyS0 diff --git a/pkg/mosconfig/mos.go b/pkg/mosconfig/mos.go index 5ee63de..5222f93 100644 --- a/pkg/mosconfig/mos.go +++ b/pkg/mosconfig/mos.go @@ -169,6 +169,27 @@ func (mos *Mos) Current(name string) (*Target, error) { return nil, errors.Errorf("Target %s not found", name) } +// We'll probably want to do a lot more setup here, but for now just +// activate services +func (mos *Mos) Boot() error { + return mos.ActivateAll() +} + +// Activate all services +func (mos *Mos) ActivateAll() error { + m, err := mos.CurrentManifest() + if err != nil { + return errors.Wrapf(err, "Failed opening manifest") + } + for _, t := range m.SysTargets { + if err := mos.Activate(t.Name); err != nil { + return errors.Wrapf(err, "Failed starting %s", t.Name) + } + } + + return nil +} + // Activate a target (service): // If it is not yet running then start it. // If it is already running, but is not at the newest version (i.e. after an