mirror of
https://github.com/safing/portmaster
synced 2025-09-02 10:39:22 +00:00
Improve starting and stopping
This commit is contained in:
parent
34894ea7d6
commit
2d0d711938
4 changed files with 12 additions and 16 deletions
|
@ -29,6 +29,7 @@ var (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// Add Go's default flag set.
|
// 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)
|
rootCmd.Flags().AddGoFlagSet(flag.CommandLine)
|
||||||
|
|
||||||
// Add persisent flags for all commands.
|
// Add persisent flags for all commands.
|
||||||
|
|
|
@ -36,10 +36,8 @@ func cmdRun(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
// SETUP
|
// SETUP
|
||||||
|
|
||||||
svcCfg.VerifyBinaryUpdates = nil // FIXME
|
// Enable SPN client mode.
|
||||||
svcCfg.VerifyIntelUpdates = nil // FIXME
|
// TODO: Move this to service config.
|
||||||
|
|
||||||
// enable SPN client mode
|
|
||||||
conf.EnableClient(true)
|
conf.EnableClient(true)
|
||||||
conf.EnableIntegration(true)
|
conf.EnableIntegration(true)
|
||||||
|
|
||||||
|
@ -97,17 +95,13 @@ func cmdRun(cmd *cobra.Command, args []string) {
|
||||||
// Wait for shutdown to be finished.
|
// Wait for shutdown to be finished.
|
||||||
select {
|
select {
|
||||||
case <-instance.ShutdownComplete():
|
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.
|
// Print stack on shutdown, if enabled.
|
||||||
if printStackOnExit {
|
if printStackOnExit {
|
||||||
printStackTo(os.Stdout, "PRINTING STACK ON EXIT")
|
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.
|
// Check if restart was triggered and send start service command if true.
|
||||||
if instance.ShouldRestart && service.IsService() {
|
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:
|
// Give a small amount of time for everything to settle:
|
||||||
// - All logs written.
|
// - All logs written.
|
||||||
// - Restart command started, if needed.
|
// - Restart command started, if needed.
|
||||||
|
|
|
@ -52,6 +52,8 @@ func (s *LinuxSystemService) Run() {
|
||||||
wait:
|
wait:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
case <-s.instance.ShuttingDown():
|
||||||
|
break wait
|
||||||
case sig := <-signalCh:
|
case sig := <-signalCh:
|
||||||
// Only print and continue to wait if SIGUSR1
|
// Only print and continue to wait if SIGUSR1
|
||||||
if sig == syscall.SIGUSR1 {
|
if sig == syscall.SIGUSR1 {
|
||||||
|
@ -64,8 +66,6 @@ wait:
|
||||||
s.instance.Shutdown()
|
s.instance.Shutdown()
|
||||||
break wait
|
break wait
|
||||||
}
|
}
|
||||||
case <-s.instance.ShuttingDown():
|
|
||||||
break wait
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,6 @@ func init() {
|
||||||
|
|
||||||
func update(cmd *cobra.Command, args []string) error {
|
func update(cmd *cobra.Command, args []string) error {
|
||||||
// Finalize config.
|
// Finalize config.
|
||||||
svcCfg.VerifyBinaryUpdates = nil // FIXME
|
|
||||||
svcCfg.VerifyIntelUpdates = nil // FIXME
|
|
||||||
err := svcCfg.Init()
|
err := svcCfg.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("internal configuration error: %w", err)
|
return fmt.Errorf("internal configuration error: %w", err)
|
||||||
|
|
Loading…
Add table
Reference in a new issue