mirror of
https://github.com/mudler/luet.git
synced 2025-08-13 13:06:37 +00:00
Lock only on commands that aren't meant to run in parallel
This commit is contained in:
parent
7de5f6656d
commit
d5166c55ab
22
cmd/root.go
22
cmd/root.go
@ -35,6 +35,7 @@ import (
|
|||||||
|
|
||||||
var cfgFile string
|
var cfgFile string
|
||||||
var Verbose bool
|
var Verbose bool
|
||||||
|
var LockedCommands = []string{"install", "uninstall", "upgrade"}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LuetCLIVersion = "0.8-dev"
|
LuetCLIVersion = "0.8-dev"
|
||||||
@ -91,16 +92,21 @@ func LoadConfig(c *config.LuetConfig) error {
|
|||||||
// Execute adds all child commands to the root command sets flags appropriately.
|
// Execute adds all child commands to the root command sets flags appropriately.
|
||||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||||
func Execute() {
|
func Execute() {
|
||||||
// XXX: This is mostly from scratch images.
|
|
||||||
if os.Getenv("LUET_NOLOCK") != "true" {
|
if os.Getenv("LUET_NOLOCK") != "true" {
|
||||||
s := single.New("luet")
|
for _, lockedCmd := range LockedCommands {
|
||||||
if err := s.CheckLock(); err != nil && err == single.ErrAlreadyRunning {
|
if os.Args[1] == lockedCmd {
|
||||||
Fatal("another instance of the app is already running, exiting")
|
s := single.New("luet")
|
||||||
} else if err != nil {
|
if err := s.CheckLock(); err != nil && err == single.ErrAlreadyRunning {
|
||||||
// Another error occurred, might be worth handling it as well
|
Fatal("another instance of the app is already running, exiting")
|
||||||
Fatal("failed to acquire exclusive app lock:", err.Error())
|
} else if err != nil {
|
||||||
|
// Another error occurred, might be worth handling it as well
|
||||||
|
Fatal("failed to acquire exclusive app lock:", err.Error())
|
||||||
|
}
|
||||||
|
defer s.TryUnlock()
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
defer s.TryUnlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := RootCmd.Execute(); err != nil {
|
if err := RootCmd.Execute(); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user