mirror of
https://github.com/restic/rest-server.git
synced 2025-12-07 09:36:13 -08:00
Merge pull request #135 from MichaelEischer/cpu-profile-shutdown
Properly close CPU profile on SIGINT
This commit is contained in:
@@ -6,9 +6,11 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"syscall"
|
||||
|
||||
restserver "github.com/restic/rest-server"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -89,7 +91,18 @@ func runRoot(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
log.Println("CPU profiling enabled")
|
||||
defer pprof.StopCPUProfile()
|
||||
|
||||
// clean profiling shutdown on sigint
|
||||
sigintCh := make(chan os.Signal, 1)
|
||||
go func() {
|
||||
for range sigintCh {
|
||||
pprof.StopCPUProfile()
|
||||
f.Close()
|
||||
log.Println("Stopped CPU profiling")
|
||||
os.Exit(130)
|
||||
}
|
||||
}()
|
||||
signal.Notify(sigintCh, syscall.SIGINT)
|
||||
}
|
||||
|
||||
if server.NoAuth {
|
||||
|
||||
Reference in New Issue
Block a user