Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Run the daemon

irsync daemon runs in the foreground and never puts itself in the background. Let a service manager start it, restart it and collect its logs: systemd on Linux, launchd on macOS. Its flags are in Command line.

What it prints

Once startup can no longer fail, the daemon prints these lines on stdout, and prints them again after every reload:

endpoint id: <EndpointId>
listening on: <socket>
debug port: <socket>

When stdout is a terminal, a short banner comes first (version, relay and discovery); it is not printed to a pipe or a file.

There is one listening on: line per bound socket. The debug port: line appears only when debug_addr is set (see Telemetry). A process that starts the daemon can read these lines and dial at once.

Run it as its own account

A daemon that the service manager runs as its own account, here irsync, keeps everything in one directory: /etc/irsync/ on Linux, /usr/local/etc/irsync/ on macOS. There is no /etc lookup, so the daemon gets --config explicitly.

  1. Create the account’s directory, owned by the account:

    install -d -o irsync -g irsync -m 0755 /etc/irsync
    

    The management commands replace a file by writing a new one next to it and renaming it, so the directory must be writable by irsync.

  2. Write /etc/irsync/irsync.toml with the state directory and the daemon’s key. Without these two keys both would default to paths under the account’s home directory:

    state_dir = "/var/lib/irsync"
    
    [daemon]
    identity = "/etc/irsync/daemon_ed25519"
    
  3. Manage the exports as the daemon’s account, with the same --config the daemon gets. For the nouns the flag may stand anywhere after the noun:

    sudo -u irsync irsync export add photos:/srv/photos --config /etc/irsync/irsync.toml
    sudo -u irsync irsync client add myclient <id> --config /etc/irsync/irsync.toml
    sudo -u irsync irsync grant add photos myclient --config /etc/irsync/irsync.toml
    sudo -u irsync irsync config set daemon.listen 0.0.0.0:4433 --config /etc/irsync/irsync.toml
    sudo -u irsync irsync id show --daemon --config /etc/irsync/irsync.toml
    sudo -u irsync irsync show --config /etc/irsync/irsync.toml
    

    The first export add generates the daemon’s key and prints its EndpointId.

Without --config, a management command edits your own ~/.config/irsync/irsync.toml: irsync export add would write your file, generate a stray ~/.config/irsync/daemon_ed25519 and print that key’s id as the daemon’s. Running the commands as irsync also keeps the files owned by the account that reads them; a daemon key generated by root has mode 0600 and the daemon cannot read it. Root can run the same commands with the same flags if it fixes the ownership afterwards.

irsync show and irsync id show -a also load the client key that [defaults] identity names in the same file, and generate it if it is missing.

Do not run it as root

A daemon that receives a push applies the metadata the client sends: permissions, owner, group, device nodes. As root, that lets any client with write access to an export create setuid files owned by root, files owned by other users, and device nodes in it. Run the daemon as an unprivileged account that owns the export trees. Ownership is then applied only where that account may change it, to its own groups, as rsync does without privilege.

The daemon enforces this: started as root, it prints why and exits. It has not had a security audit, so running it as root must be your own choice. To make that choice, start it with --run-as-root-i-know-what-i-am-doing, or set allow_root = true under [daemon] in its config file. It then logs a warning at every start.

irsync pair (see Your first sync) never starts a daemon as root. When the ssh account is root it stops before it installs or changes anything, whatever the server’s config says. Use another account, or set the daemon up by hand as described above.

Run the daemon as a user service

irsync pair makes the daemon a user service, so it keeps running and starts again after a reboot. It writes one of these files, each marked Written by irsync pair:

  • On Linux, ~/.config/systemd/user/irsync.service. pair also turns on loginctl enable-linger, so the service runs when you are not logged in.
  • On macOS, ~/Library/LaunchAgents/org.irsync.daemon.plist, a launchd agent. After a reboot it starts only once someone logs in on the Mac.

The file runs irsync daemon -vv --config with the full paths of the binary and of the server’s config file, so the service finds the same config as pair did.

irsync never changes a service file it did not write. If such a file starts daemon with the same irsync binary that pair installed (as the one in the steps below does), pair uses it as it is. If it starts anything else, pair leaves it alone, starts the daemon in the background instead, and prints the steps below. It does the same on a server with no systemd or launchd user session. irsync pair --no-service, which you pass for a daemon you run your own way, also starts it in the background. A background daemon runs under your account until the server reboots. Nothing starts it again: run irsync pair myserver from the client when it has stopped.

Where the daemon writes its log depends on how it runs. As a systemd service, its output goes to the service manager: journalctl --user -u irsync. The launchd agent on macOS, and a daemon that pair started in the background, write ~/.local/state/irsync/daemon.log.

To make the service yourself, the steps are these.

On Linux, put this in ~/.config/systemd/user/irsync.service:

