Compare commits

...

5 Commits

Author SHA1 Message Date
bakito
5dafdf5472 change output paths 2021-03-28 20:28:58 +02:00
bakito
23d5f30eb8 add systemd script 2021-03-28 20:25:25 +02:00
bakito
44609a93e3 correct logger name 2021-03-28 20:00:22 +02:00
bakito
70e60bb7d0 use external semver 2021-03-28 19:31:11 +02:00
bakito
aacffb1518 document config file 2021-03-28 17:04:41 +02:00
8 changed files with 86 additions and 56 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,5 @@
.idea
coverage.out
dist
adguardhome-sync
main

View File

@@ -20,10 +20,15 @@ test: tidy fmt vet
go test ./... -coverprofile=coverage.out
go tool cover -func=coverage.out
release:
@version=$$(go run version/semver/main.go); \
release: semver
@version=$$(semver); \
git tag -s $$version -m"Release $$version"
goreleaser --rm-dist
test-release:
goreleaser --skip-publish --snapshot --rm-dist
goreleaser --skip-publish --snapshot --rm-dist
semver:
ifeq (, $(shell which semver))
$(shell go get -u github.com/bakito/semver)
endif

View File

@@ -33,4 +33,38 @@ adguardhome-sync run
# run as daemon
adguardhome-sync run --cron "*/10 * * * *"
```
```
### Config file
location: $HOME/.adguardhome-sync.yaml
```yaml
# cron expression to run in daemon mode. (default; "" = runs only once)
cron: "*/10 * * * *"
origin:
# url of the origin instance
url: https://192.168.1.2:3000
# apiPath: define an api path if other than "/control"
# insecureSkipVerify: true # disable tls check
username: username
password: password
# replica instance (optional, if only one)
replica:
# url of the replica instance
url: http://192.168.1.3
username: username
password: password
# replicas instances (optional, if more than one)
replicas:
# url of the replica instance
- url: http://192.168.1.3
username: username
password: password
- url: http://192.168.1.4
username: username
password: password
```

View File

@@ -15,8 +15,7 @@ var doCmd = &cobra.Command{
Short: "Start a synchronisation from origin to replica",
Long: `Synchronizes the configuration form an origin instance to a replica`,
Run: func(cmd *cobra.Command, args []string) {
logger = log.GetLogger("root")
logger = log.GetLogger("run")
cfg := &types.Config{}
if err := viper.Unmarshal(cfg); err != nil {
logger.Error(err)

View File

@@ -19,7 +19,7 @@ func init() {
Development: false,
Encoding: "console",
EncoderConfig: zap.NewDevelopmentEncoderConfig(),
OutputPaths: []string{"stderr"},
OutputPaths: []string{"stdout"},
ErrorOutputPaths: []string{"stderr"},
}

View File

@@ -0,0 +1,28 @@
[Unit]
Description=AdGuard Home Sync service
ConditionFileIsExecutable=/opt/AdGuardHomeSync/adguardhome-sync
Requires=network.target
After=network-online.target syslog.target
[Service]
StartLimitInterval=5
StartLimitBurst=10
ExecStart=/opt/AdGuardHomeSync/adguardhome-sync "run" "--config" "/opt/AdGuardHomeSync/adguardhome-sync.yaml"
WorkingDirectory=/opt/AdGuardHome
Restart=on-success
SuccessExitStatus=1 2 8 SIGKILL
RestartSec=120
EnvironmentFile=-/etc/sysconfig/GoServiceExampleLogging
StandardOutput=file:/var/log/AdGuardHomeSync.out
StandardError=file:/var/log/AdGuardHomeSync.err
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target

11
systemd/README.md Normal file
View File

@@ -0,0 +1,11 @@
# Install
```bash
mkdir -p /opt/AdGuardHomeSync/
sudo cp adguardhome-sync /opt/AdGuardHomeSync/adguardhome-sync
sudo cp adguardhome-sync.yaml /opt/AdGuardHomeSync/adguardhome-sync.yaml
sudo cp AdGuardHomeSync.service /etc/systemd/system/AdGuardHomeSync.service
sudo systemctl enable AdGuardHomeSync
```

View File

@@ -1,49 +0,0 @@
package main
import (
"bufio"
"fmt"
"os"
"os/exec"
"strings"
"github.com/coreos/go-semver/semver"
)
func main() {
out, err := exec.Command("git", "branch", "--show-current").Output()
if err != nil {
panic(err)
}
branch := strings.TrimSpace(string(out))
if branch != "main" {
panic(fmt.Errorf(`error: must be in "master" branch, current branch: %q`, branch))
}
out, err = exec.Command("git", "describe").Output()
if err != nil {
panic(err)
}
version := strings.TrimPrefix(strings.TrimSpace(string(out)), "v")
v := semver.New(version)
v.BumpPatch()
reader := bufio.NewReader(os.Stdin)
if _, err = fmt.Fprintf(os.Stderr, "Enter Release Version: [v%v] ", v); err != nil {
panic(err)
}
text, err := reader.ReadString('\n')
if err != nil {
panic(err)
}
if strings.HasPrefix(text, "v") {
text = text[1:]
v = semver.New(strings.TrimSpace(text))
}
if _, err = fmt.Fprintf(os.Stderr, "Using Version: v%v\n", v); err != nil {
panic(err)
}
fmt.Printf("v%v", v)
}