Ai
3 Star 0 Fork 1

Gitee 极速下载/linuxkit

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/linuxkit/linuxkit
克隆/下载
main.go 3.02 KB
一键复制 编辑 原始数据 按行查看 历史
Justin Barrick 提交于 2018-06-08 06:50 +08:00 . Add a restart and stop command to service.
package main
import (
"context"
"flag"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/containerd/containerd/namespaces"
log "github.com/sirupsen/logrus"
)
const (
defaultSocket = "/run/containerd/containerd.sock"
defaultPath = "/containers/services"
defaultContainerd = "/usr/bin/containerd"
installPath = "/usr/bin/service"
onbootPath = "/containers/onboot"
shutdownPath = "/containers/onshutdown"
defaultContainerdNamespace = "services.linuxkit"
)
var (
defaultLogFormatter = &log.TextFormatter{}
)
// infoFormatter overrides the default format for Info() log events to
// provide an easier to read output
type infoFormatter struct {
}
func (f *infoFormatter) Format(entry *log.Entry) ([]byte, error) {
if entry.Level == log.InfoLevel {
return append([]byte(entry.Message), '\n'), nil
}
return defaultLogFormatter.Format(entry)
}
func main() {
flag.Usage = func() {
fmt.Printf("USAGE: %s [options] COMMAND\n\n", filepath.Base(os.Args[0]))
fmt.Printf("Commands:\n")
fmt.Printf(" system-init Prepare the system at start of day\n")
fmt.Printf(" stop Stop a service\n")
fmt.Printf(" start Start a service\n")
fmt.Printf(" restart Restart a service\n")
fmt.Printf(" help Print this message\n")
fmt.Printf("\n")
fmt.Printf("Run '%s COMMAND --help' for more information on the command\n", filepath.Base(os.Args[0]))
fmt.Printf("\n")
fmt.Printf("Options:\n")
flag.PrintDefaults()
}
var (
ctx = context.Background()
flagQuiet = flag.Bool("q", false, "Quiet execution")
flagVerbose = flag.Bool("v", false, "Verbose execution")
flagContainerdNamespace = flag.String("containerd-namespace", defaultContainerdNamespace, "containerd namespace to use with services")
)
// Set up logging
log.SetFormatter(new(infoFormatter))
log.SetLevel(log.InfoLevel)
flag.Parse()
if *flagQuiet && *flagVerbose {
fmt.Printf("Can't set quiet and verbose flag at the same time\n")
os.Exit(1)
}
if *flagQuiet {
log.SetLevel(log.ErrorLevel)
}
if *flagVerbose {
// Switch back to the standard formatter
log.SetFormatter(defaultLogFormatter)
log.SetLevel(log.DebugLevel)
}
ctx = namespaces.WithNamespace(ctx, *flagContainerdNamespace)
args := flag.Args()
if len(args) < 1 {
// check if called form startup scripts
command := os.Args[0]
switch {
case strings.Contains(command, "onboot"):
os.Exit(runcInit(onbootPath, "onboot"))
case strings.Contains(command, "onshutdown"):
os.Exit(runcInit(shutdownPath, "shutdown"))
case strings.Contains(command, "containerd"):
systemInitCmd(ctx, []string{})
os.Exit(0)
}
}
if len(args) < 1 {
flag.Usage()
os.Exit(1)
}
switch args[0] {
case "stop":
stopCmd(ctx, args[1:])
case "start":
startCmd(ctx, args[1:])
case "restart":
restartCmd(ctx, args[1:])
case "system-init":
systemInitCmd(ctx, args[1:])
default:
fmt.Printf("%q is not valid command.\n\n", args[0])
flag.Usage()
os.Exit(1)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/mirrors/linuxkit.git
git@gitee.com:mirrors/linuxkit.git
mirrors
linuxkit
linuxkit
46ef83c97931

搜索帮助