2022-09-08 15:39:26 +02:00
|
|
|
package hook
|
|
|
|
|
|
|
|
import (
|
2023-07-10 14:39:48 +02:00
|
|
|
"github.com/kairos-io/kairos-agent/v2/pkg/config"
|
2023-07-24 12:28:59 +02:00
|
|
|
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
|
|
|
|
"github.com/kairos-io/kairos-sdk/utils"
|
|
|
|
"time"
|
2022-09-08 15:39:26 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Lifecycle struct{}
|
|
|
|
|
2024-03-07 15:11:51 +01:00
|
|
|
func (s Lifecycle) Run(c config.Config, spec v1.Spec) error {
|
|
|
|
c.Logger.Logger.Debug().Msg("Running Lifecycle hook")
|
2023-12-05 15:46:11 +01:00
|
|
|
if spec.ShouldReboot() {
|
2023-07-24 12:28:59 +02:00
|
|
|
time.Sleep(5)
|
2022-09-08 15:39:26 +02:00
|
|
|
utils.Reboot()
|
|
|
|
}
|
|
|
|
|
2023-12-05 15:46:11 +01:00
|
|
|
if spec.ShouldShutdown() {
|
2023-07-24 12:28:59 +02:00
|
|
|
time.Sleep(5)
|
2022-09-08 15:39:26 +02:00
|
|
|
utils.PowerOFF()
|
|
|
|
}
|
2024-03-07 15:11:51 +01:00
|
|
|
c.Logger.Logger.Debug().Msg("Finish Lifecycle hook")
|
2022-09-08 15:39:26 +02:00
|
|
|
return nil
|
|
|
|
}
|