<commit_before>package main

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

	"github.com/squaremo/ambergreen/balancer"
	"github.com/squaremo/ambergreen/balancer/fatal"
)

func iptables(args []string) ([]byte, error) {
	return exec.Command("iptables", args...).CombinedOutput()
}

func main() {
	exitCode := 0
	defer os.Exit(exitCode)

	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

	fatalSink := fatal.New()
	i := balancer.Start(os.Args, fatalSink, iptables)
	defer i.Stop()

	select {
	case <-sigs:
	case err := <-fatalSink:
		fmt.Fprintln(os.Stderr, err)
		exitCode = 1
	}
}<commit_msg>Improve signal handling in balancer<commit_after>package main

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

	"github.com/squaremo/ambergreen/balancer"
	"github.com/squaremo/ambergreen/balancer/fatal"
)

func iptables(args []string) ([]byte, error) {
	return exec.Command("iptables", args...).CombinedOutput()
}

func main() {
	// Catch some signals for whcih we want to clean up on exit
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

	fatalSink := fatal.New()
	i := balancer.Start(os.Args, fatalSink, iptables)

	exitCode := 0
	var exitSignal os.Signal

	select {
	case err := <-fatalSink:
		fmt.Fprintln(os.Stderr, err)
		exitCode = 1
	case exitSignal = <-sigs:
		exitCode = 2
	}

	i.Stop()

	if sig, ok := exitSignal.(syscall.Signal); ok {
		// Now we have cleaned up, re-kill the process with
		// the signal in order to produce a signal exit
		// status:
		signal.Reset(sig)
		syscall.Kill(syscall.Getpid(), sig)
	}

	os.Exit(exitCode)
}
{'fraction_non_alphanumeric': 0.15168195718654434, 'fraction_numerical': 0.004281345565749235, 'mean_word_length': 3.9129129129129128, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1437458', 'n_tokens_mistral': 680, 'n_tokens_neox': 626, 'n_words': 145}