github.com/rkt/rkt@v1.30.1-0.20200224141603-171c416fac02/stage1/app_start/app_start.go (about) 1 // Copyright 2016 The rkt Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //+build linux 16 17 package main 18 19 import ( 20 "flag" 21 "io/ioutil" 22 "os" 23 "os/exec" 24 25 rktlog "github.com/rkt/rkt/pkg/log" 26 stage1common "github.com/rkt/rkt/stage1/common" 27 stage1initcommon "github.com/rkt/rkt/stage1/init/common" 28 29 "github.com/appc/spec/schema/types" 30 ) 31 32 var ( 33 flagApp string 34 debug bool 35 log *rktlog.Logger 36 diag *rktlog.Logger 37 ) 38 39 func init() { 40 flag.StringVar(&flagApp, "app", "", "Application name") 41 flag.BoolVar(&debug, "debug", false, "Run in debug mode") 42 } 43 44 func main() { 45 flag.Parse() 46 47 stage1initcommon.InitDebug(debug) 48 49 log, diag, _ = rktlog.NewLogSet("app-start", debug) 50 if !debug { 51 diag.SetOutput(ioutil.Discard) 52 } 53 54 appName, err := types.NewACName(flagApp) 55 if err != nil { 56 log.FatalE("invalid app name", err) 57 } 58 59 enterCmd := stage1common.PrepareEnterCmd(false) 60 61 args := enterCmd 62 args = append(args, "/usr/bin/systemctl") 63 args = append(args, "start") 64 args = append(args, appName.String()) 65 66 cmd := exec.Cmd{ 67 Path: args[0], 68 Args: args, 69 } 70 71 if out, err := cmd.CombinedOutput(); err != nil { 72 log.Fatalf("%q failed to start:\n%s", appName, out) 73 } 74 75 os.Exit(0) 76 }