pkg/server: instruction for updating on GCE

Fixes #825

Change-Id: I07dd2502816b6351b6ae71be84e98952cda5056c
This commit is contained in:
mpl 2016-07-20 02:35:20 +02:00
parent dd230b2cba
commit 73d4d49d55
1 changed files with 26 additions and 2 deletions

View File

@ -18,6 +18,7 @@ package server
import (
"encoding/json"
"errors"
"fmt"
"html"
"io"
@ -40,6 +41,8 @@ import (
"camlistore.org/pkg/server/app"
"camlistore.org/pkg/types/camtypes"
"go4.org/jsonconfig"
"google.golang.org/cloud/compute/metadata"
)
// StatusHandler publishes server status information.
@ -208,6 +211,17 @@ func (sh *StatusHandler) serveStatusJSON(rw http.ResponseWriter, req *http.Reque
httputil.ReturnJSON(rw, sh.currentStatus())
}
func (sh *StatusHandler) googleCloudConsole() (string, error) {
if !env.OnGCE() {
return "", errors.New("not on GCE")
}
projID, err := metadata.ProjectID()
if err != nil {
return "", fmt.Errorf("Error getting project ID: %v", err)
}
return "https://console.cloud.google.com/compute/instances?project=" + projID, nil
}
var quotedPrefix = regexp.MustCompile(`[;"]/(\S+?/)[&"]`)
func (sh *StatusHandler) serveStatusHTML(rw http.ResponseWriter, req *http.Request) {
@ -243,8 +257,18 @@ func (sh *StatusHandler) serveStatusHTML(rw http.ResponseWriter, req *http.Reque
f("</ul>")
f("<h2>Admin</h2>")
f("<form method='post' action='restart' onsubmit='return confirm(\"Really restart now?\")'><button>restart server</button>")
f("<input type='checkbox' name='reindex'> reindex<br></form>")
f("<ul>")
f(" <li><form method='post' action='restart' onsubmit='return confirm(\"Really restart now?\")'><button>restart server</button>")
f("<input type='checkbox' name='reindex'> reindex</form></li>")
if env.OnGCE() {
console, err := sh.googleCloudConsole()
if err != nil {
log.Printf("error getting Google Cloud Console URL: %v", err)
} else {
f(" <li><b>Updating:</b> When a new image for Camlistore on GCE is available, you can update by hitting \"Reset\" (or \"Stop\", then \"Start\") for your instance on your <a href='%s'>Google Cloud Console</a>.<br>Alternatively, you can ssh to your instance and restart the Camlistore service with: <b>sudo systemctl restart camlistored</b>.</li>", console)
}
}
f("</ul>")
f("<h2>Handlers</h2>")
f("<p>As JSON: <a href='status.json'>status.json</a>; and the <a href='%s?camli.mode=config'>discovery JSON</a>.</p>", st.rootPrefix)