Compare commits
3 Commits
8879463cb9
...
release-0.
| Author | SHA1 | Date | |
|---|---|---|---|
| 432b47d224 | |||
| 6c1321e485 | |||
| 32408e4471 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,4 +1,4 @@
|
|||||||
dospin.json
|
dospin.json
|
||||||
test_config.json
|
test_config.yaml
|
||||||
dospin
|
dospin
|
||||||
main
|
main
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ servers:
|
|||||||
minecraft:
|
minecraft:
|
||||||
ports:
|
ports:
|
||||||
- 25565
|
- 25565
|
||||||
|
activity_timeout_min: 20m
|
||||||
use_public_ip: false
|
use_public_ip: false
|
||||||
initial_size: 4gb
|
initial_size: 4gb
|
||||||
size: 4gb
|
size: 4gb
|
||||||
@@ -23,4 +24,3 @@ servers:
|
|||||||
mount -o discard,defaults /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01 /mnt/volume-nyc1-01
|
mount -o discard,defaults /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01 /mnt/volume-nyc1-01
|
||||||
echo /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01 /mnt/volume-nyc1-01 ext4 defaults,nofail,discard 0 0 | tee -a /etc/fstab
|
echo /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01 /mnt/volume-nyc1-01 ext4 defaults,nofail,discard 0 0 | tee -a /etc/fstab
|
||||||
docker run -d --restart=always -p 25565:25565 -v /mnt/volume-nyc1-01/minecraft-server:/minecraft-server -w /minecraft-server -t java:8-alpine sh start.sh
|
docker run -d --restart=always -p 25565:25565 -v /mnt/volume-nyc1-01/minecraft-server:/minecraft-server -w /minecraft-server -t java:8-alpine sh start.sh
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
#! /usr/bin/env sh
|
|
||||||
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer `cat dospin.json | jq -r .ApiToken`" "https://api.digitalocean.com/v2/droplets?page=1&per_page=100&private=true" | jq .
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
#! /usr/bin/env sh
|
|
||||||
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer `cat dospin.json | jq -r .ApiToken`" "https://api.digitalocean.com/v2/images?page=1&per_page=100&private=true" | jq .
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
#! /usr/bin/env sh
|
|
||||||
|
|
||||||
echo Keys
|
|
||||||
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer `cat dospin.json | jq -r .ApiToken`" "https://api.digitalocean.com/v2/account/keys" | jq .
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
#! /usr/bin/env sh
|
|
||||||
|
|
||||||
echo Volumes
|
|
||||||
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer `cat dospin.json | jq -r .ApiToken`" "https://api.digitalocean.com/v2/volumes" | jq .
|
|
||||||
@@ -39,6 +39,7 @@ type ServerManager struct {
|
|||||||
connStatus chan ConnStatus
|
connStatus chan ConnStatus
|
||||||
lastKeepAliveTime time.Time
|
lastKeepAliveTime time.Time
|
||||||
server ServerHandler
|
server ServerHandler
|
||||||
|
activityTimeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServerManager(name string, server ServerHandler, settings Settings) *ServerManager {
|
func NewServerManager(name string, server ServerHandler, settings Settings) *ServerManager {
|
||||||
@@ -52,6 +53,13 @@ func NewServerManager(name string, server ServerHandler, settings Settings) *Ser
|
|||||||
sm.server = server
|
sm.server = server
|
||||||
sm.lastKeepAliveTime = time.Now()
|
sm.lastKeepAliveTime = time.Now()
|
||||||
|
|
||||||
|
activityTimeout, err := time.ParseDuration(settings.Servers[sm.name].ActivityTimeout)
|
||||||
|
if err != nil { // invalid timeout, default to 5 minutes
|
||||||
|
activityTimeout = time.Duration(5 * time.Minute)
|
||||||
|
}
|
||||||
|
sm.activityTimeout = activityTimeout
|
||||||
|
log.Println("ServerManager: ", name, " has activity timeout of ", sm.activityTimeout.String())
|
||||||
|
|
||||||
return sm
|
return sm
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,8 +69,7 @@ func NewServerManager(name string, server ServerHandler, settings Settings) *Ser
|
|||||||
func (me *ServerManager) Serve() {
|
func (me *ServerManager) Serve() {
|
||||||
// TODO: see if server is currently up, and setup port forwarding if so
|
// TODO: see if server is currently up, and setup port forwarding if so
|
||||||
|
|
||||||
activityTimeout := time.Duration(5 * time.Minute)
|
ticker := time.NewTicker(1 * time.Minute)
|
||||||
ticker := time.NewTicker(activityTimeout)
|
|
||||||
|
|
||||||
// event loop
|
// event loop
|
||||||
for running := true; running; {
|
for running := true; running; {
|
||||||
@@ -74,7 +81,7 @@ func (me *ServerManager) Serve() {
|
|||||||
case action := <-me.in:
|
case action := <-me.in:
|
||||||
running = me.serveAction(action)
|
running = me.serveAction(action)
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
if time.Since(me.lastKeepAliveTime) > activityTimeout {
|
if time.Since(me.lastKeepAliveTime) > me.activityTimeout {
|
||||||
running = me.serveAction(serverManagerEvent{eventType: SERVERMANAGER_SPINDOWN})
|
running = me.serveAction(serverManagerEvent{eventType: SERVERMANAGER_SPINDOWN})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ type Settings struct {
|
|||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
Ports []int `yaml:"ports"`
|
Ports []int `yaml:"ports"`
|
||||||
ActivityTimeoutMin int `yaml:"activity_timeout_min"`
|
ActivityTimeout string `yaml:"activity_timeout"`
|
||||||
UsePublicIP bool `yaml:"use_public_ip"`
|
UsePublicIP bool `yaml:"use_public_ip"`
|
||||||
InitialSize string `yaml:"initial_size"`
|
InitialSize string `yaml:"initial_size"`
|
||||||
Size string `yaml:"size"`
|
Size string `yaml:"size"`
|
||||||
|
|||||||
Reference in New Issue
Block a user