| 79 | ) |
| 80 | |
| 81 | func Main(boxRoot http.FileSystem, db database.DatabaseConnection, localStoragePath string, olricDb *olric.EmbeddedClient, localOlricAddr string) ( |
| 82 | hostswitch.HostSwitch, *guerrilla.Daemon, task_scheduler.TaskScheduler, *resource.ConfigStore, *resource.CertificateManager, |
| 83 | *server2.FtpServer, *server.Server, *olric.EmbeddedClient) { |
| 84 | |
| 85 | PrintCliBanner() |
| 86 | |
| 87 | /// Start system initialise |
| 88 | log.Printf("Load config files") |
| 89 | initConfig, errs := LoadConfigFiles() |
| 90 | if errs != nil { |
| 91 | for _, err := range errs { |
| 92 | log.Errorf("Failed to load config indexFile: %v", err) |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | skipDbConfig, skipValueFound := os.LookupEnv("DAPTIN_SKIP_CONFIG_FROM_DATABASE") |
| 97 | |
| 98 | var existingTables []table_info.TableInfo |
| 99 | if skipValueFound && skipDbConfig == "true" { |
| 100 | log.Printf("ENV[DAPTIN_SKIP_CONFIG_FROM_DATABASE] skip loading existing tables config from database") |
| 101 | } else { |
| 102 | log.Printf("ENV[DAPTIN_SKIP_CONFIG_FROM_DATABASE] loading existing tables config from database") |
| 103 | existingTables, _ = GetTablesFromWorld(db) |
| 104 | allTables := MergeTables(existingTables, initConfig.Tables) |
| 105 | initConfig.Tables = allTables |
| 106 | } |
| 107 | |
| 108 | // rclone config load |
| 109 | //configfile.Install() |
| 110 | defaultConfig := fs.GetConfig(nil) |
| 111 | defaultConfig.DryRun = false |
| 112 | defaultConfig.LogLevel = fs.LogLevelDebug |
| 113 | defaultConfig.StatsLogLevel = fs.LogLevelDebug |
| 114 | |
| 115 | skipResourceInitialise, ok := os.LookupEnv("DAPTIN_SKIP_INITIALISE_RESOURCES") |
| 116 | if ok && skipResourceInitialise == "true" { |
| 117 | log.Infof("Skipping db resource initialise: %v", skipResourceInitialise) |
| 118 | } else { |
| 119 | log.Infof("ENV[DAPTIN_SKIP_INITIALISE_RESOURCES] value: %v", skipResourceInitialise) |
| 120 | InitialiseServerResources(&initConfig, db) |
| 121 | } |
| 122 | |
| 123 | configStore, err := resource.NewConfigStore(db) |
| 124 | resource.CheckErr(err, "Failed to get config store") |
| 125 | diskFileCache, err = lru.New(cacheSize) |
| 126 | |
| 127 | transaction, err := db.Beginx() |
| 128 | if err != nil { |
| 129 | resource.CheckErr(err, "Failed to begin transaction [122]") |
| 130 | panic(err) |
| 131 | } |
| 132 | |
| 133 | hostname, err := configStore.GetConfigValueFor("hostname", "backend", transaction) |
| 134 | if err != nil { |
| 135 | name, e := os.Hostname() |
| 136 | if e != nil { |
| 137 | name = "localhost" |
| 138 | } |