<commit_before>package main

import (
	"flag"
	"fmt"
	"os"
	"os/signal"
	"sync"
	"syscall"

	"health_monitor/api"
	"health_monitor/disk"
	"health_monitor/live"
	"health_monitor/setup"
	"health_monitor/utils"
	"health_monitor/webui"
)

// Flags holds the health_monitor command line arguments
type Flags struct {
	NoWebUI *bool
	NoCLI   *bool
	Quite   *bool
}

func main() {
	var (
		wg    sync.WaitGroup
		flags Flags
		chans [5]chan bool //Number of modules
	)

	for i := range chans {
		chans[i] = make(chan bool)
	}

	flags.NoWebUI = flag.Bool("nowebui", false, "Disables the web ui")
	flags.NoCLI = flag.Bool("nocli", false, "Disables cli")
	flags.Quite = flag.Bool("quite", false, "Disables all notifications except email")

	flag.Parse()

	go webui.RunServer(setup.ConfigVars.Port)
	if (*flags.NoCLI == true) || (*flags.NoWebUI == false) {
		fmt.Printf("[*] Server is up and running at 127.0.0.1:%s\n", setup.ConfigVars.Port)
	}

	exitChan := make(chan os.Signal, 1)
	signal.Notify(exitChan, syscall.SIGINT, syscall.SIGTERM)
	wg.Add(1)
	go tearDown(exitChan, &wg)

	runModules(chans, &wg)
	controlModule(chans, &wg)
	setup.SaveStatus()
}

func controlModule(chans [5]chan bool, wg *sync.WaitGroup) {
	api.ControlChan = make(chan utils.Status)
	for {
		data := <-api.ControlChan
		switch data.Module {
		case "live":
			if data.Run && !setup.ModulesStatus.Live {
				setup.ModulesStatus.Live = true
				wg.Add(1)
				go live.Live(chans[0], wg)
			} else if setup.ModulesStatus.Live {
				setup.ModulesStatus.Live = false
				chans[0] <- true
			}
		case "target":
			break
		case "disk":
			if data.Run && !setup.ModulesStatus.Disk {
				setup.ModulesStatus.Disk = true
				wg.Add(1)
				go disk.Disk(chans[2], wg)
			} else if setup.ModulesStatus.Disk {
				setup.ModulesStatus.Disk = false
				chans[2] <- true
			}
		}
	}
}

func runModules(chans [5]chan bool, wg *sync.WaitGroup) {
	if setup.ModulesStatus.Live {
		wg.Add(1)
		go live.Live(chans[0], wg)
	}
	if setup.ModulesStatus.Target {

	}
	if setup.ModulesStatus.Disk {
		wg.Add(1)
		go disk.Disk(chans[2], wg)
	}
}

func tearDown(exitChan chan os.Signal, wg *sync.WaitGroup) {
	<-exitChan
	fmt.Println("in teardown")
	setup.MainLogFile.Close()
	setup.DBLogFile.Close()
	setup.Database.Close()
	setup.SaveStatus()

	var module string
	for module, _ = range api.ConfFunc {
		api.ChangeModuleStatus(module, false)
	}
	wg.Done()
	wg.Wait()
	os.Exit(0)
}<commit_msg>Added logs in main function<commit_after>package main

import (
	"flag"
	"fmt"
	"os"
	"os/signal"
	"sync"
	"syscall"

	"health_monitor/api"
	"health_monitor/disk"
	"health_monitor/live"
	"health_monitor/setup"
	"health_monitor/utils"
	"health_monitor/webui"
)

// Flags holds the health_monitor command line arguments
type Flags struct {
	NoWebUI *bool
	NoCLI   *bool
	Quite   *bool
}

func main() {
	var (
		wg    sync.WaitGroup
		flags Flags
		chans [5]chan bool //Number of modules
	)

	for i := range chans {
		chans[i] = make(chan bool)
	}

	flags.NoWebUI = flag.Bool("nowebui", false, "Disables the web ui")
	flags.NoCLI = flag.Bool("nocli", false, "Disables cli")
	flags.Quite = flag.Bool("quite", false, "Disables all notifications except email")

	flag.Parse()

	go webui.RunServer(setup.ConfigVars.Port)
	if (*flags.NoCLI == true) || (*flags.NoWebUI == false) {
		fmt.Printf("[*] Server is up and running at http://127.0.0.1:%s\n", setup.ConfigVars.Port)
	}

	exitChan := make(chan os.Signal, 1)
	signal.Notify(exitChan, syscall.SIGINT, syscall.SIGTERM)
	wg.Add(1)
	go tearDown(exitChan, &wg)

	utils.ModuleLogs(setup.MainLogFile, "Running modules from last saved profile")
	runModules(chans, &wg)
	controlModule(chans, &wg)
	setup.SaveStatus()
}

func controlModule(chans [5]chan bool, wg *sync.WaitGroup) {
	api.ControlChan = make(chan utils.Status)
	for {
		data := <-api.ControlChan
		switch data.Module {
		case "live":
			if data.Run && !setup.ModulesStatus.Live {
				setup.ModulesStatus.Live = true
				wg.Add(1)
				utils.ModuleLogs(setup.MainLogFile, "Started live module")
				go live.Live(chans[0], wg)
			} else if setup.ModulesStatus.Live {
				setup.ModulesStatus.Live = false
				utils.ModuleLogs(setup.MainLogFile, "Stopped live module")
				chans[0] <- true
			}
		case "target":
			break
		case "disk":
			if data.Run && !setup.ModulesStatus.Disk {
				setup.ModulesStatus.Disk = true
				wg.Add(1)
				utils.ModuleLogs(setup.MainLogFile, "Started disk module")
				go disk.Disk(chans[2], wg)
			} else if setup.ModulesStatus.Disk {
				setup.ModulesStatus.Disk = false
				utils.ModuleLogs(setup.MainLogFile, "Stopped disk module")
				chans[2] <- true
			}
		}
	}
}

func runModules(chans [5]chan bool, wg *sync.WaitGroup) {
	if setup.ModulesStatus.Live {
		wg.Add(1)
		utils.ModuleLogs(setup.MainLogFile, "Started live module")
		go live.Live(chans[0], wg)
	}
	if setup.ModulesStatus.Target {
		utils.ModuleLogs(setup.MainLogFile, "Started target module")
	}
	if setup.ModulesStatus.Disk {
		wg.Add(1)
		utils.ModuleLogs(setup.MainLogFile, "Started disk module")
		go disk.Disk(chans[2], wg)
	}
}

func tearDown(exitChan chan os.Signal, wg *sync.WaitGroup) {
	<-exitChan
	utils.ModuleLogs(setup.MainLogFile, "Shutdown signal received.")
	setup.Database.Close()
	setup.SaveStatus()
	utils.ModuleLogs(setup.MainLogFile, "Saved all config data. Stopping running modules")

	var module string
	for module, _ = range api.ConfFunc {
		api.ChangeModuleStatus(module, false)
	}

	setup.MainLogFile.Close()
	setup.DBLogFile.Close()
	wg.Done()
	wg.Wait()
	os.Exit(0)
}
{'fraction_non_alphanumeric': 0.13959390862944163, 'fraction_numerical': 0.007976794778825236, 'mean_word_length': 3.8183406113537117, 'pattern_counts': {'":': 6, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1295857', 'n_tokens_mistral': 2297, 'n_tokens_neox': 2107, 'n_words': 453}