本文整理汇总了Golang中github.com/openshift/geard/config.ContainerBasePath函数的典型用法代码示例。如果您正苦于以下问题:Golang ContainerBasePath函数的具体用法?Golang ContainerBasePath怎么用?Golang ContainerBasePath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ContainerBasePath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
config.AddRequiredDirectory(
0750,
filepath.Join(config.ContainerBasePath(), "env", "contents"),
filepath.Join(config.ContainerBasePath(), "ports", "descriptions"),
filepath.Join(config.ContainerBasePath(), "ports", "interfaces"),
)
config.AddRequiredDirectory(
0755,
filepath.Join(config.SystemdBasePath(), "container-active.target.wants"),
)
}
示例2: init
func init() {
handler := &containerPermission{}
AddPermissionHandler("", handler)
AddPermissionHandler(ContainerPermissionType, handler)
// Register the required configuration directories
config.AddRequiredDirectory(
0755,
config.ContainerBasePath(),
filepath.Join(config.ContainerBasePath(), "access", "containers", "ssh"),
filepath.Join(config.ContainerBasePath(), "keys", "public"),
)
}
示例3: init
func init() {
config.AddRequiredDirectory(
0755,
config.ContainerBasePath(),
filepath.Join(config.ContainerBasePath(), "home"),
filepath.Join(config.ContainerBasePath(), "units"),
)
config.AddRequiredDirectory(
0750,
filepath.Join(config.ContainerBasePath(), "targets"),
filepath.Join(config.ContainerBasePath(), "slices"),
)
}
示例4: disableAllUnits
func disableAllUnits() {
systemd := systemd.Connection()
for _, path := range []string{
filepath.Join(config.ContainerBasePath(), "units"),
} {
filepath.Walk(path, func(p string, info os.FileInfo, err error) error {
if os.IsNotExist(err) {
return nil
}
if err != nil {
log.Printf("init: Can't read %s: %v", p, err)
return nil
}
if info.IsDir() {
return nil
}
if !isSystemdFile(p) {
return nil
}
fmt.Printf("Stopping and disabling %s\n", filepath.Base(p))
if status, err := systemd.StopUnit(filepath.Base(p), "fail"); err != nil {
log.Printf("init: Unable to stop %s: %v, %+v", p, status, err)
}
if _, err := systemd.DisableUnitFiles([]string{p}, false); err != nil {
log.Printf("init: Unable to disable %s: %+v", p, err)
}
return nil
})
if err := systemd.Reload(); err != nil {
log.Printf("init: systemd reload failed: %+v", err)
}
}
}
示例5: GitAccessPathFor
func (i RepoIdentifier) GitAccessPathFor(name string, write bool) string {
var access string
if write {
access = ".write"
} else {
access = ".read"
}
return utils.IsolateContentPathWithPerm(filepath.Join(config.ContainerBasePath(), "access", "git"), string(i), name+access, 0775)
}
示例6: GetDockerContainerPacketCounts
func GetDockerContainerPacketCounts(d *docker.DockerClient) (map[containers.Identifier]int, error) {
serviceFiles, err := filepath.Glob(filepath.Join(gearconfig.ContainerBasePath(), "units", "**", containers.IdentifierPrefix+"*.service"))
if err != nil {
return nil, err
}
ids := make([]string, 0)
packetCount := make(map[containers.Identifier]int)
for _, s := range serviceFiles {
id := filepath.Base(s)
if strings.HasPrefix(id, containers.IdentifierPrefix) && strings.HasSuffix(id, ".service") {
id = id[len(containers.IdentifierPrefix):(len(id) - len(".service"))]
if id, err := containers.NewIdentifier(id); err == nil {
ids = append(ids, string(id))
packetCount[id] = 0
}
}
}
containerIPs, err := d.GetContainerIPs(ids)
if err != nil {
return nil, err
}
cmd := exec.Command("/sbin/iptables-save", "-c")
output, err := cmd.Output()
if err != nil {
return nil, err
}
scan := bufio.NewScanner(bytes.NewBuffer(output))
for scan.Scan() {
line := scan.Text()
if strings.Contains(line, "-A DOCKER ! -i docker0") && strings.Contains(line, "-j DNAT") {
//Example: [0:0] -A DOCKER ! -i docker0 -p tcp -m tcp --dport 4000 -j DNAT --to-destination 172.17.0.3:8080
items := strings.Fields(line)
packets, _ := strconv.Atoi(strings.Split(items[0], ":")[0][1:])
destIp := strings.Split(items[15], ":")[0]
id, _ := containers.NewIdentifier(containerIPs[destIp])
packetCount[id] = packetCount[id] + packets
}
if strings.Contains(line, "-A OUTPUT -d 127.0.0.1/32 -p tcp -m tcp --dport") && strings.Contains(line, "-m comment --comment ") {
//Example: [5850:394136] -A OUTPUT -d 127.0.0.1/32 -p tcp -m tcp --dport 4000 -m comment --comment 0001 -j ACCEPT
items := strings.Fields(line)
packets, _ := strconv.Atoi(strings.Split(items[0], ":")[0][1:])
if id, err := containers.NewIdentifier(items[14]); err == nil {
packetCount[id] = packetCount[id] + packets
}
}
}
return packetCount, nil
}
示例7: Clean
// Removes unused definition files by checking what definition files
// are actually in use in the service file.
func (r *UnitFilesCleanup) Clean(ctx *CleanerContext) {
if !ctx.Repair {
return
}
ctx.LogInfo.Println("--- UNIT FILES REPAIR ---")
unitsPath := filepath.Join(config.ContainerBasePath(), "units")
filepath.Walk(unitsPath, func(path string, info os.FileInfo, err error) error {
if os.IsNotExist(err) {
return nil
}
if err != nil {
ctx.LogError.Printf("repair_unit_files: Can't read %s: %v", path, err)
return nil
}
if info.IsDir() {
return nil
}
if filepath.Ext(path) != ".service" {
return nil
}
props, er := systemd.GetUnitFileProperties(path)
if er != nil {
ctx.LogError.Println("Failed to get unit file properties")
return er
}
// X-ContainerRequestId property has the name of the definition file in use.
currDefinitionFile, ok := props["X-ContainerRequestId"]
if !ok {
return nil
}
containerId, ok := props["X-ContainerId"]
if !ok {
return nil
}
definitionsDirPath := filepath.Join(filepath.Dir(path), containerId)
removeFilesExcluding(currDefinitionFile, definitionsDirPath, r.unusedFor, ctx)
// TODO: Also remove empty directories.
// TODO: Validate the ports and other information in the systemd file.
return nil
})
}
示例8: InitializeSystemdFile
func InitializeSystemdFile(fType SystemdFileType, name string, template *template.Template, values interface{}, start bool) error {
var partPath string
var ext string
switch {
case fType == TargetType:
partPath = "targets"
ext = ".target"
case fType == SliceType:
partPath = "slices"
ext = ".slice"
case fType == UnitType:
partPath = "units"
ext = ".service"
}
path := filepath.Join(config.ContainerBasePath(), partPath, name+ext)
unit, err := os.OpenFile(path, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0666)
if os.IsExist(err) {
return nil
} else if err != nil {
return err
}
if errs := template.Execute(unit, values); errs != nil {
log.Printf("gear: Unable to write %s %s: %v", fType, name, errs)
return nil
}
if errc := unit.Close(); errc != nil {
log.Printf("gear: Unable to close target %s %s: %v", fType, name, errc)
return nil
}
if start {
log.Printf("systemd: Starting %s", path)
_, err = StartAndEnableUnit(Connection(), name+ext, path, "fail")
return err
} else {
return EnableAndReloadUnit(Connection(), name+ext, path)
}
return nil
}
示例9: Clean
// Remove port allocations that don't point to systemd definition files.
func (r *PortsCleanup) Clean(ctx *CleanerContext) {
ctx.LogInfo.Println("--- PORTS CLEANUP ---")
portsPath := filepath.Join(config.ContainerBasePath(), "ports", "interfaces")
filepath.Walk(portsPath, func(path string, fi os.FileInfo, err error) error {
if os.IsNotExist(err) {
return nil
}
if err != nil {
ctx.LogError.Printf("Can't read %s: %v", path, err)
return nil
}
if fi.IsDir() {
return nil
}
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
unitPath, err := os.Readlink(path)
if err != nil {
ctx.LogError.Printf("Failed to read the link: %v", err)
return nil
}
if _, err := os.Stat(unitPath); os.IsNotExist(err) {
ctx.LogInfo.Printf("Recovering port %v as it does not point to a definition file.", path)
if !ctx.DryRun {
if err = os.Remove(path); err != nil {
ctx.LogError.Printf("Failed to remove %s: %v", path, err)
}
}
return nil
}
}
return nil
})
}
示例10: VersionedUnitPathFor
func (i Identifier) VersionedUnitPathFor(suffix string) string {
return utils.IsolateContentPathWithPerm(filepath.Join(config.ContainerBasePath(), "units"), string(i), suffix, 0775)
}
示例11: init
func init() {
// Bind mounted into the router
config.AddRequiredDirectory(0755, filepath.Join(config.ContainerBasePath(), "router"))
}
示例12: PortDescriptionPathFor
func (i Identifier) PortDescriptionPathFor() string {
return utils.IsolateContentPath(filepath.Join(config.ContainerBasePath(), "ports", "descriptions"), string(i), "")
}
示例13: publicKeyPathFor
func publicKeyPathFor(f utils.Fingerprint) string {
return utils.IsolateContentPathWithPerm(filepath.Join(config.ContainerBasePath(), "keys", "public"), f.ToShortName(), "", 0775)
}
示例14: RepositoryPathFor
func (i RepoIdentifier) RepositoryPathFor() string {
return filepath.Join(config.ContainerBasePath(), "git", string(i))
}
示例15: HomePath
func (i RepoIdentifier) HomePath() string {
return utils.IsolateContentPathWithPerm(filepath.Join(config.ContainerBasePath(), fmt.Sprintf("%shome", RepoIdentifierPrefix)), string(i), "home", 0775)
}