Skip to content

Commit

Permalink
fix DB dir and add local hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Corya committed Mar 20, 2024
1 parent cdec979 commit 0c0b89e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ COPY nsswitch.conf /etc/nsswitch.conf

# default ENV
ENV CSYNC2_AUTO=younger
ENV CSYNC2_DB=/var/lib/csync2/favre.db
ENV CSYNC2_DB_DIR=/var/lib/csync2
ENV CSYNC2_SYSTEM_DIR=/run/csync2
ENV FAVRE_DEBOUNCE_DELAY=2000

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Favre is a wrapper around [Csync2](https://github.com/LINBIT/csync2/blob/master/
## Configuration
Many of the configuration options available for Csync2 are available for Favre. These environmental variables will be rendered into a file `/run/csync2/csync2.cfg` prior to running `csync2`.

`CSYNC2_DB`: advised to persist with docker volume, default `/var/lib/csync2/favre.db`
`CSYNC2_DB_DIR`: advised to persist with docker volume, default `/var/lib/csync2`

`CSYNC2_KEY_FILE`: mandatory, no default, should be stored as a docker secret

Expand Down
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ const { spawn, execFileSync } = require ('node:child_process');
const watch = require ('node-watch');
const Mustache = require ('mustache');
const fs = require('node:fs');
const os = require('node:os');

if (!process.env.CSYNC2_KEY_FILE) {
console.error ('CSYNC2_KEY_FILE must be set');
process.exit (1);
}

// start the csync2 daemon
const csync2d = spawn ('csync2', ['-ii', '-vvv', '-D', process.env.CSYNC2_DB_FILE], {
const csync2d = spawn ('csync2', ['-ii', '-vvv', '-D', process.env.CSYNC2_DB_DIR], {
stdio: ['ignore', 'inherit', 'inherit']
})
});

// mustache things
const cfgTemplate = `
Expand Down Expand Up @@ -80,7 +81,7 @@ async function sync () {
taskLookups.push (dns.reverse (record.address));
}
// get resolvable task hosts
let hosts = [];
let hosts = [os.hostname()];
let tasks = await Promise.all (taskLookups);
for (let task of tasks) {
hosts.push (task[0]);
Expand All @@ -94,7 +95,7 @@ async function sync () {
console.log ('Writing config file', configFile);
fs.writeFileSync (`${process.env.CSYNC2_SYSTEM_DIR}/csync2.cfg`, configFile);
// execute the synchronization
execFileSync ('csync2', ['-x', '-r', '-vvv', '-D', process.env.CSYNC2_DB]);
execFileSync ('csync2', ['-x', '-r', '-vvv', '-D', process.env.CSYNC2_DB_DIR]);

}
}
Expand Down

0 comments on commit 0c0b89e

Please sign in to comment.