本文整理汇总了Golang中github.com/snapcore/snapd/logger.Noticef函数的典型用法代码示例。如果您正苦于以下问题:Golang Noticef函数的具体用法?Golang Noticef怎么用?Golang Noticef使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Noticef函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: RemoveSnapServices
// RemoveSnapServices disables and removes service units for the applications from the snap which are services.
func RemoveSnapServices(s *snap.Info, inter interacter) error {
sysd := systemd.New(dirs.GlobalRootDir, inter)
nservices := 0
for _, app := range s.Apps {
if app.Daemon == "" {
continue
}
nservices++
serviceName := filepath.Base(app.ServiceFile())
if err := sysd.Disable(serviceName); err != nil {
return err
}
if err := os.Remove(app.ServiceFile()); err != nil && !os.IsNotExist(err) {
logger.Noticef("Failed to remove service file for %q: %v", serviceName, err)
}
if err := os.Remove(app.ServiceSocketFile()); err != nil && !os.IsNotExist(err) {
logger.Noticef("Failed to remove socket file for %q: %v", serviceName, err)
}
}
// only reload if we actually had services
if nservices > 0 {
if err := sysd.DaemonReload(); err != nil {
return err
}
}
return nil
}
开发者ID:clobrano,项目名称:snappy,代码行数:35,代码来源:services.go
示例2: removeCurrentSymlinks
func removeCurrentSymlinks(info snap.PlaceInfo) error {
var err1, err2 error
// the snap "current" symlink
currentActiveSymlink := filepath.Join(info.MountDir(), "..", "current")
err1 = os.Remove(currentActiveSymlink)
if err1 != nil && !os.IsNotExist(err1) {
logger.Noticef("Cannot remove %q: %v", currentActiveSymlink, err1)
} else {
err1 = nil
}
// the data "current" symlink
currentDataSymlink := filepath.Join(info.DataDir(), "..", "current")
err2 = os.Remove(currentDataSymlink)
if err2 != nil && !os.IsNotExist(err2) {
logger.Noticef("Cannot remove %q: %v", currentDataSymlink, err2)
} else {
err2 = nil
}
if err1 != nil && err2 != nil {
return fmt.Errorf("cannot remove snap current symlink: %v and %v", err1, err2)
} else if err1 != nil {
return fmt.Errorf("cannot remove snap current symlink: %v", err1)
} else if err2 != nil {
return fmt.Errorf("cannot remove snap current symlink: %v", err2)
}
return nil
}
开发者ID:niemeyer,项目名称:snapd,代码行数:31,代码来源:link.go
示例3: autoImportFromAllMounts
func autoImportFromAllMounts() (int, error) {
cands, err := autoImportCandidates()
if err != nil {
return 0, err
}
added := 0
for _, cand := range cands {
err := ackFile(cand)
// the server is not ready yet
if _, ok := err.(client.ConnectionError); ok {
logger.Noticef("queuing for later %s", cand)
if err := queueFile(cand); err != nil {
return 0, err
}
continue
}
if err != nil {
logger.Noticef("error: cannot import %s: %s", cand, err)
continue
} else {
logger.Noticef("imported %s", cand)
}
added++
}
return added, nil
}
开发者ID:niemeyer,项目名称:snapd,代码行数:28,代码来源:cmd_auto_import.go
示例4: autoImportFromSpool
func autoImportFromSpool() (added int, err error) {
files, err := ioutil.ReadDir(dirs.SnapAssertsSpoolDir)
if os.IsNotExist(err) {
return 0, nil
}
if err != nil {
return 0, err
}
for _, fi := range files {
cand := filepath.Join(dirs.SnapAssertsSpoolDir, fi.Name())
if err := ackFile(cand); err != nil {
logger.Noticef("error: cannot import %s: %s", cand, err)
continue
} else {
logger.Noticef("imported %s", cand)
added++
}
// FIXME: only remove stuff older than N days?
if err := os.Remove(cand); err != nil {
return 0, err
}
}
return added, nil
}
开发者ID:niemeyer,项目名称:snapd,代码行数:26,代码来源:cmd_auto_import.go
示例5: patch1
// patch1 adds the snap type and the current revision to the snap state.
func patch1(s *state.State) error {
var stateMap map[string]*snapstate.SnapState
err := s.Get("snaps", &stateMap)
if err == state.ErrNoState {
return nil
}
if err != nil {
return err
}
for snapName, snapState := range stateMap {
seq := snapState.Sequence
if len(seq) == 0 {
continue
}
typ := snap.TypeApp
snapInfo, err := readInfo(snapName, seq[len(seq)-1])
if err != nil {
logger.Noticef("Recording type for snap %q: cannot retrieve info, assuming it's a app: %v", snapName, err)
} else {
logger.Noticef("Recording type for snap %q: setting to %q", snapName, snapInfo.Type)
typ = snapInfo.Type
}
snapState.SetType(typ)
snapState.Current = seq[len(seq)-1].Revision
}
s.Set("snaps", stateMap)
return nil
}
开发者ID:clobrano,项目名称:snappy,代码行数:32,代码来源:patch1.go
示例6: check
func (c *autoConnectChecker) check(plug *interfaces.Plug, slot *interfaces.Slot) bool {
var plugDecl *asserts.SnapDeclaration
if plug.Snap.SnapID != "" {
var err error
plugDecl, err = c.snapDeclaration(plug.Snap.SnapID)
if err != nil {
logger.Noticef("error: cannot find snap declaration for %q: %v", plug.Snap.Name(), err)
return false
}
}
var slotDecl *asserts.SnapDeclaration
if slot.Snap.SnapID != "" {
var err error
slotDecl, err = c.snapDeclaration(slot.Snap.SnapID)
if err != nil {
logger.Noticef("error: cannot find snap declaration for %q: %v", slot.Snap.Name(), err)
return false
}
}
// check the connection against the declarations' rules
ic := policy.ConnectCandidate{
Plug: plug.PlugInfo,
PlugSnapDeclaration: plugDecl,
Slot: slot.SlotInfo,
SlotSnapDeclaration: slotDecl,
BaseDeclaration: c.baseDecl,
}
return ic.CheckAutoConnect() == nil
}
开发者ID:niemeyer,项目名称:snapd,代码行数:32,代码来源:helpers.go
示例7: Apply
// Apply applies any necessary patches to update the provided state to
// conventions required by the current patch level of the system.
func Apply(s *state.State) error {
var stateLevel int
s.Lock()
err := s.Get("patch-level", &stateLevel)
s.Unlock()
if err != nil && err != state.ErrNoState {
return err
}
if stateLevel == Level {
// already at right level, nothing to do
return nil
}
if stateLevel > Level {
return fmt.Errorf("cannot downgrade: snapd is too old for the current system state (patch level %d)", stateLevel)
}
level := stateLevel
for level < Level {
logger.Noticef("Patching system state from level %d to %d", level, level+1)
patch := patches[level+1]
if patch == nil {
return fmt.Errorf("cannot upgrade: snapd is too new for the current system state (patch level %d)", level)
}
err := applyOne(patch, s, level)
if err != nil {
logger.Noticef("Cannnot patch: %v", err)
return fmt.Errorf("cannot patch system state from level %d to %d: %v", level, level+1, err)
}
level++
}
return nil
}
开发者ID:niemeyer,项目名称:snapd,代码行数:35,代码来源:patch.go
示例8: UpdateMany
// UpdateMany updates everything from the given list of names that the
// store says is updateable. If the list is empty, update everything.
// Note that the state must be locked by the caller.
func UpdateMany(st *state.State, names []string, userID int) ([]string, []*state.TaskSet, error) {
user, err := userFromUserID(st, userID)
if err != nil {
return nil, nil, err
}
updates, stateByID, err := refreshCandidates(st, names, user)
if err != nil {
return nil, nil, err
}
if ValidateRefreshes != nil && len(updates) != 0 {
updates, err = ValidateRefreshes(st, updates, userID)
if err != nil {
// not doing "refresh all" report the error
if len(names) != 0 {
return nil, nil, err
}
// doing "refresh all", log the problems
logger.Noticef("cannot refresh some snaps: %v", err)
}
}
updated := make([]string, 0, len(updates))
tasksets := make([]*state.TaskSet, 0, len(updates))
for _, update := range updates {
snapst := stateByID[update.SnapID]
// XXX: this check goes away when update-to-local is done
if err := checkRevisionIsNew(update.Name(), snapst, update.Revision); err != nil {
continue
}
ss := &SnapSetup{
Channel: snapst.Channel,
UserID: userID,
Flags: snapst.Flags.ForSnapSetup(),
DownloadInfo: &update.DownloadInfo,
SideInfo: &update.SideInfo,
}
ts, err := doInstall(st, snapst, ss)
if err != nil {
if len(names) == 0 {
// doing "refresh all", just skip this snap
logger.Noticef("cannot refresh snap %q: %v", update.Name(), err)
continue
}
return nil, nil, err
}
updated = append(updated, update.Name())
tasksets = append(tasksets, ts)
}
return updated, tasksets, nil
}
开发者ID:niemeyer,项目名称:snapd,代码行数:58,代码来源:snapstate.go
示例9: UpdateBootRevisions
// UpdateBootRevisions synchronizes the active kernel and OS snap versions
// with the versions that actually booted. This is needed because a
// system may install "os=v2" but that fails to boot. The bootloader
// fallback logic will revert to "os=v1" but on the filesystem snappy
// still has the "active" version set to "v2" which is
// misleading. This code will check what kernel/os booted and set
// those versions active.To do this it creates a Change and kicks
// start it directly.
func UpdateBootRevisions(st *state.State) error {
const errorPrefix = "cannot update revisions after boot changes: "
if release.OnClassic {
return nil
}
bootloader, err := partition.FindBootloader()
if err != nil {
return fmt.Errorf(errorPrefix+"%s", err)
}
m, err := bootloader.GetBootVars("snap_kernel", "snap_core")
if err != nil {
return fmt.Errorf(errorPrefix+"%s", err)
}
var tsAll []*state.TaskSet
for _, snapNameAndRevno := range []string{m["snap_kernel"], m["snap_core"]} {
name, rev, err := nameAndRevnoFromSnap(snapNameAndRevno)
if err != nil {
logger.Noticef("cannot parse %q: %s", snapNameAndRevno, err)
continue
}
info, err := CurrentInfo(st, name)
if err != nil {
logger.Noticef("cannot get info for %q: %s", name, err)
continue
}
if rev != info.SideInfo.Revision {
// FIXME: check that there is no task
// for this already in progress
ts, err := RevertToRevision(st, name, rev, Flags{})
if err != nil {
return err
}
tsAll = append(tsAll, ts)
}
}
if len(tsAll) == 0 {
return nil
}
msg := fmt.Sprintf("Update kernel and core snap revisions")
chg := st.NewChange("update-revisions", msg)
for _, ts := range tsAll {
chg.AddAll(ts)
}
st.EnsureBefore(0)
return nil
}
开发者ID:niemeyer,项目名称:snapd,代码行数:61,代码来源:booted.go
示例10: Setup
func (b *Backend) Setup(snapInfo *snap.Info, confinement interfaces.ConfinementOptions, repo *interfaces.Repository) error {
snapName := snapInfo.Name()
rawSnippets, err := repo.SecuritySnippetsForSnap(snapInfo.Name(), interfaces.SecuritySystemd)
if err != nil {
return fmt.Errorf("cannot obtain systemd security snippets for snap %q: %s", snapName, err)
}
snippets, err := unmarshalRawSnippetMap(rawSnippets)
if err != nil {
return fmt.Errorf("cannot unmarshal systemd snippets for snap %q: %s", snapName, err)
}
snippet, err := mergeSnippetMap(snippets)
if err != nil {
return fmt.Errorf("cannot merge systemd snippets for snap %q: %s", snapName, err)
}
content, err := renderSnippet(snippet)
if err != nil {
return fmt.Errorf("cannot render systemd snippets for snap %q: %s", snapName, err)
}
dir := dirs.SnapServicesDir
if err := os.MkdirAll(dir, 0755); err != nil {
return fmt.Errorf("cannot create directory for systemd services %q: %s", dir, err)
}
glob := interfaces.InterfaceServiceName(snapName, "*")
systemd := sysd.New(dirs.GlobalRootDir, &dummyReporter{})
// We need to be carefully here and stop all removed service units before
// we remove their files as otherwise systemd is not able to disable/stop
// them anymore.
if err := disableRemovedServices(systemd, dir, glob, content); err != nil {
logger.Noticef("cannot stop removed services: %s", err)
}
changed, removed, errEnsure := osutil.EnsureDirState(dir, glob, content)
// Reload systemd whenever something is added or removed
if len(changed) > 0 || len(removed) > 0 {
err := systemd.DaemonReload()
if err != nil {
logger.Noticef("cannot reload systemd state: %s", err)
}
}
// Ensure the service is running right now and on reboots
for _, service := range changed {
if err := systemd.Enable(service); err != nil {
logger.Noticef("cannot enable service %q: %s", service, err)
}
// If we have a new service here which isn't started yet the restart
// operation will start it.
if err := systemd.Restart(service, 10*time.Second); err != nil {
logger.Noticef("cannot restart service %q: %s", service, err)
}
}
return errEnsure
}
开发者ID:pedronis,项目名称:snappy,代码行数:52,代码来源:backend.go
示例11: ClearTrashedData
// ClearTrashedData removes the trash. It returns no errors on the assumption that it is called very late in the game.
func (b Backend) ClearTrashedData(oldSnap *snap.Info) {
dirs, err := snapDataDirs(oldSnap)
if err != nil {
logger.Noticef("Cannot remove previous data for %q: %v", oldSnap.Name(), err)
return
}
for _, d := range dirs {
if err := clearTrash(d); err != nil {
logger.Noticef("Cannot remove %s: %v", d, err)
}
}
}
开发者ID:niemeyer,项目名称:snapd,代码行数:14,代码来源:copydata.go
示例12: Setup
func (b *Backend) Setup(snapInfo *snap.Info, devMode bool, repo *interfaces.Repository) error {
snapName := snapInfo.Name()
rawSnippets, err := repo.SecuritySnippetsForSnap(snapInfo.Name(), interfaces.SecuritySystemd)
if err != nil {
return fmt.Errorf("cannot obtain systemd security snippets for snap %q: %s", snapName, err)
}
snippets, err := unmarshalRawSnippetMap(rawSnippets)
if err != nil {
return fmt.Errorf("cannot unmarshal systemd snippets for snap %q: %s", snapName, err)
}
snippet, err := mergeSnippetMap(snippets)
if err != nil {
return fmt.Errorf("cannot merge systemd snippets for snap %q: %s", snapName, err)
}
content, err := renderSnippet(snippet)
if err != nil {
return fmt.Errorf("cannot render systemd snippets for snap %q: %s", snapName, err)
}
dir := dirs.SnapServicesDir
if err := os.MkdirAll(dir, 0755); err != nil {
return fmt.Errorf("cannot create directory for systemd services %q: %s", dir, err)
}
glob := interfaces.InterfaceServiceName(snapName, "*")
changed, removed, errEnsure := osutil.EnsureDirState(dir, glob, content)
systemd := sysd.New(dirs.GlobalRootDir, &dummyReporter{})
// Reload systemd whenever something is added or removed
if len(changed) > 0 || len(removed) > 0 {
err := systemd.DaemonReload()
if err != nil {
logger.Noticef("cannot reload systemd state: %s", err)
}
}
// Start any new services
for _, service := range changed {
err := systemd.Start(service)
if err != nil {
logger.Noticef("cannot start service %q: %s", service, err)
}
}
// Stop any removed services
for _, service := range removed {
err := systemd.Stop(service, 10*time.Second)
if err != nil {
logger.Noticef("cannot stop service %q: %s", service, err)
}
}
return errEnsure
}
开发者ID:niemeyer,项目名称:snapd,代码行数:48,代码来源:backend.go
示例13: KernelOrOsRebootRequired
// KernelOrOsRebootRequired returns whether a reboot is required to swith to the given OS or kernel snap.
func KernelOrOsRebootRequired(s *snap.Info) bool {
if s.Type != snap.TypeKernel && s.Type != snap.TypeOS {
return false
}
bootloader, err := partition.FindBootloader()
if err != nil {
logger.Noticef("cannot get boot settings: %s", err)
return false
}
var nextBoot, goodBoot string
switch s.Type {
case snap.TypeKernel:
nextBoot = "snap_try_kernel"
goodBoot = "snap_kernel"
case snap.TypeOS:
nextBoot = "snap_try_core"
goodBoot = "snap_core"
}
m, err := bootloader.GetBootVars(nextBoot, goodBoot)
if err != nil {
return false
}
squashfsName := filepath.Base(s.MountFile())
if m[nextBoot] == squashfsName && m[goodBoot] != m[nextBoot] {
return true
}
return false
}
开发者ID:pedronis,项目名称:snappy,代码行数:34,代码来源:kernel_os.go
示例14: run
func run() error {
store.SetUserAgentFromVersion(cmd.Version)
d, err := daemon.New()
if err != nil {
return err
}
if err := d.Init(); err != nil {
return err
}
d.Version = cmd.Version
d.Start()
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
select {
case sig := <-ch:
logger.Noticef("Exiting on %s signal.\n", sig)
case <-d.Dying():
// something called Stop()
}
return d.Stop()
}
开发者ID:niemeyer,项目名称:snapd,代码行数:25,代码来源:main.go
示例15: FirstBoot
// FirstBoot will do some initial boot setup and then sync the
// state
func FirstBoot() error {
// Disable firstboot on classic for now. In the long run we want
// classic to have a firstboot as well so that we can install
// snaps in a classic environment (LP: #1609903). However right
// now firstboot is under heavy development so until the dust
// settles we disable it.
if release.OnClassic {
return nil
}
if firstboot.HasRun() {
return ErrNotFirstBoot
}
// FIXME: the netplan config is static, we do not need to generate
// it from snapd, we can just set it in e.g. ubuntu-core-config
if err := firstbootInitialNetworkConfig(); err != nil {
logger.Noticef("Failed during inital network configuration: %s", err)
}
// snappy will be in a very unhappy state if this happens,
// because populateStateFromSeed will error if there
// is a state file already
if err := populateStateFromSeed(); err != nil {
return err
}
return firstboot.StampFirstBoot()
}
开发者ID:clobrano,项目名称:snappy,代码行数:31,代码来源:firstboot.go
示例16: requestRestart
func (o *Overlord) requestRestart(t state.RestartType) {
if o.restartHandler == nil {
logger.Noticef("restart requested but no handler set")
} else {
o.restartHandler(t)
}
}
开发者ID:clobrano,项目名称:snappy,代码行数:7,代码来源:overlord.go
示例17: runSnapConfine
func runSnapConfine(info *snap.Info, securityTag, snapApp, command, hook string, args []string) error {
if err := createUserDataDirs(info); err != nil {
logger.Noticef("WARNING: cannot create user data directory: %s", err)
}
cmd := []string{
filepath.Join(dirs.LibExecDir, "snap-confine"),
securityTag,
filepath.Join(dirs.LibExecDir, "snap-exec"),
}
if command != "" {
cmd = append(cmd, "--command="+command)
}
if hook != "" {
cmd = append(cmd, "--hook="+hook)
}
// snap-exec is POSIXly-- options must come before positionals.
cmd = append(cmd, snapApp)
cmd = append(cmd, args...)
return syscallExec(cmd[0], cmd, snapenv.ExecEnv(info))
}
开发者ID:niemeyer,项目名称:snapd,代码行数:25,代码来源:cmd_run.go
示例18: queueFile
func queueFile(src string) error {
// refuse huge files, this is for assertions
fi, err := os.Stat(src)
if err != nil {
return err
}
// 640kb ought be to enough for anyone
if fi.Size() > 640*1024 {
msg := fmt.Errorf("cannot queue %s, file size too big: %v", src, fi.Size())
logger.Noticef("error: %v", msg)
return msg
}
// ensure name is predictable, weak hash is ok
hash, _, err := osutil.FileDigest(src, crypto.SHA3_384)
if err != nil {
return err
}
dst := filepath.Join(dirs.SnapAssertsSpoolDir, fmt.Sprintf("%s.assert", base64.URLEncoding.EncodeToString(hash)))
if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
return err
}
return osutil.CopyFile(src, dst, osutil.CopyFlagOverwrite)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:26,代码来源:cmd_auto_import.go
示例19: doSetupProfiles
func (m *InterfaceManager) doSetupProfiles(task *state.Task, _ *tomb.Tomb) error {
task.State().Lock()
defer task.State().Unlock()
// Get snap.Info from bits handed by the snap manager.
ss, err := snapstate.TaskSnapSetup(task)
if err != nil {
return err
}
snapInfo, err := snap.ReadInfo(ss.Name(), ss.SideInfo)
if err != nil {
return err
}
snap.AddImplicitSlots(snapInfo)
snapName := snapInfo.Name()
// The snap may have been updated so perform the following operation to
// ensure that we are always working on the correct state:
//
// - disconnect all connections to/from the given snap
// - remembering the snaps that were affected by this operation
// - remove the (old) snap from the interfaces repository
// - add the (new) snap to the interfaces repository
// - restore connections based on what is kept in the state
// - if a connection cannot be restored then remove it from the state
// - setup the security of all the affected snaps
affectedSnaps, err := m.repo.DisconnectSnap(snapName)
if err != nil {
return err
}
// XXX: what about snap renames? We should remove the old name (or switch
// to IDs in the interfaces repository)
if err := m.repo.RemoveSnap(snapName); err != nil {
return err
}
if err := m.repo.AddSnap(snapInfo); err != nil {
if _, ok := err.(*interfaces.BadInterfacesError); ok {
logger.Noticef("%s", err)
} else {
return err
}
}
if err := m.reloadConnections(snapName); err != nil {
return err
}
// FIXME: here we should not reconnect auto-connect plug/slot
// pairs that were explicitly disconnected by the user
if err := m.autoConnect(task, snapName, nil); err != nil {
return err
}
if err := setupSnapSecurity(task, snapInfo, ss.DevModeAllowed(), m.repo); err != nil {
return err
}
return m.setupAffectedSnaps(task, snapName, affectedSnaps)
}
开发者ID:niemeyer,项目名称:snapd,代码行数:57,代码来源:handlers.go
示例20: disableRemovedServices
func disableRemovedServices(systemd sysd.Systemd, dir, glob string, content map[string]*osutil.FileState) error {
paths, err := filepath.Glob(filepath.Join(dir, glob))
if err != nil {
return err
}
for _, path := range paths {
service := filepath.Base(path)
if content[service] == nil {
if err := systemd.Disable(service); err != nil {
logger.Noticef("cannot disable service %q: %s", service, err)
}
if err := systemd.Stop(service, 5*time.Second); err != nil {
logger.Noticef("cannot stop service %q: %s", service, err)
}
}
}
return nil
}
开发者ID:pedronis,项目名称:snappy,代码行数:18,代码来源:backend.go
注:本文中的github.com/snapcore/snapd/logger.Noticef函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论