本文整理汇总了Golang中github.com/snapcore/snapd/logger.Noticef函数的典型用法代码示例。如果您正苦于以下问题:Golang Noticef函数的具体用法?Golang Noticef怎么用?Golang Noticef使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Noticef函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
}
}
示例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
}
示例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
}
示例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()
}
示例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()
}