github.com/blixtra/rkt@v0.8.1-0.20160204105720-ab0d1add1a43/stage0/entrypoint.go (about) 1 // Copyright 2015 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 stage0 18 19 import ( 20 "encoding/json" 21 "errors" 22 "fmt" 23 "io/ioutil" 24 25 "github.com/appc/spec/schema" 26 "github.com/coreos/rkt/common" 27 "github.com/hashicorp/errwrap" 28 ) 29 30 const ( 31 enterEntrypoint = "coreos.com/rkt/stage1/enter" 32 runEntrypoint = "coreos.com/rkt/stage1/run" 33 gcEntrypoint = "coreos.com/rkt/stage1/gc" 34 ) 35 36 // getStage1Entrypoint retrieves the named entrypoint from the stage1 manifest for a given pod 37 func getStage1Entrypoint(cdir string, entrypoint string) (string, error) { 38 b, err := ioutil.ReadFile(common.Stage1ManifestPath(cdir)) 39 if err != nil { 40 return "", errwrap.Wrap(errors.New("error reading pod manifest"), err) 41 } 42 43 s1m := schema.ImageManifest{} 44 if err := json.Unmarshal(b, &s1m); err != nil { 45 return "", errwrap.Wrap(errors.New("error unmarshaling stage1 manifest"), err) 46 } 47 48 if ep, ok := s1m.Annotations.Get(entrypoint); ok { 49 return ep, nil 50 } 51 52 return "", fmt.Errorf("entrypoint %q not found", entrypoint) 53 }