Skip to content

Commit

Permalink
Implement 'mos boot'
Browse files Browse the repository at this point in the history
This starts all services.

Closes #7

Signed-off-by: Serge Hallyn <[email protected]>
  • Loading branch information
hallyn committed Oct 25, 2023
1 parent 5feaad5 commit 65a808d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cmd/mosctl/boot.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions cmd/mosctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func main() {
app.Commands = []cli.Command{
createBootFsCmd,
activateCmd,
bootCmd,
installCmd,
mountCmd,
updateCmd,
Expand Down
18 changes: 18 additions & 0 deletions layers/install/mos-boot-setup.service
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions layers/install/stacker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions pkg/mosconfig/mos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 65a808d

Please sign in to comment.