-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (59 loc) · 1.52 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"flag"
"log"
"os"
"os/exec"
"github.com/3Blades/core-server"
_ "github.com/lib/pq"
)
var (
databaseURL string
redisURL string
hashID string
resourceDir string
port int
hubServerSecretKey string
serverStateKey string
)
func main() {
flag.StringVar(&databaseURL, "db", "", "Database url")
flag.StringVar(&redisURL, "redis", "redis://localhost:6379/0", "Redis url")
flag.StringVar(&hashID, "hashid", "", "Workspace hash id")
flag.StringVar(&resourceDir, "resource", "", "Resource dir")
flag.IntVar(&port, "port", -1, "Notebook port")
flag.StringVar(&hubServerSecretKey, "secret", "", "Secret key")
flag.Parse()
serverStateKey = "server_state_" + hashID
serverID, err := core.DecodeHashID(hubServerSecretKey, hashID)
if err != nil {
go core.SetStatus(redisURL, "Error", serverStateKey)
log.Fatal(err)
}
core.StartScript(databaseURL, serverID)
err = core.CreateSSHTunnels(databaseURL, resourceDir, serverID)
if err != nil {
go core.SetStatus(redisURL, "Error", serverStateKey)
log.Fatal(err)
}
err = runNotebook()
if err != nil {
log.Fatal(err)
}
}
func runNotebook() error {
args := flag.Args()
log.Println(args)
command := args[0]
cargs := args[1:]
err := os.Chdir(resourceDir)
if err != nil {
go core.SetStatus(redisURL, "Error", serverStateKey)
return err
}
cmd := exec.Command(command, cargs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
go core.SetStatus(redisURL, "Running", serverStateKey)
return cmd.Run()
}