This is an old revision of the document!
Table of Contents
Chia Autostart (Linux)
Running Chia as a service has several benefits, the main one being this always ensures your node / farm is running. Example given: When your farm reboots unexpectedly the service will auto start your farm after boot. You can also use this to autostart only the node or harvester (change the startup script accordingly).
Step 1 - Create a Chia startup script
Use your preferred editor to create the following text file and save it (eg: startchia.sh)
Note: Replace {USERNAME} with the name of the user having Chia installed.
#!/bin/bash /usr/bin/env bash -c 'cd /home/{USERNAME}/chia-blockchain && . ./activate && chia start farmer' 2>/dev/null
After saving use chmod +x startchia.sh
to set the correct permissions. You can now execute the script to test if this starts up your farm: ./startchia.sh
.
Step 2 - Create the Chia service
Create the Chia service: sudo nano /etc/systemd/system/chia.service
and paste the following service:
Note: Replace {USERNAME} (3x) with the name of the user having Chia installed.
[Unit] Description=Chia Service [Service] Type=forking RemainAfterExit=no User={username} WorkingDirectory=/home/{username}/chia-blockchain ExecStart=/home/{username}/startchia.sh Restart=always [Install] WantedBy=multi-user.target
Step 3 - Enable the Chia service
You should now be able to see the service with sudo systemctl status chia
:
$ sudo systemctl status chia ● chia.service - Chia Service Loaded: loaded (/etc/systemd/system/chia.service; disabled; vendor preset: enabled) Active: inactive (dead)
- Enable the service by running:
sudo systemctl enable chia
- Start the service by running:
sudo systemctl start chia
Running sudo systemctl status chia
will now give the following output:
$ sudo systemctl status chia ● chia.service - Chia Service Loaded: loaded (/etc/systemd/system/chia.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2021-09-06 13:41:42 CEST; 1min 41s ago Process: 492 ExecStart=/home/{username}/startchia.sh (code=exited, status=0/SUCCESS) Main PID: 503 (chia_daemon) Tasks: 33 (limit: 4701) Memory: 3.3G CGroup: /system.slice/chia.service ├─ 503 chia_daemon ├─ 708 chia_harvester ├─ 709 chia_farmer ├─ 710 chia_full_node ├─ 711 chia_wallet ├─1263 chia_full_node └─1266 chia_full_node Sep 06 13:41:37 debian systemd[1]: Starting Chia Service... Sep 06 13:41:42 debian startfarm.sh[492]: Daemon not started yet Sep 06 13:41:42 debian startfarm.sh[492]: Starting daemon Sep 06 13:41:42 debian startfarm.sh[492]: chia_harvester: started Sep 06 13:41:42 debian startfarm.sh[492]: chia_farmer: started Sep 06 13:41:42 debian startfarm.sh[492]: chia_full_node: started Sep 06 13:41:42 debian startfarm.sh[492]: chia_wallet: started Sep 06 13:41:42 debian systemd[1]: Started Chia Service.
It should say “Active: active” and “enabled” in the Loaded section. When you reboot the system, Chia should automatically start up.