Browse Source

打包和运行脚本

tuon 1 year ago
parent
commit
b773e821ba
3 changed files with 29 additions and 9 deletions
  1. 2 0
      build.sh
  2. 21 9
      main.go
  3. 6 0
      start.sh

+ 2 - 0
build.sh

@@ -0,0 +1,2 @@
+#!/bin/sh
+CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./

+ 21 - 9
main.go

@@ -10,6 +10,7 @@ import (
 
 func main() {
 	serverPort := 12345
+	path := ""
 	if len(os.Args) > 1 {
 		for k, v := range os.Args {
 			if k == 0 {
@@ -18,6 +19,7 @@ func main() {
 			arg := strings.TrimSpace(v)
 			hasPortL := strings.HasPrefix(arg, "--port=")
 			hasPortS := strings.HasPrefix(arg, "-p=")
+			hasPath := strings.HasPrefix(arg, "--path=")
 			if hasPortL {
 				i, err := strconv.ParseInt(strings.ReplaceAll(arg, "--port=", ""), 10, 32)
 				if err == nil {
@@ -32,18 +34,28 @@ func main() {
 					break
 				}
 			}
+			if hasPath {
+				path = strings.ReplaceAll(arg, "--path=", "")
+			}
 		}
 	}
 
-	http.HandleFunc("/", indexHandler)
-	http.HandleFunc("/jrebel/leases", jrebelLeasesHandler)
-	http.HandleFunc("/jrebel/leases/1", jrebelLeases1Handler)
-	http.HandleFunc("/agent/leases", jrebelLeasesHandler)
-	http.HandleFunc("/agent/leases/1", jrebelLeases1Handler)
-	http.HandleFunc("/jrebel/validate-connection", jrebelValidateHandler)
-	http.HandleFunc("/rpc/ping.action", pingHandler)
-	http.HandleFunc("/rpc/obtainTicket.action", obtainTicketHandler)
-	http.HandleFunc("/rpc/releaseTicket.action", releaseTicketHandler)
+	if strings.HasSuffix(path, "/") {
+		path = strings.TrimSuffix(path, "/")
+	}
+	if len(path) > 0 && !strings.HasPrefix(path, "/") {
+		path = fmt.Sprintf("/%s", path)
+	}
+
+	http.HandleFunc(path, indexHandler)
+	http.HandleFunc(fmt.Sprintf("%s/jrebel/leases", path), jrebelLeasesHandler)
+	http.HandleFunc(fmt.Sprintf("%s/jrebel/leases/1", path), jrebelLeases1Handler)
+	http.HandleFunc(fmt.Sprintf("%s/agent/leases", path), jrebelLeasesHandler)
+	http.HandleFunc(fmt.Sprintf("%s/agent/leases/1", path), jrebelLeases1Handler)
+	http.HandleFunc(fmt.Sprintf("%s/jrebel/validate-connection", path), jrebelValidateHandler)
+	http.HandleFunc(fmt.Sprintf("%s/rpc/ping.action", path), pingHandler)
+	http.HandleFunc(fmt.Sprintf("%s/rpc/obtainTicket.action", path), obtainTicketHandler)
+	http.HandleFunc(fmt.Sprintf("%s/rpc/releaseTicket.action", path), releaseTicketHandler)
 
 	fmt.Printf("start server with port = %d\n", serverPort)
 

+ 6 - 0
start.sh

@@ -0,0 +1,6 @@
+#!/bin/sh
+pid=$(ps -elf | grep jrebel-license-active-server | grep -v grep | awk '{print $4}')
+if [ $pid != "" ]; then
+    kill -9 $pid
+fi
+nohup ./jrebel-license-active-server --path=/jrebel --port=12345 &