Skip to content

Commit

Permalink
signal graceful method, create service url
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterlong committed Dec 19, 2019
1 parent 05ff5c5 commit d9e0387
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 52 deletions.
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/hunterlong/statping/utils"
"github.com/joho/godotenv"
"os"
"os/signal"
"syscall"
)

var (
Expand Down Expand Up @@ -61,6 +63,7 @@ func parseFlags() {
// main will run the Statping application
func main() {
var err error
go sigterm()
parseFlags()
loadDotEnvs()
source.Assets()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions core/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -68,6 +70,7 @@ func InsertSampleData() error {
Timeout: 30,
Order: 3,
Public: types.NewNullBool(true),
VerifySSL: types.NewNullBool(true),
GroupId: 2,
CreatedAt: createdOn,
})
Expand All @@ -83,6 +86,7 @@ func InsertSampleData() error {
Timeout: 30,
Order: 4,
Public: types.NewNullBool(true),
VerifySSL: types.NewNullBool(true),
GroupId: 2,
CreatedAt: createdOn,
})
Expand Down
2 changes: 1 addition & 1 deletion handlers/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion source/scss/mobile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

.card-body {
font-size: 10pt;
padding: 0px 10px;
padding: 10px 10px;
}

.lg_number {
Expand Down
31 changes: 19 additions & 12 deletions source/tmpl/form_service.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{{else}}
<form class="ajax_form" action="/api/services" data-redirect="/services" method="POST">
{{end}}
<h4 class="mb-5 text-muted">Basic Information</h4>
<div class="form-group row">
<label for="service_name" class="col-sm-4 col-form-label">Service Name</label>
<div class="col-sm-8">
Expand All @@ -33,6 +34,21 @@
<small class="form-text text-muted">Statping will attempt to connect to this URL</small>
</div>
</div>
<div class="form-group row">
<label for="service_type" class="col-sm-4 col-form-label">Group</label>
<div class="col-sm-8">
<select name="group_id" class="form-control" id="group_id">
<option value="0" {{if eq $s.GroupId 0}}selected{{end}}>None</option>
{{range Groups false}}
<option value="{{.Id}}" {{if eq $s.GroupId .Id}}selected{{end}}>{{.Name}}</option>
{{end}}
</select>
<small class="form-text text-muted">Attach this service to a group</small>
</div>
</div>

<h4 class="mt-5 mb-5 text-muted">Request Details</h4>

<div class="form-group row{{if (eq .Type "tcp") or (eq .Type "udp")}} d-none{{end}}">
<label for="service_check_type" class="col-sm-4 col-form-label">Service Check Type</label>
<div class="col-sm-8">
Expand Down Expand Up @@ -80,6 +96,9 @@
<input type="number" name="port" class="form-control" value="{{if ne .Port 0}}{{.Port}}{{end}}" id="service_port" placeholder="8080">
</div>
</div>

<h4 class="mt-5 mb-5 text-muted">Additional Options</h4>

<div class="form-group row">
<label for="service_interval" class="col-sm-4 col-form-label">Check Interval (Seconds)</label>
<div class="col-sm-8">
Expand Down Expand Up @@ -138,18 +157,6 @@
</span>
</div>
</div>
<div class="form-group row">
<label for="service_type" class="col-sm-4 col-form-label">Group</label>
<div class="col-sm-8">
<select name="group_id" class="form-control" id="group_id">
<option value="0" {{if eq $s.GroupId 0}}selected{{end}}>None</option>
{{range Groups false}}
<option value="{{.Id}}" {{if eq $s.GroupId .Id}}selected{{end}}>{{.Name}}</option>
{{end}}
</select>
<small class="form-text text-muted">Attach this service to a group</small>
</div>
</div>
<div class="form-group row">
<div class="{{if ne .Id 0}}col-6{{else}}col-12{{end}}">
<button type="submit" class="btn btn-success btn-block">{{if ne .Id 0}}Update Service{{else}}Create Service{{end}}</button>
Expand Down
6 changes: 3 additions & 3 deletions source/tmpl/messages.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{template "nav"}}
{{if .}}
<div class="col-12">
<h3>Messages</h3>
<h1 class="text-black-50">Messages</h1>
<table class="table table-striped">
<thead>
<tr>
Expand Down Expand Up @@ -34,7 +34,7 @@
{{end}}
{{if Auth}}
<div class="col-12">
<h3>Create Message</h3>
<h1 class="text-black-50 mt-5">Create Message</h1>
{{template "form_message" NewMessage}}
</div>
{{end}}
Expand All @@ -56,4 +56,4 @@ $(document).ready(function() {
});
});
</script>
{{end}}
{{end}}
9 changes: 9 additions & 0 deletions source/tmpl/service_create.gohtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{define "title"}}Statping | Create Service{{end}}
{{define "content"}}
<div class="container col-md-7 col-sm-12 mt-md-5 bg-light">
{{template "nav"}}
<div class="col-12">
{{template "form_service" NewService}}
</div>
</div>
{{end}}
16 changes: 7 additions & 9 deletions source/tmpl/services.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

