1
0

Moving other source code files into prog package. Renaming processes.json to config.json.

This commit is contained in:
Alexander Andreev 2022-01-02 02:56:46 +04:00
parent 82ecb23a62
commit 0c8dc36697
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F
5 changed files with 11 additions and 10 deletions

View File

@ -22,6 +22,7 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
. "httpprocwatchd/prog"
"log" "log"
"os" "os"
"os/exec" "os/exec"
@ -56,8 +57,8 @@ func main() {
log.SetFlags(0) log.SetFlags(0)
flag.StringVar(&oConfigPath, "config", "processes.json", "path to configuration file") flag.StringVar(&oConfigPath, "config", "config.json", "path to configuration file")
flag.StringVar(&oConfigPath, "c", "processes.json", "path to configuration file (shorthand)") flag.StringVar(&oConfigPath, "c", "config.json", "path to configuration file (shorthand)")
flag.BoolVar(&oShowVersion, "version", false, "show version") flag.BoolVar(&oShowVersion, "version", false, "show version")
flag.BoolVar(&oShowVersion, "v", false, "show version (shorthand)") flag.BoolVar(&oShowVersion, "v", false, "show version (shorthand)")
@ -124,7 +125,7 @@ func main() {
return return
} }
srv := createAndStartHTTPServer(conf) srv := CreateAndStartHTTPServer(conf)
syssignal := make(chan os.Signal, 1) syssignal := make(chan os.Signal, 1)
signal.Notify(syssignal, os.Interrupt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) signal.Notify(syssignal, os.Interrupt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
@ -137,7 +138,7 @@ func main() {
fallthrough fallthrough
case syscall.SIGINT | syscall.SIGTERM: case syscall.SIGINT | syscall.SIGTERM:
log.Println("Shutting down... ") log.Println("Shutting down... ")
shutdownHTTPServer(srv) ShutdownHTTPServer(srv)
log.Println("Server shutted down.") log.Println("Server shutted down.")
os.Exit(0) os.Exit(0)
case syscall.SIGHUP: case syscall.SIGHUP:

View File

@ -17,7 +17,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package main package prog
import ( import (
"encoding/json" "encoding/json"

View File

@ -17,7 +17,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package main package prog
import "errors" import "errors"

View File

@ -17,7 +17,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package main package prog
import ( import (
"encoding/xml" "encoding/xml"

View File

@ -17,7 +17,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package main package prog
import ( import (
"context" "context"
@ -28,7 +28,7 @@ import (
"time" "time"
) )
func createAndStartHTTPServer(conf *Configuration) *http.Server { func CreateAndStartHTTPServer(conf *Configuration) *http.Server {
router := http.NewServeMux() router := http.NewServeMux()
router.HandleFunc("/processes", AreProcessesUp(&conf.Processes)) router.HandleFunc("/processes", AreProcessesUp(&conf.Processes))
@ -49,7 +49,7 @@ func createAndStartHTTPServer(conf *Configuration) *http.Server {
return srv return srv
} }
func shutdownHTTPServer(srv *http.Server) { func ShutdownHTTPServer(srv *http.Server) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() defer cancel()