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
No related branches found
No related tags found
No related merge requests found
...@@ -129,7 +129,7 @@ prepare_uninstall_dev_srv: ...@@ -129,7 +129,7 @@ prepare_uninstall_dev_srv:
@echo "[Uninstalling nexus-server development environment in $(SERVER_BASEDIR)]" @echo "[Uninstalling nexus-server development environment in $(SERVER_BASEDIR)]"
run_srv: check_prefix_var $(SERVER_BASEDIR)/bin/nexus-server 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 # 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 ...@@ -3,8 +3,6 @@ Description=nexus-server service
After=network.target After=network.target
[Service] [Service]
Environment="PATH=/usr/bin:$PATH"
Environment="NEXUS_CERTS_DIR=_PREFIX_/nexus-server/certs"
User=nexus User=nexus
Group=nexus Group=nexus
UMask=0007 UMask=0007
......
...@@ -3,11 +3,7 @@ package consts ...@@ -3,11 +3,7 @@ package consts
const ( const (
DefaultLogLevel = "info" DefaultLogLevel = "info"
ENV_NEXUS_CERTS_DIR = "NEXUS_CERTS_DIR"
APIDefaultPort = 1077 APIDefaultPort = 1077
APIPortMin = 1025
APIPortMax = 1099
VMSpiceMinPort = 1100 VMSpiceMinPort = 1100
VMSpiceMaxPort = 65535 VMSpiceMaxPort = 65535
......
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"path" "path"
"flag" "flag"
"strconv"
"strings" "strings"
"nexus-server/vms" "nexus-server/vms"
"nexus-server/exec" "nexus-server/exec"
...@@ -49,9 +48,6 @@ func main() { ...@@ -49,9 +48,6 @@ func main() {
} }
loglevelFlag := flag.String("l", consts.DefaultLogLevel, "Log level: debug, info, warn, error, fatal") 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() flag.Parse()
loglevelStr := strings.ToLower(*loglevelFlag) loglevelStr := strings.ToLower(*loglevelFlag)
...@@ -71,12 +67,6 @@ func main() { ...@@ -71,12 +67,6 @@ func main() {
usage() usage()
} }
port := *portFlag
if port < consts.APIPortMin || port > consts.APIPortMax {
fmt.Println("Invalid port number!")
usage()
}
err := users.InitUsers() err := users.InitUsers()
if err != nil { if err != nil {
log.Fatal(err.Error()) log.Fatal(err.Error())
...@@ -95,5 +85,5 @@ func main() { ...@@ -95,5 +85,5 @@ func main() {
cleaner.Start() cleaner.Start()
router.New().Start(port) router.New().Start(consts.APIDefaultPort)
} }
package paths package paths
import ( import (
"os"
"path/filepath" "path/filepath"
"nexus-server/logger" "nexus-server/logger"
c "nexus-server/consts"
) )
type Paths struct { type Paths struct {
...@@ -13,7 +11,7 @@ type Paths struct { ...@@ -13,7 +11,7 @@ type Paths struct {
DataDir string DataDir string
VMsDir string VMsDir string
TemplatesDir string TemplatesDir string
NexusPkiDir string CertsDir string
TmpDir string TmpDir string
} }
...@@ -25,16 +23,7 @@ func GetInstance() *Paths { ...@@ -25,16 +23,7 @@ func GetInstance() *Paths {
} }
func Init() { func Init() {
certsDirEnvVar, found := os.LookupEnv(c.ENV_NEXUS_CERTS_DIR) certs := "../certs"
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)
config := "../config" config := "../config"
data := "../data" data := "../data"
paths = &Paths { paths = &Paths {
...@@ -43,7 +32,7 @@ func Init() { ...@@ -43,7 +32,7 @@ func Init() {
DataDir: data, DataDir: data,
VMsDir: filepath.Join(data, "/vms"), VMsDir: filepath.Join(data, "/vms"),
TemplatesDir: filepath.Join(data, "/templates"), TemplatesDir: filepath.Join(data, "/templates"),
NexusPkiDir: certsDirEnvVar, CertsDir: certs,
TmpDir: filepath.Join(data, "/tmp"), TmpDir: filepath.Join(data, "/tmp"),
} }
} }
...@@ -107,8 +107,8 @@ func (router *Router)Start(port int) { ...@@ -107,8 +107,8 @@ func (router *Router)Start(port int) {
// Starts server in a dedicated goroutine. // Starts server in a dedicated goroutine.
go func() { go func() {
pkiDir := paths.GetInstance().NexusPkiDir certsDir := paths.GetInstance().CertsDir
if err := router.echo.StartTLS(":"+strconv.Itoa(port), filepath.Join(pkiDir, "/server-cert.pem"), filepath.Join(pkiDir, "/server-key.pem")); err != nil { 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 { if err != http.ErrServerClosed {
log.Fatal("Server error: "+err.Error()) log.Fatal("Server error: "+err.Error())
} else { } else {
......
...@@ -51,6 +51,7 @@ func GetVMsInstance() *VMs { ...@@ -51,6 +51,7 @@ func GetVMsInstance() *VMs {
func InitVMs() error { func InitVMs() error {
vmsDir := paths.GetInstance().VMsDir vmsDir := paths.GetInstance().VMsDir
vms = &VMs { m: make(map[string]*VM), dir: vmsDir, rwlock: new(sync.RWMutex), usedRAM: 0 } 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: " errMsg := "Failed reading VMs directory: "
dirs1, err := utils.GetSubDirs(vmsDir) dirs1, err := utils.GetSubDirs(vmsDir)
...@@ -241,8 +242,8 @@ func (vms *VMs)StartVMWithCreds(vmID uuid.UUID, port int, checkPort bool, pwd st ...@@ -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. // 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 { runQemuFn := func(vm *VM, port int, pwd, pwdFile string, endofExecFn endOfExecCallback) error {
pkiDir := paths.GetInstance().NexusPkiDir 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, pkiDir) 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 { if err != nil {
log.Error(prefix+"filepath join error: "+err.Error()) log.Error(prefix+"filepath join error: "+err.Error())
return err return err
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment