Improve starting and stopping
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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,18 +95,14 @@ func cmdRun(cmd *cobra.Command, args []string) {
|
||||
// Wait for shutdown to be finished.
|
||||
select {
|
||||
case <-instance.ShutdownComplete():
|
||||
// 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")
|
||||
}
|
||||
|
||||
// Stop logging.
|
||||
log.Shutdown()
|
||||
|
||||
// Print stack on shutdown, if enabled.
|
||||
if printStackOnExit {
|
||||
printStackTo(os.Stdout, "PRINTING STACK ON EXIT")
|
||||
}
|
||||
|
||||
// Check if restart was triggered and send start service command if true.
|
||||
if instance.ShouldRestart && service.IsService() {
|
||||
if err := service.RestartService(); err != nil {
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user