Improve starting and stopping

This commit is contained in:
Daniel 2024-11-08 14:39:28 +01:00
parent 34894ea7d6
commit 2d0d711938
4 changed files with 12 additions and 16 deletions

View file

@ -29,6 +29,7 @@ var (
func init() {
// Add Go's default flag set.
// TODO: Move flags throughout Portmaster to here and add their values to the service config.
rootCmd.Flags().AddGoFlagSet(flag.CommandLine)
// Add persisent flags for all commands.

View file

@ -36,10 +36,8 @@ func cmdRun(cmd *cobra.Command, args []string) {
// SETUP
svcCfg.VerifyBinaryUpdates = nil // FIXME
svcCfg.VerifyIntelUpdates = nil // FIXME
// enable SPN client mode
// Enable SPN client mode.
// TODO: Move this to service config.
conf.EnableClient(true)
conf.EnableIntegration(true)
@ -97,17 +95,13 @@ func cmdRun(cmd *cobra.Command, args []string) {
// Wait for shutdown to be finished.
select {
case <-instance.ShutdownComplete():
case <-time.After(3 * time.Minute):
printStackTo(os.Stderr, "PRINTING STACK - TAKING TOO LONG FOR SHUTDOWN")
}
// Stop logging.
log.Shutdown()
// Print stack on shutdown, if enabled.
if printStackOnExit {
printStackTo(os.Stdout, "PRINTING STACK ON EXIT")
}
case <-time.After(3 * time.Minute):
printStackTo(os.Stderr, "PRINTING STACK - TAKING TOO LONG FOR SHUTDOWN")
}
// Check if restart was triggered and send start service command if true.
if instance.ShouldRestart && service.IsService() {
@ -116,6 +110,9 @@ func cmdRun(cmd *cobra.Command, args []string) {
}
}
// Stop logging.
log.Shutdown()
// Give a small amount of time for everything to settle:
// - All logs written.
// - Restart command started, if needed.

View file

@ -52,6 +52,8 @@ func (s *LinuxSystemService) Run() {
wait:
for {
select {
case <-s.instance.ShuttingDown():
break wait
case sig := <-signalCh:
// Only print and continue to wait if SIGUSR1
if sig == syscall.SIGUSR1 {
@ -64,8 +66,6 @@ wait:
s.instance.Shutdown()
break wait
}
case <-s.instance.ShuttingDown():
break wait
}
}

View file

@ -24,8 +24,6 @@ func init() {
func update(cmd *cobra.Command, args []string) error {
// Finalize config.
svcCfg.VerifyBinaryUpdates = nil // FIXME
svcCfg.VerifyIntelUpdates = nil // FIXME
err := svcCfg.Init()
if err != nil {
return fmt.Errorf("internal configuration error: %w", err)