[Unit]
Description=irsync daemon
[Service]
ExecStart=%h/.local/bin/irsync daemon -vv
Restart=on-failure
[Install]
WantedBy=default.target

Then stop the daemon irsync started and let the service take over:

pid="$(sed -n 's/^pid=//p' ~/.local/state/irsync/daemon.lock)"
kill "$pid"
while kill -0 "$pid" 2>/dev/null; do sleep 0.2; done
systemctl --user enable --now irsync
loginctl enable-linger $USER

loginctl enable-linger lets your user services run when you are not logged in.

On macOS, put this in ~/Library/LaunchAgents/org.irsync.daemon.plist, with your home directory for $HOME:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
  <key>Label</key><string>org.irsync.daemon</string>
  <key>ProgramArguments</key><array><string>$HOME/.local/bin/irsync</string><string>daemon</string><string>-vv</string></array>
  <key>RunAtLoad</key><true/>
  <key>KeepAlive</key><true/>
</dict></plist>

Then stop the daemon irsync started and let the service take over:

pid="$(sed -n 's/^pid=//p' ~/.local/state/irsync/daemon.lock)"
kill "$pid"
while kill -0 "$pid" 2>/dev/null; do sleep 0.2; done
launchctl load -w ~/Library/LaunchAgents/org.irsync.daemon.plist

If the state directory is not the default one, pair prints the path of daemon.lock to use instead. The kill is needed because the lock lets only one daemon run at a time: the service cannot start while the first daemon holds it, so the loop waits until that daemon has exited. These lines are sh syntax; from fish or tcsh, run them under sh.

Under systemd

  1. Write /etc/systemd/system/irsync.service:

    [Unit]
    Description=irsync daemon
    After=network-online.target
    Wants=network-online.target
    
    [Service]
    Type=simple
    ExecStart=/usr/local/bin/irsync daemon -vv --config /etc/irsync/irsync.toml
    ExecReload=/bin/kill -HUP $MAINPID
    Restart=on-failure
    RestartSec=5
    User=irsync
    
    [Install]
    WantedBy=multi-user.target
    

    The User= account needs read access to the export paths, write access to the read-write ones, read access to the key and to irsync.toml, and write access to state_dir.

  2. Start it, and start it at boot:

    systemctl enable --now irsync
    
  3. Follow its log:

    journalctl -u irsync -f
    

systemctl reload irsync applies changed [daemon] settings without a restart.

Under launchd

  1. Write ~/Library/LaunchAgents/org.irsync.daemon.plist:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
      <key>Label</key>
      <string>org.irsync.daemon</string>
      <key>ProgramArguments</key>
      <array>
        <string>/usr/local/bin/irsync</string>
        <string>daemon</string>
        <string>-vv</string>
        <string>--config</string>
        <string>/usr/local/etc/irsync/irsync.toml</string>
      </array>
      <key>RunAtLoad</key>
      <true/>
      <key>KeepAlive</key>
      <true/>
      <key>StandardErrorPath</key>
      <string>/usr/local/var/log/irsync.log</string>
    </dict>
    </plist>
    

    For a daemon that runs as its own account, put the file in /Library/LaunchDaemons instead, add a UserName key naming the account, and manage the exports as in Run it as its own account, with the /usr/local/etc/irsync/ paths.

  2. Load it:

    launchctl load ~/Library/LaunchAgents/org.irsync.daemon.plist
    

launchd has no reload verb. To apply changed [daemon] settings without a restart, send the signal yourself:

kill -HUP $(pgrep -f 'irsync daemon')

Durability

A push writes each file to a temporary name and renames it into place. By default, as in rsync, nothing is flushed to disk explicitly: a power loss or kernel crash in the seconds after a push can leave a file at its name with the right size and time but not its content, which the next quick check does not notice. A client asks for a flush per file with --fsync; an export with fsync = true (irsync config set exports.NAME.fsync true) flushes every push into it whatever the client asked. On a slow disk this costs time: about 30% of a push of 31,000 small files to btrfs on two spinning disks. Like read_only, the setting is read on every connection.

Logs

The daemon logs to stderr; journald and launchd’s StandardErrorPath capture it. The default level is warn: the daemon logs warnings and errors only. -vv gives info logs, which is what a service wants in its journal; -vvv gives debug, -vvvv trace, and -vvvvv trace plus every protocol message, as on the client. -q lowers it to errors only. RUST_LOG overrides all of them, in the tracing filter syntax, for example RUST_LOG=irsync=debug.

Each line of a session carries the session’s span and its fields, as in session{session_id=… side="daemon" …}:transfer: …, which tells concurrent sessions apart.

Stop it

SIGTERM or SIGINT (Ctrl-C) stops the daemon cleanly: it closes its endpoint and flushes its telemetry. SIGTERM is what systemctl stop and launchd send to stop a job. A session cut off this way resumes like any dropped connection. SIGHUP does not stop the daemon; it reloads the settings.

See also