<div class="col-12">
{{if ne (len .Services) 0}}
<h3>Services</h3>
<h1 class="text-black-50">Services <a href="/service/create" class="btn btn-outline-success mt-1 float-right">
<i class="fas fa-plus"></i> Create</a>
</h1>
<table class="table">
<thead>
<tr>
Expand All @@ -21,7 +23,7 @@
<tr id="service_{{.Id}}" data-id="{{.Id}}">
<td><span class="drag_icon d-none d-md-inline"><i class="fas fa-bars"></i></span> {{.Name}}</td>
<td class="d-none d-md-table-cell">{{if .Online}}<span class="badge badge-success">ONLINE</span>{{else}}<span class="badge badge-danger">OFFLINE</span>{{end}}
<i class="toggle-service fas {{if .IsRunning}}fa-toggle-on text-success{{else}}fa-toggle-off text-muted{{end}}" data-online="{{if .IsRunning}}true{{else}}false{{end}}" data-id="{{.Id}}"></i>
<i class="toggle-service fas {{if .IsRunning}}fa-toggle-on{{else}}fa-toggle-off{{end}} {{if .Online}}text-success{{else}}text-danger{{end}}" data-online="{{if .IsRunning}}true{{else}}false{{end}}" data-id="{{.Id}}"></i>
</td>
<td class="d-none d-md-table-cell">{{if .Public.Bool}}<span class="badge badge-primary">PUBLIC</span>{{else}}<span class="badge badge-secondary">PRIVATE</span>{{end}}</td>
<td class="d-none d-md-table-cell">{{if ne .GroupId 0}}<span class="badge badge-secondary">{{(Group .GroupId).Name}}</span>{{end}}</td>
Expand All @@ -36,14 +38,10 @@
</tbody>
</table>
{{end}}
{{if Auth}}
<h3>Create Service</h3>
{{template "form_service" NewService}}
{{end}}
</div>

<div class="col-12 mt-3">
<h3>Groups</h3>
<div class="col-12 mt-5">
<h1 class="text-muted">Groups</h1>
<table class="table">
<thead>
<tr>
Expand All @@ -70,7 +68,7 @@
</tbody>
</table>
{{if Auth}}
<h3>Create Group</h3>
<h1 class="text-muted mt-5">Create Group</h1>
{{template "form_group" NewGroup}}
{{end}}
</div>
Expand Down
35 changes: 16 additions & 19 deletions source/tmpl/settings.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
<div class="row">
<div class="col-md-3 col-sm-12 mb-4 mb-md-0">
<div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
<h6 class="text-muted">Main Settings</h6>
<a class="nav-link active" id="v-pills-home-tab" data-toggle="pill" href="#v-pills-home" role="tab" aria-controls="v-pills-home" aria-selected="true"><i class="fa fa-cogs"></i> Settings</a>
<a class="nav-link" id="v-pills-notifications-tab" data-toggle="pill" href="#v-pills-notifications" role="tab" aria-controls="v-pills-notifications" aria-selected="true"><i class="fa fa-cogs"></i> Notifications</a>
<h6>Notifiers</h6>
<a class="nav-link" id="v-pills-notifications-tab" data-toggle="pill" href="#v-pills-notifications" role="tab" aria-controls="v-pills-notifications" aria-selected="true"><i class="fa fa-bell"></i> Notifications</a>
<a class="nav-link" id="v-pills-style-tab" data-toggle="pill" href="#v-pills-style" role="tab" aria-controls="v-pills-style" aria-selected="false"><i class="fa fa-image"></i> Theme Editor</a>
<a class="nav-link" id="v-pills-cache-tab" data-toggle="pill" href="#v-pills-cache" role="tab" aria-controls="v-pills-cache" aria-selected="false"><i class="fa fa-paperclip"></i> Cache</a>
<h6 class="mt-4 text-muted">Notifiers</h6>

