[main.go] listWatchedProcesses -> print... . Moving it and version to bottom.
Use os.Exit(0) instead of just return from main. StoreConfiguration moved out Add/RemoveProcess methods.
This commit is contained in:
parent
316c932ac2
commit
7c72851554
52
main.go
52
main.go
@ -9,22 +9,6 @@ import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// listWatchedProcesses prints a list of processes being watched.
|
||||
func listWatchedProcesses(processes *[]string) {
|
||||
for _, v := range *processes {
|
||||
fmt.Printf("%s, ", v)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
// version prints information about program.
|
||||
func version() {
|
||||
fmt.Println("httpprocwatchd ver. 1.3.2")
|
||||
fmt.Println("Copyright (c) 2021,2022 Alexander \"Arav\" Andreev <me@arav.top>")
|
||||
fmt.Println("This program is licensed under terms of MIT+NIGGER license a copy")
|
||||
fmt.Println("of wich is located in /usr/share/licenses/httpprocwatchd/LICENSE.")
|
||||
}
|
||||
|
||||
func main() {
|
||||
var oConfigPath string
|
||||
var oShowVersion bool
|
||||
@ -54,7 +38,7 @@ func main() {
|
||||
|
||||
if oShowVersion {
|
||||
version()
|
||||
return
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
conf, err := LoadConfiguration(oConfigPath)
|
||||
@ -63,27 +47,32 @@ func main() {
|
||||
}
|
||||
|
||||
if oListProcesses {
|
||||
listWatchedProcesses(&conf.Processes)
|
||||
return
|
||||
printWatchedProcesses(&conf.Processes)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if oAddProcess != "" {
|
||||
err := conf.AddProcessToList(oAddProcess, oConfigPath)
|
||||
err := conf.AddProcess(oAddProcess, oConfigPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot add process: %s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
if oRemoveProcess != "" {
|
||||
err := conf.RemoveProcessFromList(oRemoveProcess, oConfigPath)
|
||||
err := conf.RemoveProcess(oRemoveProcess, oConfigPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot remove process: %s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
// If we modified a list then let's look for a running program and
|
||||
// send SIGHUP for it to reload a list.
|
||||
// send SIGHUP to it to reload a list. Here we assume that there
|
||||
// is only one process running, so we just filter our PID.
|
||||
if oAddProcess != "" || oRemoveProcess != "" {
|
||||
if err := conf.StoreConfiguration(oConfigPath); err != nil {
|
||||
log.Fatalf("Cannot write configuration. Error: %s\n", err)
|
||||
}
|
||||
|
||||
pids, _ := GetProcessPIDs("httpprocwatchd")
|
||||
if pids != nil && len(pids) > 1 {
|
||||
var trgt_pid int
|
||||
@ -97,7 +86,8 @@ func main() {
|
||||
proc.Signal(syscall.SIGHUP)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
srv := CreateAndStartHTTPServer(conf)
|
||||
@ -126,3 +116,19 @@ func main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// printWatchedProcesses prints a list of processes being watched.
|
||||
func printWatchedProcesses(processes *[]string) {
|
||||
for _, v := range *processes {
|
||||
fmt.Printf("%s, ", v)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
// version prints information about program.
|
||||
func version() {
|
||||
fmt.Println("httpprocwatchd ver. 1.3.2")
|
||||
fmt.Println("Copyright (c) 2021,2022 Alexander \"Arav\" Andreev <me@arav.top>")
|
||||
fmt.Println("This program is licensed under terms of MIT+NIGGER license a copy")
|
||||
fmt.Println("of wich is located in /usr/share/licenses/httpprocwatchd/LICENSE.")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user