# Service mode

On a machine where nobody logs in, such as a server whose folder should stay in sync, run CrushSync as a background service instead of as a tray app.

A service has no tray icon and no window. Set CrushSync up with the app first, then hand its settings to the service.

## Windows

1. Install the app, enter the server and login, and set up the syncs ([First connection](First-Connection.md)). Check that they run.
2. In the tray menu, untick **Start with Login**, then **Quit** CrushSync.
3. Open an elevated Command Prompt or PowerShell, go to the program's `resources` folder, usually `C:\Users\<you>\AppData\Local\Programs\CrushSync\resources`, and make sure the service finds your settings: copy `prefs.XML` from the settings folder `%LOCALAPPDATA%\CrushSync\` into this folder.
4. Install the service:

   ```
   .\Java\bin\java.exe -jar CrushTunnel.jar inline_script "service sync;quit"
   ```

5. Check it in the **Services** console, or with `sc query`.

To remove the service:

```
.\Java\bin\java.exe -jar CrushTunnel.jar inline_script "service remove sync;quit"
```

**With the jar from the server instead.** You can also take `CrushTunnel.jar` from your CrushMFT server's `WebInterface` folder into a folder of your choice, with a Java of your own, and run the same command there. Copy your working `prefs.XML` into that folder first, since a service has no tray icon to set it up with.

To run more than one, each from its own folder, add `_` and a name: `service sync_-Archive` and `service remove sync_-Archive`.

## macOS: the file watcher

If changes on a Mac are only picked up at the next comparison instead of at once, install CrushSync's file watcher. It is a small system service that tells CrushSync about changes in real time, and it is installed once.

Decide where `CrushSync.app` stays (do not move or rename it afterwards), then in Terminal:

```
cd /Applications/CrushSync.app/Contents/Resources/
sudo Java/bin/java -cp CrushTunnel.jar com.crushftp.client.CrushSyncFSWatchServer -i
```

Enter your administrator password. To remove the watcher later, run the same command with `-r` instead of `-i`.

## Things to know

- The service syncs as the user whose `prefs.XML` you copied, to the folders named in it. Make sure the account the service runs under can read and write those folders.
- To change the syncs, stop the service, change them with the app, copy `prefs.XML` again, and start the service.
- The log is written next to `prefs.XML`.