{{ range .Notifications }}
<a class="nav-link text-capitalize" id="v-pills-{{underscore .Select.Method}}-tab" data-toggle="pill" href="#v-pills-{{underscore .Select.Method}}" role="tab" aria-controls="v-pills-{{underscore .Select.Method}}" aria-selected="false"><i class="{{.Select.Icon}}"></i> {{.Select.Method}}<span class="badge badge-success float-right">4</span></a>
<a class="nav-link text-capitalize" id="v-pills-{{underscore .Select.Method}}-tab" data-toggle="pill" href="#v-pills-{{underscore .Select.Method}}" role="tab" aria-controls="v-pills-{{underscore .Select.Method}}" aria-selected="false"><i class="{{.Select.Icon}}"></i> {{.Select.Method}}
{{if .Select.Enabled.Bool}}<span class="badge badge-light float-right mt-1"><div class="fas fa-check text-success"></div></span>{{end}}</a>
{{ end }}
<a class="nav-link d-none" id="v-pills-backups-tab" data-toggle="pill" href="#v-pills-backups" role="tab" aria-controls="v-pills-backups" aria-selected="false">Backups</a>
{{ range .Plugins }}
Expand All @@ -26,8 +29,6 @@
{{end}}
<div class="tab-content" id="v-pills-tabContent">
<div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">
<h3>Settings</h3>

<form method="POST" action="/settings">
<div class="form-group">
<label for="project">Project Name</label>
Expand Down Expand Up @@ -125,7 +126,7 @@

</form>

<h3 class="mt-4">Bulk Import Services</h3>
<h2 class="mt-5">Bulk Import Services</h2>
You can import multiple services based on a CSV file with the format shown on the <a href="https://github.com/hunterlong/statping/wiki/Bulk-Import-Services" target="_blank">Bulk Import Wiki</a>.

<div class="card mt-2">
Expand All @@ -141,22 +142,18 @@
</div>
</div>


<h3 class="mt-4">Additional Settings</h3>

<div class="row">
<div class="col-12">
{{if .Domain}}
<div class="row align-content-center">
<img class="rounded text-center" width="300" height="300" src="https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl={{ QrAuth }}">
<h2 class="mt-5">Additional Settings</h2>
<div class="row">
<div class="col-12">
<div class="row align-content-center">
<img class="rounded text-center" width="300" height="300" src="https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl={{ QrAuth }}">
</div>
<a class="btn btn-sm btn-primary" href={{safeURL QrAuth}}>Open in Statping App</a>
<a href="/settings/export" class="btn btn-sm btn-secondary">Export Settings</a>
</div>
</div>

<a class="btn btn-sm btn-primary" href={{safeURL QrAuth}}>Open in Statping App</a>
<a href="/settings/export" class="btn btn-sm btn-secondary">Export Settings</a>
{{end}}

</div>
</div>
</div>

<div class="tab-pane" id="v-pills-notifications" role="tabpanel" aria-labelledby="v-pills-notifications-tab">
Expand Down
4 changes: 2 additions & 2 deletions source/tmpl/users.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="container col-md-7 col-sm-12 mt-md-5 bg-light">
{{template "nav"}}
<div class="col-12">
<h3>Users</h3>
<h1 class="text-black-50">Users</h1>
<table class="table table-striped">
<thead>
<tr>
Expand All @@ -26,7 +26,7 @@
</tbody>
</table>
{{if Auth}}
<h3>Create User</h3>
<h1 class="text-black-50 mt-5">Create User</h1>
{{template "form_user" NewUser}}
{{end}}
</div>
Expand Down
4 changes: 2 additions & 2 deletions source/wiki.go

Large diffs are not rendered by default.

0 comments on commit d9e0387

Please sign in to comment.