github.com/david-imola/snapd@v0.0.0-20210611180407-2de8ddeece6d/overlord/patch/patch3.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2016 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package patch 21 22 import ( 23 "github.com/snapcore/snapd/i18n" 24 "github.com/snapcore/snapd/overlord/state" 25 ) 26 27 func init() { 28 patches[3] = []PatchFunc{patch3} 29 } 30 31 // patch3: 32 // - migrates pending tasks and add {start,stop}-snap-services tasks 33 func patch3(s *state.State) error { 34 35 // migrate all pending tasks and insert "{start,stop}-snap-server" 36 for _, t := range s.Tasks() { 37 if t.Status().Ready() { 38 continue 39 } 40 41 if t.Kind() == "link-snap" { 42 startSnapServices := s.NewTask("start-snap-services", i18n.G("Start snap services")) 43 startSnapServices.Set("snap-setup-task", t.ID()) 44 startSnapServices.WaitFor(t) 45 46 chg := t.Change() 47 chg.AddTask(startSnapServices) 48 } 49 50 if t.Kind() == "unlink-snap" || t.Kind() == "unlink-current-snap" { 51 stopSnapServices := s.NewTask("stop-snap-services", i18n.G("Stop snap services")) 52 stopSnapServices.Set("snap-setup-task", t.ID()) 53 t.WaitFor(stopSnapServices) 54 55 chg := t.Change() 56 chg.AddTask(stopSnapServices) 57 } 58 } 59 60 return nil 61 }