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>

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 grant add photos myclient --config /etc/irsync/irsync.toml
    sudo -u irsync irsync host add myclient <id> --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 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 ssh setup warns when you sign in as root: the daemon it starts then runs as root, and the client’s immediate grant reaches every path on the server.

Keep a daemon started over ssh running

When the ssh setup starts the daemon, it runs in the background under your account until the server reboots. When a later sync gets no answer within about 15 seconds, it starts the daemon again over ssh, but only when you sync. To keep it running all the time, make it a user service. The setup prints these steps for the server’s system; they are the same here.

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

[Unit]
Description=irsync daemon
[Service]
ExecStart=%h/.local/share/irsync/bin/irsync daemon
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/share/irsync/bin/irsync</string><string>daemon</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, the setup 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 --config /etc/irsync/irsync.toml
    ExecReload=/bin/kill -HUP $MAINPID
    KillSignal=SIGINT
    Restart=on-failure
    RestartSec=5
    User=irsync
    Environment=RUST_LOG=info
    
    [Install]
    WantedBy=multi-user.target
    

    KillSignal=SIGINT makes systemctl stop send the signal the daemon shuts down cleanly on (see Stop it). 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, hosts.toml and exports.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/net.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>net.irsync.daemon</string>
      <key>ProgramArguments</key>
      <array>
        <string>/usr/local/bin/irsync</string>
        <string>daemon</string>
        <string>--config</string>
        <string>/usr/local/etc/irsync/irsync.toml</string>
      </array>
      <key>EnvironmentVariables</key>
      <dict>
        <key>RUST_LOG</key>
        <string>info</string>
      </dict>
      <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/net.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 info. -v raises it to debug, -vv to trace, and -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

SIGINT (Ctrl-C) stops the daemon cleanly: it closes its endpoint and flushes its telemetry. systemctl stop sends SIGINT with the unit above. The daemon installs no handler for SIGTERM, which launchd sends to stop a job and which is systemd’s default, so SIGTERM ends the process at once, without that flush. A session cut off either way resumes like any dropped connection. SIGHUP does not stop the daemon; it reloads the settings.

See also