Skip to content
Snippets Groups Projects
Commit 2ce6d8cd authored by Florent Gluck's avatar Florent Gluck
Browse files

ongoing work on nexus-server config file support rather than hardcoded value in code

parent 2a870efa
Branches
No related tags found
No related merge requests found
......@@ -129,7 +129,7 @@ prepare_uninstall_dev_srv:
@echo "[Uninstalling nexus-server development environment in $(SERVER_BASEDIR)]"
run_srv: check_prefix_var $(SERVER_BASEDIR)/bin/nexus-server
@cd $(SERVER_BASEDIR)/bin && NEXUS_CERTS_DIR=../certs ./nexus-server
@cd $(SERVER_BASEDIR)/bin && ./nexus-server
#-------------------------------------------------------------------------
# Server targets for prod environment
......
# Port the API listens to (must be > 1024 and < 65535)
APIDefaultPort = 1077
# Define the range of ports used by each VM for their spice server
VMSpiceMinPort = 1100
VMSpiceMaxPort = 65535
# Log level
# Supported levels: panic, fatal, error, warn, info, debug
LogLevel = info
# Absolute path to QEMU system binary
QemuSystem = /usr/bin/qemu-system-x86_64
# Absolute path to QEMU image binary
QemuImg = /usr/bin/qemu-img
# Absolute path to guestfish binary
Guestfish = /usr/bin/guestfish
# Directory where temporary files are created
TmpDir = /tmp
MaxUploadSize = 30G
# We estimate that KVM allows for this amount of RAM saving in % (due to page sharing across VMs).
# 30% seems to be a pretty conservative estimate.
KsmRamSaving = 0.3
# To prevent RAM saturation, we refuse running new VMs if more than
# this amount of memory is being used (in %).
RamUsageLimit = 0.85
......@@ -3,8 +3,6 @@ Description=nexus-server service
After=network.target
[Service]
Environment="PATH=/usr/bin:$PATH"
Environment="NEXUS_CERTS_DIR=_PREFIX_/nexus-server/certs"
User=nexus
Group=nexus
UMask=0007
......
......@@ -3,11 +3,7 @@ package consts
const (
DefaultLogLevel = "info"
ENV_NEXUS_CERTS_DIR = "NEXUS_CERTS_DIR"
APIDefaultPort = 1077
APIPortMin = 1025
APIPortMax = 1099
VMSpiceMinPort = 1100
VMSpiceMaxPort = 65535
......
......@@ -5,7 +5,6 @@ import (
"fmt"
"path"
"flag"
"strconv"
"strings"
"nexus-server/vms"
"nexus-server/exec"
......@@ -49,9 +48,6 @@ func main() {
}
loglevelFlag := flag.String("l", consts.DefaultLogLevel, "Log level: debug, info, warn, error, fatal")
portMin := strconv.Itoa(consts.APIPortMin)
portMax := strconv.Itoa(consts.APIPortMax)
portFlag := flag.Int("p", consts.APIDefaultPort, "Port on which to listen to (between "+portMin+" and "+portMax+")")
flag.Parse()
loglevelStr := strings.ToLower(*loglevelFlag)
......@@ -71,12 +67,6 @@ func main() {
usage()
}
port := *portFlag
if port < consts.APIPortMin || port > consts.APIPortMax {
fmt.Println("Invalid port number!")
usage()
}
err := users.InitUsers()
if err != nil {
log.Fatal(err.Error())
......@@ -95,5 +85,5 @@ func main() {
cleaner.Start()
router.New().Start(port)
router.New().Start(consts.APIDefaultPort)
}
package paths
import (
"os"
"path/filepath"
"nexus-server/logger"
c "nexus-server/consts"
)
type Paths struct {
......@@ -13,7 +11,7 @@ type Paths struct {
DataDir string
VMsDir string
TemplatesDir string
NexusPkiDir string
CertsDir string
TmpDir string
}
......@@ -25,16 +23,7 @@ func GetInstance() *Paths {
}
func Init() {
certsDirEnvVar, found := os.LookupEnv(c.ENV_NEXUS_CERTS_DIR)
if !found {
log.Error("Environment variable \""+c.ENV_NEXUS_CERTS_DIR+"\" must be set!")
log.Error("It defines the directory where server-cert.pem and server-key.pem reside.")
os.Exit(1)
}
certsDir, _ := filepath.Abs(certsDirEnvVar)
log.Info("Using certificates in ", certsDir)
certs := "../certs"
config := "../config"
data := "../data"
paths = &Paths {
......@@ -43,7 +32,7 @@ func Init() {
DataDir: data,
VMsDir: filepath.Join(data, "/vms"),
TemplatesDir: filepath.Join(data, "/templates"),
NexusPkiDir: certsDirEnvVar,
CertsDir: certs,
TmpDir: filepath.Join(data, "/tmp"),
}
}
......@@ -107,8 +107,8 @@ func (router *Router)Start(port int) {
// Starts server in a dedicated goroutine.
go func() {
pkiDir := paths.GetInstance().NexusPkiDir
if err := router.echo.StartTLS(":"+strconv.Itoa(port), filepath.Join(pkiDir, "/server-cert.pem"), filepath.Join(pkiDir, "/server-key.pem")); err != nil {
certsDir := paths.GetInstance().CertsDir
if err := router.echo.StartTLS(":"+strconv.Itoa(port), filepath.Join(certsDir, "/server-cert.pem"), filepath.Join(certsDir, "/server-key.pem")); err != nil {
if err != http.ErrServerClosed {
log.Fatal("Server error: "+err.Error())
} else {
......
......@@ -51,6 +51,7 @@ func GetVMsInstance() *VMs {
func InitVMs() error {
vmsDir := paths.GetInstance().VMsDir
vms = &VMs { m: make(map[string]*VM), dir: vmsDir, rwlock: new(sync.RWMutex), usedRAM: 0 }
vms.usedPorts[c.APIDefaultPort] = true
errMsg := "Failed reading VMs directory: "
dirs1, err := utils.GetSubDirs(vmsDir)
......@@ -241,8 +242,8 @@ func (vms *VMs)StartVMWithCreds(vmID uuid.UUID, port int, checkPort bool, pwd st
// Function that executes the VM in QEMU using the specified spice port and password.
runQemuFn := func(vm *VM, port int, pwd, pwdFile string, endofExecFn endOfExecCallback) error {
pkiDir := paths.GetInstance().NexusPkiDir
cmd, err := exec.NewQemuSystem(vm.qgaSock, vm.v.Cpus, vm.v.Ram, string(vm.v.Nic), vm.v.UsbDevs, filepath.Join(vm.dir, vmDiskFile), port, pwdFile, pkiDir)
certsDir := paths.GetInstance().CertsDir
cmd, err := exec.NewQemuSystem(vm.qgaSock, vm.v.Cpus, vm.v.Ram, string(vm.v.Nic), vm.v.UsbDevs, filepath.Join(vm.dir, vmDiskFile), port, pwdFile, certsDir)
if err != nil {
log.Error(prefix+"filepath join error: "+err.Error())
return err
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment