mirror of
https://github.com/bakito/adguardhome-sync.git
synced 2025-01-07 15:49:13 +08:00
run on startup #10
This commit is contained in:
parent
3edb5222d6
commit
2e93920931
5 changed files with 17 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -14,7 +14,8 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
configCron = "cron"
|
||||
configCron = "cron"
|
||||
configRunOnStart = "runOnStart"
|
||||
|
||||
configAPIPort = "api.port"
|
||||
configAPIUsername = "api.username"
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue