User Tools

Site Tools


guides:farming:chia_autostart_linux

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
guides:farming:chia_autostart_linux [2021/09/06 11:59] – Show correct filename ajguides:farming:chia_autostart_linux [2023/08/13 15:43] (current) – old revision restored vleesbanaan
Line 3: Line 3:
 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). 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 Chia startup script =====+===== Step 1 - Create the Chia service =====
  
-Use your preferred editor to create the following text file and save it (egstartchia.sh)+Create the Chia service''sudo nano /etc/systemd/system/chia@.service'' and paste the following service:
  
-//Note: Replace {USERNAME} with the name of the user having Chia installed. +//Note: Replace {USERNAME} (2x) with the name of the user having Chia installed.
-//<code> +
-#!/bin/bash +
-/usr/bin/env bash -c 'cd /home/{USERNAME}/chia-blockchain && . ./activate && chia start farmer' 2>/dev/null +
-</code> +
- +
-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.+
 //<code> //<code>
 [Unit] [Unit]
Line 25: Line 13:
 [Service] [Service]
 Type=forking Type=forking
-RemainAfterExit=no +User={USERNAME
-User={username+WorkingDirectory=/home/{USERNAME}/chia-blockchain 
-WorkingDirectory=/home/{username}/chia-blockchain +ExecStart=/usr/bin/bash -c "./activate && chia start %i && deactivate" 
-ExecStart=/home/{username}/startchia.sh+ExecStop=/usr/bin/bash -c ". ./activate && chia stop -d all && deactivate"
 Restart=always Restart=always
 [Install] [Install]
Line 34: Line 22:
 </code> </code>
  
-===== Step Enable the Chia service =====+===== Step Reload systemd manager =====
  
-You should now be able to see the service with ''sudo systemctl status chia'':+Reloading the systemd manager is needed to work with our new service.
  
 <code> <code>
-sudo systemctl status chia +sudo systemctl daemon-reload
-● chia.service Chia Service +
-   Loaded: loaded (/etc/systemd/system/chia.service; disabled; vendor preset: enabled) +
-   Active: inactive (dead)+
 </code> </code>
  
-  * Enable the service by running: ''sudo systemctl enable chia'' +===== Step 3 - Enable the Chia service ===== 
-  * Start the service by running''sudo systemctl start chia''+ 
 +The service can take an argument after the '@'. Use this argument to start the required chia service. 
 + 
 +For example, to enable the farmer:
  
-Running ''sudo systemctl status chia'' will now give the following output: 
 <code> <code>
-sudo systemctl status chia +sudo systemctl enable --now chia@farmer 
-● chia.service Chia Service +</code>
-   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... +Running ''sudo systemctl status chia@farmer'' will now give the following output: 
-Sep 06 13:41:42 debian startfarm.sh[492]: Daemon not started yet +<code> 
-Sep 06 13:41:42 debian startfarm.sh[492]: Starting daemon +$ systemctl status [email protected]  
-Sep 06 13:41:42 debian startfarm.sh[492]: chia_harvester: started +[email protected] - Chia Service 
-Sep 06 13:41:42 debian startfarm.sh[492]: chia_farmer: started +     Loaded: loaded (/etc/systemd/system/[email protected]; enabled; vendor preset: enabled) 
-Sep 06 13:41:42 debian startfarm.sh[492]: chia_full_node: started +     Active: active (running) since Fri 2021-12-10 21:40:53 CET; 21s ago 
-Sep 06 13:41:42 debian startfarm.sh[492]: chia_wallet: started +    Process: 13500 ExecStart=/usr/bin/bash -c . ./activate && chia start farmer && deactivate (code=exited, status=0/SUCCESS) 
-Sep 06 13:41:42 debian systemd[1]: Started Chia Service.+   Main PID: 13514 (chia_daemon) 
 +      Tasks: 17 (limit: 9278) 
 +     Memory: 1.4G 
 +     CGroup: /system.slice/system-chia.slice/[email protected] 
 +             ├─13514 chia_daemon 
 +             ├─13520 chia_harvester 
 +             ├─13521 chia_farmer 
 +             ├─13522 chia_full_node 
 +             └─13523 chia_wallet 
 + 
 +Dec 10 21:40:47 chia systemd[1]: Starting Chia Service... 
 +Dec 10 21:40:53 chia bash[13501]: Daemon not started yet 
 +Dec 10 21:40:53 chia bash[13501]: Starting daemon 
 +Dec 10 21:40:53 chia bash[13501]: chia_harvester: started 
 +Dec 10 21:40:53 chia bash[13501]: chia_farmer: started 
 +Dec 10 21:40:53 chia bash[13501]: chia_full_node: started 
 +Dec 10 21:40:53 chia bash[13501]: chia_wallet: started 
 +Dec 10 21:40:53 chia systemd[1]: Started Chia Service.
 </code> </code>
  
-It should say "Active: active" and "enabled" in the Loaded section. When you reboot the system, Chia should automatically start up.+It should say "Active: active" and "enabled" in the Loaded section.  
 + 
 +From now on, when you reboot the system, Chia should automatically start up.
guides/farming/chia_autostart_linux.1630929597.txt.gz · Last modified: 2021/09/06 11:59 by aj

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki