From d9e03871f3e859e61ab1787a653b2bc37b6c0942 Mon Sep 17 00:00:00 2001 From: Hunter Long Date: Thu, 19 Dec 2019 08:48:59 -0800 Subject: [PATCH] signal graceful method, create service url --- Makefile | 14 ++++++++++--- cmd/main.go | 12 +++++++++++ core/sample.go | 4 ++++ handlers/routes.go | 2 +- source/scss/mobile.scss | 2 +- source/tmpl/form_service.gohtml | 31 ++++++++++++++++----------- source/tmpl/messages.gohtml | 6 +++--- source/tmpl/service_create.gohtml | 9 ++++++++ source/tmpl/services.gohtml | 16 +++++++------- source/tmpl/settings.gohtml | 35 ++++++++++++++----------------- source/tmpl/users.gohtml | 4 ++-- source/wiki.go | 4 ++-- 12 files changed, 87 insertions(+), 52 deletions(-) create mode 100644 source/tmpl/service_create.gohtml diff --git a/Makefile b/Makefile index 5a7a26b1..5dc8564c 100644 --- a/Makefile +++ b/Makefile @@ -73,13 +73,21 @@ run: build # run Statping with Delve for debugging rundlv: - dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./$(BINARY_NAME) + lsof -ti:8080 | xargs kill + DB_CONN=sqlite DB_HOST=localhost DB_DATABASE=sqlite DB_PASS=none DB_USER=none GO_ENV=test \ + dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./statping + +killdlv: + lsof -ti:2345 | xargs kill builddlv: $(GOBUILD) -gcflags "all=-N -l" -o ./$(BINARY_NAME) -v ./cmd watch: - reflex -v -r '\.go' -s -- sh -c 'make builddlv && make rundlv' + find . -print | grep -i '.*\.\(go\|gohtml\)' | justrun -v -c \ + 'go build -v -gcflags "all=-N -l" -o statping ./cmd && make rundlv &' \ + -delay 10s -stdin \ + -i="Makefile,statping,statup.db,statup.db-journal,handlers/graphql/generated.go" # compile assets using SASS and Rice. compiles scss -> css, and run rice embed-go compile: generate @@ -250,7 +258,7 @@ clean: rm -rf dev/test/cypress/videos rm -f coverage.* sass rm -f source/rice-box.go - rm -f *.db-journal + rm -rf **/*.db-journal rm -rf *.snap find . -name "*.out" -type f -delete find . -name "*.cpu" -type f -delete diff --git a/cmd/main.go b/cmd/main.go index b0990e07..1463ed4f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -25,6 +25,8 @@ import ( "github.com/hunterlong/statping/utils" "github.com/joho/godotenv" "os" + "os/signal" + "syscall" ) var ( @@ -61,6 +63,7 @@ func parseFlags() { // main will run the Statping application func main() { var err error + go sigterm() parseFlags() loadDotEnvs() source.Assets() @@ -92,6 +95,15 @@ func main() { mainProcess() } +// sigterm will attempt to close the database connections gracefully +func sigterm() { + sigs := make(chan os.Signal, 1) + signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL) + <-sigs + core.CloseDB() + os.Exit(1) +} + // loadDotEnvs attempts to load database configs from a '.env' file in root directory func loadDotEnvs() error { err := godotenv.Load() diff --git a/core/sample.go b/core/sample.go index 20d3c68f..f53fb386 100644 --- a/core/sample.go +++ b/core/sample.go @@ -44,6 +44,7 @@ func InsertSampleData() error { Order: 1, GroupId: 1, Permalink: types.NewNullString("google"), + VerifySSL: types.NewNullBool(true), CreatedAt: createdOn, }) s2 := ReturnService(&types.Service{ @@ -56,6 +57,7 @@ func InsertSampleData() error { Timeout: 20, Order: 2, Permalink: types.NewNullString("statping_github"), + VerifySSL: types.NewNullBool(true), CreatedAt: createdOn, }) s3 := ReturnService(&types.Service{ @@ -68,6 +70,7 @@ func InsertSampleData() error { Timeout: 30, Order: 3, Public: types.NewNullBool(true), + VerifySSL: types.NewNullBool(true), GroupId: 2, CreatedAt: createdOn, }) @@ -83,6 +86,7 @@ func InsertSampleData() error { Timeout: 30, Order: 4, Public: types.NewNullBool(true), + VerifySSL: types.NewNullBool(true), GroupId: 2, CreatedAt: createdOn, }) diff --git a/handlers/routes.go b/handlers/routes.go index 2c3bce0d..44af5554 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -89,10 +89,10 @@ func Router() *mux.Router { // SERVICE Routes r.Handle("/services", authenticated(servicesHandler, true)).Methods("GET") + r.Handle("/service/create", authenticated(createServiceHandler, true)).Methods("GET") r.Handle("/service/{id}", http.HandlerFunc(servicesViewHandler)).Methods("GET") r.Handle("/service/{id}/edit", authenticated(servicesViewHandler, true)).Methods("GET") r.Handle("/service/{id}/delete_failures", authenticated(servicesDeleteFailuresHandler, true)).Methods("GET") - r.Handle("/service/create", authenticated(createServiceHandler, true)).Methods("GET") r.Handle("/group/{id}", http.HandlerFunc(groupViewHandler)).Methods("GET") diff --git a/source/scss/mobile.scss b/source/scss/mobile.scss index 0ae37874..f5d4cdca 100644 --- a/source/scss/mobile.scss +++ b/source/scss/mobile.scss @@ -48,7 +48,7 @@ .card-body { font-size: 10pt; - padding: 0px 10px; + padding: 10px 10px; } .lg_number { diff --git a/source/tmpl/form_service.gohtml b/source/tmpl/form_service.gohtml index f9ee9376..964b84e2 100644 --- a/source/tmpl/form_service.gohtml +++ b/source/tmpl/form_service.gohtml @@ -7,6 +7,7 @@ {{else}}
{{end}} +

Basic Information

@@ -33,6 +34,21 @@ Statping will attempt to connect to this URL
+
+ +
+ + Attach this service to a group +
+
+ +

Request Details

+
@@ -80,6 +96,9 @@
+ +

Additional Options

+
@@ -138,18 +157,6 @@
-
- -
- - Attach this service to a group -
-
diff --git a/source/tmpl/messages.gohtml b/source/tmpl/messages.gohtml index 5ec025e4..4d19672e 100644 --- a/source/tmpl/messages.gohtml +++ b/source/tmpl/messages.gohtml @@ -4,7 +4,7 @@ {{template "nav"}} {{if .}}
-

Messages

+

Messages

@@ -34,7 +34,7 @@ {{end}} {{if Auth}}
-

Create Message

+

Create Message

{{template "form_message" NewMessage}}
{{end}} @@ -56,4 +56,4 @@ $(document).ready(function() { }); }); -{{end}} \ No newline at end of file +{{end}} diff --git a/source/tmpl/service_create.gohtml b/source/tmpl/service_create.gohtml new file mode 100644 index 00000000..86bb0712 --- /dev/null +++ b/source/tmpl/service_create.gohtml @@ -0,0 +1,9 @@ +{{define "title"}}Statping | Create Service{{end}} +{{define "content"}} +
+{{template "nav"}} +
+ {{template "form_service" NewService}} +
+
+{{end}} diff --git a/source/tmpl/services.gohtml b/source/tmpl/services.gohtml index f97252d4..99ce6b60 100644 --- a/source/tmpl/services.gohtml +++ b/source/tmpl/services.gohtml @@ -5,7 +5,9 @@
{{if ne (len .Services) 0}} -

Services

+

Services + Create +

@@ -21,7 +23,7 @@ @@ -36,14 +38,10 @@
{{.Name}} {{if .Online}}ONLINE{{else}}OFFLINE{{end}} - + {{if .Public.Bool}}PUBLIC{{else}}PRIVATE{{end}} {{if ne .GroupId 0}}{{(Group .GroupId).Name}}{{end}}
{{end}} - {{if Auth}} -

Create Service

- {{template "form_service" NewService}} - {{end}}
-
-

Groups

+
+

Groups

@@ -70,7 +68,7 @@
{{if Auth}} -

Create Group

+

Create Group

{{template "form_group" NewGroup}} {{end}}
diff --git a/source/tmpl/settings.gohtml b/source/tmpl/settings.gohtml index 664789a3..465f9d96 100644 --- a/source/tmpl/settings.gohtml +++ b/source/tmpl/settings.gohtml @@ -6,13 +6,16 @@