Lorenz Brun | c88c82d | 2020-05-08 14:35:04 +0200 | [diff] [blame] | 1 | // 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 | |
| 17 | package containerd |
| 18 | |
| 19 | import ( |
| 20 | "context" |
Lorenz Brun | 878f5f9 | 2020-05-12 16:15:39 +0200 | [diff] [blame^] | 21 | "fmt" |
| 22 | "git.monogon.dev/source/nexantic.git/core/internal/common/supervisor" |
Lorenz Brun | c88c82d | 2020-05-08 14:35:04 +0200 | [diff] [blame] | 23 | "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 Brun | 878f5f9 | 2020-05-12 16:15:39 +0200 | [diff] [blame^] | 31 | type Service struct { |
| 32 | Log *logbuffer.LogBuffer |
| 33 | } |
Lorenz Brun | c88c82d | 2020-05-08 14:35:04 +0200 | [diff] [blame] | 34 | |
Lorenz Brun | 878f5f9 | 2020-05-12 16:15:39 +0200 | [diff] [blame^] | 35 | func New() (*Service, error) { |
| 36 | return &Service{Log: logbuffer.New(5000, 16384)}, nil |
| 37 | } |
Lorenz Brun | c88c82d | 2020-05-08 14:35:04 +0200 | [diff] [blame] | 38 | |
Lorenz Brun | 878f5f9 | 2020-05-12 16:15:39 +0200 | [diff] [blame^] | 39 | func (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 Brun | c88c82d | 2020-05-08 14:35:04 +0200 | [diff] [blame] | 58 | } |
Lorenz Brun | c88c82d | 2020-05-08 14:35:04 +0200 | [diff] [blame] | 59 | } |