2014-08-16 03:50:59 +00:00
|
|
|
/*
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
Copyright 2014 The Perkeep Authors
|
2014-08-16 03:50:59 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package serverinit
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-08-19 06:17:17 +00:00
|
|
|
"os"
|
2014-08-16 03:50:59 +00:00
|
|
|
"strings"
|
|
|
|
|
2018-01-03 05:03:30 +00:00
|
|
|
"perkeep.org/internal/osutil"
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
"perkeep.org/pkg/env"
|
|
|
|
"perkeep.org/pkg/types/serverconfig"
|
2016-09-07 18:27:11 +00:00
|
|
|
|
|
|
|
"cloud.google.com/go/compute/metadata"
|
2014-08-16 03:50:59 +00:00
|
|
|
)
|
|
|
|
|
pkg/serverinit: on GCE, reset name if instance name is in camlistore.net
On GCE, on startup, we did not set the camliNetIP in the high-level
config if the camlistore-hostname instance var vas already set.
The camliNetIP presence in the config is the signal for the server
that it should be configured as part of camlistore.net (and in
particular that it should update the record for its name on the
camlistore.net DNS server). Part of this configuration is to set the
camlistore-hostname var for the instance.
Therefore, a server which had been configured once as described above,
would not, on a subsequent restart, behave as if part of camlistore.net
and would skip the related configuration code path. Unless the
camlistore-hostname var was manually wiped before restart.
As this manual step is not an obvious one, this CL changes the
initialization, so that if a camlistore-hostname var is set, but the
value is a subdomain of "camlistore.net", the var is treated as empty
and initialization proceeds as if with a new server.
Fixes #963
Change-Id: Iab70185d7b90ef7e70bb831d363ff9d525922e35
2017-10-03 22:44:18 +00:00
|
|
|
// For getting a name in camlistore.net
|
|
|
|
const (
|
|
|
|
// CamliNetDNS is the hostname of the camlistore.net DNS server.
|
|
|
|
CamliNetDNS = "camnetdns.camlistore.org"
|
|
|
|
// CamliNetDomain is the camlistore.net domain name. It is relevant to
|
|
|
|
// Camlistore, because a deployment through the Camlistore on Google Cloud launcher
|
|
|
|
// automatically offers a subdomain name in this domain to any instance.
|
|
|
|
CamliNetDomain = "camlistore.net"
|
|
|
|
)
|
|
|
|
|
2014-08-16 03:50:59 +00:00
|
|
|
// DefaultEnvConfig returns the default configuration when running on a known
|
|
|
|
// environment. Currently this just includes Google Compute Engine.
|
|
|
|
// If the environment isn't known (nil, nil) is returned.
|
|
|
|
func DefaultEnvConfig() (*Config, error) {
|
2015-04-01 15:37:32 +00:00
|
|
|
if !env.OnGCE() {
|
2014-08-16 03:50:59 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
auth := "none"
|
2015-04-01 15:37:32 +00:00
|
|
|
user, _ := metadata.InstanceAttributeValue("camlistore-username")
|
|
|
|
pass, _ := metadata.InstanceAttributeValue("camlistore-password")
|
|
|
|
confBucket, err := metadata.InstanceAttributeValue("camlistore-config-dir")
|
2014-08-16 05:06:13 +00:00
|
|
|
if confBucket == "" || err != nil {
|
2014-12-12 22:32:58 +00:00
|
|
|
return nil, fmt.Errorf("VM instance metadata key 'camlistore-config-dir' not set: %v", err)
|
2014-08-16 03:50:59 +00:00
|
|
|
}
|
2015-04-01 15:37:32 +00:00
|
|
|
blobBucket, err := metadata.InstanceAttributeValue("camlistore-blob-dir")
|
2014-08-16 05:06:13 +00:00
|
|
|
if blobBucket == "" || err != nil {
|
2014-12-12 22:32:58 +00:00
|
|
|
return nil, fmt.Errorf("VM instance metadata key 'camlistore-blob-dir' not set: %v", err)
|
2014-08-16 03:50:59 +00:00
|
|
|
}
|
|
|
|
if user != "" && pass != "" {
|
|
|
|
auth = "userpass:" + user + ":" + pass
|
|
|
|
}
|
|
|
|
|
|
|
|
if v := osutil.SecretRingFile(); !strings.HasPrefix(v, "/gcs/") {
|
|
|
|
return nil, fmt.Errorf("Internal error: secret ring path on GCE should be at /gcs/, not %q", v)
|
|
|
|
}
|
|
|
|
keyId, secRing, err := getOrMakeKeyring()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-08-19 06:17:17 +00:00
|
|
|
highConf := &serverconfig.Config{
|
2014-08-16 03:50:59 +00:00
|
|
|
Auth: auth,
|
|
|
|
HTTPS: true,
|
|
|
|
Identity: keyId,
|
|
|
|
IdentitySecretRing: secRing,
|
2014-12-12 22:32:58 +00:00
|
|
|
GoogleCloudStorage: ":" + strings.TrimPrefix(blobBucket, "gs://"),
|
2014-08-23 16:46:56 +00:00
|
|
|
DBNames: map[string]string{},
|
2015-02-02 14:48:20 +00:00
|
|
|
PackRelated: true,
|
2017-04-05 14:11:01 +00:00
|
|
|
ShareHandler: true,
|
2014-08-19 06:17:17 +00:00
|
|
|
}
|
|
|
|
|
2016-12-18 00:24:15 +00:00
|
|
|
externalIP, _ := metadata.ExternalIP()
|
|
|
|
hostName, _ := metadata.InstanceAttributeValue("camlistore-hostname")
|
2018-01-03 06:10:37 +00:00
|
|
|
// If they specified a hostname (probably with pk-deploy), then:
|
2017-01-13 15:04:23 +00:00
|
|
|
// if it looks like an FQDN, camlistored is going to rely on Let's
|
|
|
|
// Encrypt, else camlistored is going to generate some self-signed for that
|
|
|
|
// hostname.
|
pkg/serverinit: on GCE, reset name if instance name is in camlistore.net
On GCE, on startup, we did not set the camliNetIP in the high-level
config if the camlistore-hostname instance var vas already set.
The camliNetIP presence in the config is the signal for the server
that it should be configured as part of camlistore.net (and in
particular that it should update the record for its name on the
camlistore.net DNS server). Part of this configuration is to set the
camlistore-hostname var for the instance.
Therefore, a server which had been configured once as described above,
would not, on a subsequent restart, behave as if part of camlistore.net
and would skip the related configuration code path. Unless the
camlistore-hostname var was manually wiped before restart.
As this manual step is not an obvious one, this CL changes the
initialization, so that if a camlistore-hostname var is set, but the
value is a subdomain of "camlistore.net", the var is treated as empty
and initialization proceeds as if with a new server.
Fixes #963
Change-Id: Iab70185d7b90ef7e70bb831d363ff9d525922e35
2017-10-03 22:44:18 +00:00
|
|
|
// Also, if the hostname is in camlistore.net, we want Camlistore to initialize
|
|
|
|
// exactly as if the instance had no hostname, so that it registers its hostname/IP
|
|
|
|
// with the camlistore.net DNS server (possibly needlessly, if the instance IP has
|
|
|
|
// not changed) again.
|
|
|
|
if hostName != "" && !strings.HasSuffix(hostName, CamliNetDomain) {
|
2016-12-18 00:24:15 +00:00
|
|
|
highConf.BaseURL = fmt.Sprintf("https://%s", hostName)
|
|
|
|
highConf.Listen = "0.0.0.0:443"
|
|
|
|
} else {
|
|
|
|
highConf.CamliNetIP = externalIP
|
|
|
|
}
|
|
|
|
|
2014-08-19 06:17:17 +00:00
|
|
|
// Detect a linked Docker MySQL container. It must have alias "mysqldb".
|
|
|
|
if v := os.Getenv("MYSQLDB_PORT"); strings.HasPrefix(v, "tcp://") {
|
|
|
|
hostPort := strings.TrimPrefix(v, "tcp://")
|
|
|
|
highConf.MySQL = "root@" + hostPort + ":" // no password
|
2014-08-24 02:55:04 +00:00
|
|
|
highConf.DBNames["queue-sync-to-index"] = "sync_index_queue"
|
|
|
|
highConf.DBNames["ui_thumbcache"] = "ui_thumbmeta_cache"
|
2015-02-02 14:48:20 +00:00
|
|
|
highConf.DBNames["blobpacked_index"] = "blobpacked_index"
|
2014-08-19 06:17:17 +00:00
|
|
|
} else {
|
|
|
|
// TODO: also detect Cloud SQL.
|
|
|
|
highConf.KVFile = "/index.kv"
|
|
|
|
}
|
|
|
|
|
|
|
|
return genLowLevelConfig(highConf)
|
2014-08-16 03:50:59 +00:00
|
|
|
}
|