run on startup #10

This commit is contained in:
bakito 2021-04-18 22:20:08 +02:00
parent 3edb5222d6
commit 2e93920931
No known key found for this signature in database
GPG key ID: FAF93C1C384DD6B4
5 changed files with 17 additions and 7 deletions

View file

@ -101,6 +101,7 @@ services:
- REPLICA1_APIPATH=/some/path/control
# - REPLICA1_AUTOSETUP=true # if true, AdGuardHome is automatically initialized.
- CRON=*/10 * * * * # run every 10 minutes
- RUNONSTART=true
ports:
- 8080:8080
restart: unless-stopped
@ -114,6 +115,9 @@ location: $HOME/.adguardhome-sync.yaml
# cron expression to run in daemon mode. (default; "" = runs only once)
cron: "*/10 * * * *"
# runs the synchronisation on startup
runOnStart: true
origin:
# url of the origin instance
url: https://192.168.1.2:3000

View file

@ -14,7 +14,8 @@ import (
)
const (
configCron = "cron"
configCron = "cron"
configRunOnStart = "runOnStart"
configAPIPort = "api.port"
configAPIUsername = "api.username"

View file

@ -28,6 +28,8 @@ func init() {
rootCmd.AddCommand(doCmd)
doCmd.PersistentFlags().String("cron", "", "The cron expression to run in daemon mode")
_ = viper.BindPFlag(configCron, doCmd.PersistentFlags().Lookup("cron"))
doCmd.PersistentFlags().Bool("runOnStart", true, "Run the sync job on start.")
_ = viper.BindPFlag(configRunOnStart, doCmd.PersistentFlags().Lookup("runOnStart"))
doCmd.PersistentFlags().Int("api-port", 8080, "Sync API Port, the API endpoint will be started to enable remote triggering; if 0 port API is disabled.")
_ = viper.BindPFlag(configAPIPort, doCmd.PersistentFlags().Lookup("api-port"))
doCmd.PersistentFlags().String("api-username", "", "Sync API username")

View file

@ -51,7 +51,9 @@ func Sync(cfg *types.Config) error {
} else {
w.cron.Run()
}
} else {
}
if cfg.RunOnStart {
l.With("version", version.Version).Info("Run on startup")
w.sync()
}
if cfg.API.Port != 0 {

View file

@ -13,11 +13,12 @@ const (
// Config application configuration struct
type Config struct {
Origin AdGuardInstance `json:"origin" yaml:"origin"`
Replica AdGuardInstance `json:"replica,omitempty" yaml:"replica,omitempty"`
Replicas []AdGuardInstance `json:"replicas,omitempty" yaml:"replicas,omitempty"`
Cron string `json:"cron,omitempty" yaml:"cron,omitempty"`
API API `json:"api,omitempty" yaml:"api,omitempty"`
Origin AdGuardInstance `json:"origin" yaml:"origin"`
Replica AdGuardInstance `json:"replica,omitempty" yaml:"replica,omitempty"`
Replicas []AdGuardInstance `json:"replicas,omitempty" yaml:"replicas,omitempty"`
Cron string `json:"cron,omitempty" yaml:"cron,omitempty"`
RunOnStart bool `json:"runOnStart,omitempty" yaml:"runOnStart,omitempty"`
API API `json:"api,omitempty" yaml:"api,omitempty"`
}
// API configuration