github.com/containerd/containerd@v22.0.0-20200918172823-438c87b8e050+incompatible/services/opt/service.go (about) 1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package opt 18 19 import ( 20 "fmt" 21 "os" 22 "path/filepath" 23 24 "github.com/containerd/containerd/plugin" 25 "github.com/pkg/errors" 26 ) 27 28 // Config for the opt manager 29 type Config struct { 30 // Path for the opt directory 31 Path string `toml:"path"` 32 } 33 34 func init() { 35 plugin.Register(&plugin.Registration{ 36 Type: plugin.InternalPlugin, 37 ID: "opt", 38 Config: &Config{ 39 Path: defaultPath, 40 }, 41 InitFn: func(ic *plugin.InitContext) (interface{}, error) { 42 path := ic.Config.(*Config).Path 43 ic.Meta.Exports["path"] = path 44 bin := filepath.Join(path, "bin") 45 if err := os.MkdirAll(bin, 0711); err != nil { 46 return nil, err 47 } 48 if err := os.Setenv("PATH", fmt.Sprintf("%s%c%s", bin, os.PathListSeparator, os.Getenv("PATH"))); err != nil { 49 return nil, errors.Wrapf(err, "set binary image directory in path %s", bin) 50 } 51 52 lib := filepath.Join(path, "lib") 53 if err := os.MkdirAll(lib, 0711); err != nil { 54 return nil, err 55 } 56 if err := os.Setenv("LD_LIBRARY_PATH", fmt.Sprintf("%s%c%s", lib, os.PathListSeparator, os.Getenv("LD_LIBRARY_PATH"))); err != nil { 57 return nil, errors.Wrapf(err, "set binary lib directory in path %s", lib) 58 } 59 return &manager{}, nil 60 }, 61 }) 62 } 63 64 type manager struct { 65 }