diff --git a/servers/README.md b/servers/README.md index fd1b7c6f..c5b731ba 100644 --- a/servers/README.md +++ b/servers/README.md @@ -28,3 +28,10 @@ You can automatically start a Statup server with automatic SSL encryption using DOMAIN=mydomain.com EMAIL=info@mydomain.com \ docker-compose -f docker-compose-ssl.yml up -d ``` + +## Systemd +```$xslt +/etc/systemd/system/statup.service + + +``` \ No newline at end of file diff --git a/servers/init.sh b/servers/init.sh new file mode 100644 index 00000000..d377ec22 --- /dev/null +++ b/servers/init.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +cd /home/ubuntu +curl -o /home/ubuntu/startup.sh -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/hunterlong/statup/master/servers/startup.sh +chmod +x /home/ubuntu/startup.sh +./startup.sh \ No newline at end of file diff --git a/servers/startup-ssl.sh b/servers/startup-ssl.sh new file mode 100644 index 00000000..2ca1323c --- /dev/null +++ b/servers/startup-ssl.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +LETSENCRYPT_HOST="status.balancebadge.io" +LETSENCRYPT_EMAIL="info@socialeck.com" + +rm -f docker-compose.yml +curl -o docker-compose.yml -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/hunterlong/statu$ +sudo service docker start +sudo docker system prune -af +sudo LETSENCRYPT_HOST=$LETSENCRYPT_HOST LETSENCRYPT_EMAIL=$LETSENCRYPT_EMAIL docker-compose pull +sudo LETSENCRYPT_HOST=$LETSENCRYPT_HOST LETSENCRYPT_EMAIL=$LETSENCRYPT_EMAIL docker-compose up -d \ No newline at end of file diff --git a/servers/startup.sh b/servers/startup.sh new file mode 100644 index 00000000..6b54a8fb --- /dev/null +++ b/servers/startup.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +cd /home/ubuntu +rm -f docker-compose.yml +curl -o docker-compose.yml -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/hunterlong/statup/master/servers/docker-compose.yml +sudo service docker start +sudo docker system prune -af +sudo docker-compose pull +sudo docker-compose up -d \ No newline at end of file diff --git a/servers/statup.service b/servers/statup.service new file mode 100644 index 00000000..b4657221 --- /dev/null +++ b/servers/statup.service @@ -0,0 +1,12 @@ +[Unit] +Description=Statup Docker Startup +After=network.target +After=systemd-user-sessions.service +After=network-online.target + +[Service] +Type=oneshot +ExecStart=/home/ubuntu/startup.sh + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/servers/ubuntu-docker.sh b/servers/ubuntu-docker.sh new file mode 100644 index 00000000..8da782ff --- /dev/null +++ b/servers/ubuntu-docker.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +sudo apt-get update +sudo apt-get install \ + apt-transport-https \ + ca-certificates \ + curl \ + software-properties-common -y +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - +sudo add-apt-repository \ + "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) \ + stable" +sudo apt-get update +sudo apt-get install docker-ce -y +sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose +sudo chmod +x /usr/local/bin/docker-compose +sudo docker-compose --version +sudo systemctl enable docker +mkdir statup +cd statup +wget https://raw.githubusercontent.com/hunterlong/statup/master/servers/docker-compose.yml +sudo service docker start +sudo docker-compose up -d \ No newline at end of file diff --git a/services.go b/services.go index b3d4a520..0f3941db 100644 --- a/services.go +++ b/services.go @@ -102,17 +102,15 @@ type GraphJson struct { Y float64 `json:"y"` } - type DateScan struct { CreatedAt time.Time `json:"x"` - Value int64 `json:"y"` + Value int64 `json:"y"` } - func (s *Service) GraphData() string { var d []DateScan - since := time.Now().Add(time.Hour * -12 + time.Minute * 0 + time.Second * 0) + since := time.Now().Add(time.Hour*-12 + time.Minute*0 + time.Second*0) sql := fmt.Sprintf("SELECT date_trunc('minute', created_at), AVG(latency)*1000 AS value FROM hits WHERE service=%v AND created_at > '%v' GROUP BY 1 ORDER BY date_trunc ASC;", s.Id, since.Format(time.RFC3339)) @@ -136,7 +134,6 @@ func (s *Service) GraphData() string { } - if err != nil { panic(err) } @@ -154,7 +151,6 @@ func (s *Service) GraphData() string { return string(data) } - //func (s *Service) GraphData() string { // var d []GraphJson // hits, _ := s.LimitedHits()