Install on Linux#
crushbalance_init.sh is the control script for Linux and BSD. The host needs no Java: see step 3.
-
Copy
CrushBalance.jarandcrushbalance_init.shinto the install folder,CRUSH_DIR(the script's default is/var/opt/CrushBalance/). -
Check the settings at the top of
crushbalance_init.sh:CRUSH_DIR: the install folder;CRUSH_USER: the user CrushBalance runs as (rootby default; see "Run as a non-root user" below);JAVA:javameans the folderJavain the install folder when there is one, otherwise the system'sjava. Give a full path (for exampleJAVA="/usr/lib/jvm/temurin-25/bin/java") to use exactly that Java;JAVA_OPTS: the Java options, the heap first (-Xmx1024M, Capacity and tuning);MAX_OPEN_FILES: the open-file limit CrushBalance gets (1048576 as delivered);OWN_JAVAandJAVA_API: CrushBalance's own Java, below.
-
As root, run
./crushbalance_init.sh install. It registers the servicecrushbalance, enables it at boot and starts it:- on a systemd host it writes
/etc/systemd/system/crushbalance.service: Java runs as the service's own process, asCRUSH_USER, withLimitNOFILEfromMAX_OPEN_FILES,Restart=alwaysandRestartSec=5; - otherwise it links
/etc/init.d/crushbalanceto the script and registers it withchkconfigorupdate-rc.d(BSD: anrc.dscript); INIT_SYSTEMat the top of the script (systemd,sysvorbsd) decides where the script cannot tell.- No Java needed. When the host has no Java 21 or newer, the first start downloads Eclipse Temurin's JRE into
CRUSH_DIR/Java, andinstallsays so. It needscurlorwget, and HTTPS toapi.adoptium.netandgithub.com.
From then on:
./crushbalance_init.sh start|stop|restart|status|info.statusprints the service file andCrushBalance is running [pid …], orCrushBalance is not running.with exit code 3.stopwaits until the process has exited, which normally takes about 4 seconds; one that is still there afterSTOP_WAIT, 30 s, is killed.infoshows the system, the Java in use and the settings.- On a systemd host prefer
systemctl start|stop|restart crushbalance, so systemd knows the state. A process stopped outside systemd is started again 5 seconds later (Restart=always). startrefuses a Java older than 21 ("CrushBalance needs Java 21 or later (Java 25 or later is recommended), but … is Java …") and warns below 25.
- on a systemd host it writes
-
The script starts
java -Ddir=$CRUSH_DIR -Xmx1024M -XX:-UseBASE64Intrinsics -jar CrushBalance.jar -dinCRUSH_DIR. On the first start CrushBalance createsprefs.XML,crushbalance.key, the admin certificate and the setup token.- The token is in
CRUSH_DIR/setup-token.txt. - It is also in the console output with the admin URL and the certificate fingerprint: in the journal under systemd (
journalctl -u crushbalance), or inCRUSH_DIR/nohup.outwhen the script was started from a terminal. - Continue with First-run setup.
- The token is in
- Headless password instead of the token. Run
java -jar CrushBalance.jar -set-admin-passwordinCRUSH_DIR, as the user the service runs as. It prompts twice without echo (or reads one line from stdin when not on a terminal). It works before the first start (it createsprefs.XML) and while CrushBalance runs (applied within about 2 seconds). Setup then ends and the token file is deleted. - Run as a non-root user (recommended). It is one setting,
CRUSH_USER:- Create the user, for example
useradd --system --shell /usr/sbin/nologin crushbalance. - Set
CRUSH_USER="crushbalance"in the script. - Give the user the folder:
chown -R crushbalance: /var/opt/CrushBalanceandchmod 700 /var/opt/CrushBalance. - As root, run
./crushbalance_init.sh install.
- The systemd unit then has
User=crushbalanceandAmbientCapabilities=CAP_NET_BIND_SERVICE: CrushBalance runs as that user and may still open ports below 1024. - From then on, manage the service with
systemctl. Never runcrushbalance_init.shas root while the folder belongs to the service user: that user can replace the script, and root would run whatever it then holds. To uninstall later, stop the service, give the folder back to root (chown -R root: /var/opt/CrushBalance), look at the script, then run./crushbalance_init.sh uninstall. - Keystores you add later (for example the certbot PKCS12 file of Operating) must be readable by that user.
- Without systemd,
startrun by root starts CrushBalance asCRUSH_USER(withsu, so the user needs a login shell), but nothing gives that user the ports below 1024: use high ports in CrushBalance and redirect to them (iptables -t nat -A PREROUTING -p tcp -m tcp --dport 21 -j REDIRECT --to-ports 2121). - Run every CLI command (
-set-admin-password,-check-config) as that user too, so the files keep their owner.
- Create the user, for example
- A copy of the script from CrushBalance 11 still starts CrushBalance 27 when its
JAVAis Java 21 or newer, but it downloads no Java and has the oldinstalland settings. Replace it (Upgrading).
CrushBalance's own Java#
CrushBalance can bring its own Java and keep it up to date: Eclipse Temurin's JRE, the newest LTS, downloaded from Adoptium into the folder Java of the install folder. It is the same on Windows and macOS, where CrushBalance.exe and CrushBalance.app do what the script does here.
- Whose Java. Only a
Javafolder that CrushBalance downloaded is CrushBalance's: it holds the filecrushftp-java.txt. A Java of the system, one you name withJAVA=, and aJavafolder you put there yourself are used as they are and never changed. - The first start. With no Java 21 or newer on the host, the script downloads the JRE, checks it against the SHA-256 that Adoptium publishes, and starts CrushBalance on it. With
OWN_JAVA="true"at the top of the script it does so although the host has a Java. - Updates. Running on its own Java, CrushBalance asks Adoptium for the newest LTS two minutes after its start and then every 12 hours. A newer one is downloaded into
Java.newbeside the one in use, gets your changes tocacerts,java.securityandkrb5.conf, and is started once as a test. The log says when it is ready. - CrushBalance never restarts itself for a new Java, because a restart ends every connection. The new Java is put in place at the next start, whenever you make it; the one before stays as
Java.olduntil CrushBalance is up. - A new Java that does not start is taken back out, the Java before it is used, and that release is not tried again (it is written to
java_badin the install folder). - Network. HTTPS to
api.adoptium.netandgithub.com(and where GitHub sends its downloads). A host that reaches neither stays on the Java it has.JAVA_APIin the script names a copy of Adoptium's API in your own network. - Turning it off. Install Java 21 or newer on the host and remove the
Javafolder while CrushBalance is stopped, or name a Java withJAVA=. Keeping that Java current is then yours again.