blob: 4624e53872cda077eb6c68f779bb340141916e4f [file] [log] [blame]
// Copyright 2017 The Upspin Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Server helpers.
package subcmd
import (
// ServerConfig describes the configuration of an upspinserver.
type ServerConfig struct {
// Addr specifies the public host and port of the upspinserver.
Addr upspin.NetAddr
// User specifies the user name that the upspinserver will run as.
User upspin.UserName
// StoreConfig specifies the configuration options for the StoreServer.
StoreConfig []string
// ServerConfigFile specifies the file name of the JSON-encoded ServerConfig.
const ServerConfigFile = "serverconfig.json"
// SetupServerFiles specifies the configuration files that 'upspin setupserver'
// should send to the upspinserver.
var SetupServerFiles = []string{
// ReadServerConfig reads and JSON-decodes the ServerConfigFile under cfgPath.
func (s *State) ReadServerConfig(cfgPath string) *ServerConfig {
cfgFile := filepath.Join(cfgPath, ServerConfigFile)
b, err := ioutil.ReadFile(cfgFile)
if err != nil {
if os.IsNotExist(err) {
s.Exitf("No server config file found at %q.\nRun 'upspin setupdomain' first.", cfgFile)
cfg := &ServerConfig{}
if err := json.Unmarshal(b, cfg); err != nil {
return cfg
// WriteServerConfig JSON-encodes and writes the ServerConfigFile under cfgPath.
func (s *State) WriteServerConfig(cfgPath string, cfg *ServerConfig) {
cfgFile := filepath.Join(cfgPath, ServerConfigFile)
b, err := json.Marshal(cfg)
if err != nil {
err = ioutil.WriteFile(cfgFile, b, 0644)
if err != nil {