Welcome to mirror list, hosted at ThFree Co, Russian Federation.

signal_unix.go « grumble « cmd - github.com/mumble-voip/grumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 02db23b008fbfcd636e37c14e74600254f14ef9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) 2011 The Grumble Authors
// The use of this source code is goverened by a BSD-style
// license that can be found in the LICENSE-file.

// +build darwin freebsd linux netbsd openbsd

package main

import (
	"fmt"
	"log"
	"os"
	"os/signal"
	"syscall"

	"mumble.info/grumble/pkg/logtarget"
)

func SignalHandler() {
	sigchan := make(chan os.Signal, 10)
	signal.Notify(sigchan, syscall.SIGUSR2, syscall.SIGTERM, syscall.SIGINT)
	for sig := range sigchan {
		if sig == syscall.SIGUSR2 {
			err := logtarget.Default.Rotate()
			if err != nil {
				fmt.Fprintf(os.Stderr, "unable to rotate log file: %v", err)
			}
			continue
		}
		if sig == syscall.SIGINT || sig == syscall.SIGTERM {
			for _, server := range servers {
				log.Printf("Stopping server %v", server.Id)
				err := server.Stop()
				if err != nil {
					log.Printf("Server err %v", err)
				}
			}
			log.Print("All servers stopped. Exiting.")
			os.Exit(0)
		}
	}
}