blob: 77e9156b36987d6c175bf35cf57a92b01e9580fa [file] [log] [blame]
Lorenz Brunc88c82d2020-05-08 14:35:04 +02001// Copyright 2020 The Monogon Project Authors.
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17package containerd
18
19import (
20 "context"
Lorenz Brun878f5f92020-05-12 16:15:39 +020021 "fmt"
22 "git.monogon.dev/source/nexantic.git/core/internal/common/supervisor"
Lorenz Brunc88c82d2020-05-08 14:35:04 +020023 "os"
24 "os/exec"
25
26 "git.monogon.dev/source/nexantic.git/core/pkg/logbuffer"
27
28 "golang.org/x/sys/unix"
29)
30
Lorenz Brun878f5f92020-05-12 16:15:39 +020031type Service struct {
32 Log *logbuffer.LogBuffer
33}
Lorenz Brunc88c82d2020-05-08 14:35:04 +020034
Lorenz Brun878f5f92020-05-12 16:15:39 +020035func New() (*Service, error) {
36 return &Service{Log: logbuffer.New(5000, 16384)}, nil
37}
Lorenz Brunc88c82d2020-05-08 14:35:04 +020038
Lorenz Brun878f5f92020-05-12 16:15:39 +020039func (s *Service) Run() supervisor.Runnable {
40 return func(ctx context.Context) error {
41 cmd := exec.CommandContext(ctx, "/containerd/bin/containerd", "--config", "/containerd/conf/config.toml")
42 cmd.Stdout = s.Log
43 cmd.Stderr = s.Log
44 cmd.Env = []string{"PATH=/containerd/bin", "TMPDIR=/containerd/run/tmp"}
45
46 if err := unix.Mount("tmpfs", "/containerd/run", "tmpfs", 0, ""); err != nil {
47 panic(err)
48 }
49 if err := os.MkdirAll("/containerd/run/tmp", 0755); err != nil {
50 panic(err)
51 }
52
53 // TODO(lorenz): Healthcheck against CRI RuntimeService.Status() and SignalHealthy
54
55 err := cmd.Run()
56 fmt.Fprintf(s.Log, "containerd stopped: %v\n", err)
57 return err
Lorenz Brunc88c82d2020-05-08 14:35:04 +020058 }
Lorenz Brunc88c82d2020-05-08 14:35:04 +020059}