jsyncd v1.0.5
Jsyncd
jsyncd is a daemon aimed at simplifying syncing real time file changes to local directories or remote hosts.
Why?
- Configure multiple apps to sync to various local and/or remote directories.
- Goal to support macOS, Windows, and Linux by using
Chokidaras a unified file monitoring watcher. - More simple configuration options when compared to
Lsyncd. - Better console output with color coded logging for ease of understanding when the program is not daemonized.
How
This program works by monitoring config.appConfigs.directories.source for file system changes using the chokidar module and firing off a dynamically built Rsync.build commands.
This program manages configuration options for both rsync and chokidar to customize your live file mirroring needs.
Getting started
Install with npm:
npm install -g jsyncdIf installed globally, run with:
jsyncd /path/to/config.mjsNote: If the config file path is specified, it must be the last option passed to the jsyncd command.
Or place the config file in ~/.config/jsyncd/config.mjs and run with:
jsyncdCLI Options
CLI Options override settings that are also defined in the config file.
-l, --log FILE Log file path
-k, --kill[=CONTINUE]
Kill any running jsyncd processes and exit, true value continues program
-h, --help Display this help message
-v, --version Display version information and exit
-d, --daemon Detach and daemonize the process
-i, --ignore Pass `ignoreInitial` to `chokidarWatchOptions`, skips startup sync
-D, --debug Log the generated `Rsync.build` commandConfig File
The configuration file is the core of instructing jsyncd how to sync what files from where to who and where. The configuration file is a javascript module that exports a variable called config.
The config file can be customized to build your synchronization configs dynamically via plain javascript.
A default config file can be placed in ~/.config/jsyncd/config.mjs. A template can be found in config_example.mjs.
Options
- logFile - (default:
/var/log/jsyncd/jsyncd.log) Path to where STDOUT will be redirected. Required whendaemonizeistrue. - daemonize - (default:
false) Detach process and run program as daemon. - debug - (default:
false) Output the generated rsync command. Can help with debugging theRsync.buildcommand. - rsyncBuildOptions - (default:
{}) These are key value pairs passed to theRsync.buildfunction. The ones provided here are for example. All options from rsync are supported.- flags - (default:
''OR[]) Optional: pass to theRsync.flags. Typical defaults may includeafor archive andito log individual files as they sync to theconfig.logFile. - exclude - (default:
[]) Optional: passed to theRsync.excludefunction. Folders and files for rsync to ignore under thesourcedirectory. Specifying here will be a default for all sources.
- flags - (default:
- appConfigs - (default:
[{}]) An array of objects where eachappConfigdefines a host -> remote server connection and path monitoring options.- name - (default:
'') Optional: Give your app a name. It'll show up in the logs when this app syncs to give you further insight on what is actively syncing. - rsyncBuildOptions - (default:
{}) Overide the globalRsync.buildoptions for this app. Specified keys replace higher up keys. - targetHostname - (default:
'') Optional: IP Address or domain of target. - targetUsername - (default:
'') Optional: ssh username if not configured with ~/.ssh/config.targetHostnameis required if this is specified. - sshOptions - (default:
{}) Optional: Configure a non-standard ssh options such as port and/or an private key file. Options must have key/value pairs that match key/values in the ssh manual. These options build thersync --rsh "ssh -i {/path/to/privkey} -p {port}"command. - directories - (default:
[{}]) An array of objects that configure local -> target directory syncs. Each key/value pair in each element of each object is passed toRsync.buildand is arsyncBuildOptionsconfiguration.- source - (required) Path to watch for changes and sync to
destination. A trailing slash on the directory will sync the contents such as/path/*. No trailing slash copies the entire directory. - destination - (required) Path to where
rsyncshould send the files. - exclude - (default: []) Optional: Specify specific exclude files/folders for this source to exclude.
- source - (required) Path to watch for changes and sync to
- chokidarWatchOptions - (default:
{}) May be any supportedchokidaroptions and passed asoptionstochokidar.watch(paths, [options]). Common parameters may beignoreInitialandignoredthough there are many other options such as setting up polling instead of event based callbacks.
- name - (default:
Note: rsyncBuildOptions cascade from the top level down to the directories level with the most specific key/value pair being what is passed to Rsync.build.
This allows you to set global defaults, app defaults, and override specific directories with unique settings. For instance, if all your hosts have the same rsyncExcludePattern, you can set that value at the config.rsyncExcludePattern level. However, setting that again at a config.appConfig or config.appConfig.directories level will override a higher up setting.
Note2: chokidarWatchOptions cascades from the top level down to the appConfigs level with the most specific key/value paris being what is passed to chokidar.watch(paths, [options])
Minimal config.mjs Example
Following is a minimal example to get started. This config will sync the contents of /var/folder1/ into the directory /var/folder2/.
let config = {
appConfigs: [{
directories: [{
source: '/var/folder1/',
destination: '/var/folder2/',
}]
}]
};
export default config;Goals
Configuring multiple virtualbox environments with different projects became unwieldy so I was looking for a way to easily configure each target with a different set of rules for live file monitoring.
Originally, I had used the lsyncd project which worked fine, but I found myself writing LUA in order to set up these rules until I built a program to manage lsyncd configurations. This wasn't ideal since the configuration was in LUA and I had no prior experience and not much desire to learn LUA.
Additionally, lsyncd has, at best, flakey support on macOS depending on the macOS version and no support on Windows without a solution such as WSL or cygwin. jsyncd solves these problems by using the rsync and chokidar libraries for cross platform compatability bundled into one unified synchronization configuration tool.
Additional
If you are doing frequent syncs to a remote host and need the changes to appear very quickly (such as debugging code!) you can consider using a shared ssh system connection to avoid the startup time of connecting via ssh.
To configure a semi-persistant ssh connection, add these example configurations to your ~/.ssh/config file:
HOST <targetHostname>
ControlMaster auto
ControlPath ~/.ssh/ssh-%r@%h:%p
ControlPersist 180011 months ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago