pass config path in cmd args

This commit is contained in:
Daniel Liu 2022-01-06 18:41:55 -05:00
parent 2b6fe3e1a0
commit fe1d5116ab
3 changed files with 25 additions and 11 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"flag"
"fmt"
"net"
"os"
@ -16,10 +17,23 @@ import (
"git.csclub.uwaterloo.ca/public/merlin/sync"
)
// get config path from command args
var CONFIG_PATH = "merlin-config.ini"
var DEFAULT_CONFIG_PATH = "merlin-config.ini"
func main() {
// custom help message
flag.Usage = func() {
w := flag.CommandLine.Output()
fmt.Fprintf(w, "USAGE: merlin [-h | --help] [--config=<config-path>]\n")
flag.PrintDefaults()
}
// parse command args
// if more are added can prob use a library
configPath := flag.String("config", DEFAULT_CONFIG_PATH, "alternate config file")
flag.Parse()
// check that merlin is run as mirror user
// check that mirror user has pid of 1001
@ -43,7 +57,7 @@ func main() {
repoIdx := 0
loadConfig := func() {
config.LoadConfig(CONFIG_PATH, doneChan, stopChan)
config.LoadConfig(*configPath, doneChan, stopChan)
logger.OutLog("Loaded config:\n" + fmt.Sprintf("%+v\n", config.Conf))
repoIdx = 0

View File

@ -86,7 +86,7 @@ func cscSyncCDImage(repo *config.Repo) []string {
func cscSyncCeph(repo *config.Repo) []string {
args := []string {
args := []string{
"rsync", "--stats", "--progress", "--quiet", "-4", "--address=" + config.Conf.IPv4Address,
repo.RsyncHost + "::ceph",
"--recursive", "--times", "--links", "--hard-links",
@ -259,7 +259,7 @@ func getSyncCommand(repo *config.Repo) (args []string) {
return cscSyncBadPerms(repo)
case "csc-sync-cdimage":
return cscSyncCDImage(repo)
case "csc-sync-ceph":
case "csc-sync-ceph":
return cscSyncCeph(repo)
case "csc-sync-chmod":
return cscSyncChmod(repo)

View File

@ -2,8 +2,8 @@ package sync
import (
"path/filepath"
"testing"
"reflect"
"testing"
"git.csclub.uwaterloo.ca/public/merlin/config"
"git.csclub.uwaterloo.ca/public/merlin/logger"
@ -16,10 +16,10 @@ func dummyRepoConf(name string, syncType string, frequencyStr string, localDir s
doneChan := make(chan config.SyncResult)
stopChan := make(chan struct{})
repoLogFile := filepath.Join("test_files", name, name + ".log")
repoLogFile := filepath.Join("test_files", name, name+".log")
logger := logger.NewLogger(name, repoLogFile)
return &config.Repo {
return &config.Repo{
Name: name,
SyncType: syncType,
FrequencyStr: frequencyStr,
@ -50,9 +50,9 @@ func TestGetSyncCommand(t *testing.T) {
config.Conf.DownloadDir = "test_files"
testData := []struct{
repoConf *config.Repo
expected []string
testData := []struct {
repoConf *config.Repo
expected []string
}{
{
repoConf: dummyRepoConf("ubuntu", "csc-sync-debian", "bi-hourly", "ubuntu", "archive.ubuntu.com", "ubuntu"),