One of the most tedious aspects of rebooting a server that’s hosting many VMs is having to log in to each guest after and ensure the proper services have started back up. Most common services ship with some sort of boot script these days, such as Apache, MySQL, Grafana, etc. Today, I finally set up the Chia fullnode software to start on-boot using a new systemd service entry. It turns out it was significantly easier than I anticipated and only took a few minutes to complete.
These are the steps that I followed on my Oracle Linux 8.6 server. The same steps would also apply to CentOS 8 and RedHat 8.
Step 1: Create a new service entry (file) in systemd for Chia
[root@chianode ~]# vim /etc/systemd/system/chia.service
[Unit] Description=Chia Service [Service] Type=forking User=chia WorkingDirectory=/home/chia/chia-blockchain ExecStart=/usr/bin/bash -c ". ./activate && chia start farmer && deactivate" ExecStop=/usr/bin/bash -c ". ./activate && chia stop all -d && deactivate" [Install] WantedBy=multi-user.target
In the example above, I have the Chia software running under the chia user with a home directory of /home/chia. I’m starting the farmer, which includes all services necessary to farm such as the full node. You can edit the code to reflect your environment and/or software needs.
Step 2: Reload systemctl to pick up our new service file. This will also need run any time you make changes to the above file.
[root@chianode ~]# systemctl daemon-reload
Step 3: Start the service and enable it to run on-startup.
[root@chianode ~]# systemctl enable chia Created symlink /etc/systemd/system/multi-user.target.wants/chia.service → /etc/systemd/system/chia.service. [root@chianode ~]# systemctl start chia
It’s that easy!! I should have done this a long time ago… This will also allow you to stop the services easily as well.
systemctl stop chia
And you can easily check whether or not they started successfully.
[root@chianode ~]# systemctl status chia ● chia.service - Chia Service Loaded: loaded (/etc/systemd/system/chia.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2022-10-29 20:23:11 EDT; 31s ago Process: 3547 ExecStart=/usr/bin/bash -c . ./activate && chia start farmer && deactivate (code=exited, status=0/SUCCESS) Main PID: 3556 (chia_daemon) Tasks: 38 (limit: 48842) Memory: 868.8M CGroup: /system.slice/chia.service ├─3556 chia_daemon ├─3570 chia_harvester ├─3571 chia_farmer ├─3572 chia_full_node ├─3573 chia_wallet ├─3617 chia_wallet_worker ├─3620 chia_full_node_worker ├─3623 chia_full_node_worker ├─3624 chia_full_node_worker └─3627 chia_full_node_worker Oct 29 20:23:07 chianode.home.lcl systemd[1]: Starting Chia Service... Oct 29 20:23:11 chianode.home.lcl bash[3548]: Daemon not started yet Oct 29 20:23:11 chianode.home.lcl bash[3548]: Starting daemon Oct 29 20:23:11 chianode.home.lcl bash[3548]: chia_harvester: started Oct 29 20:23:11 chianode.home.lcl bash[3548]: chia_farmer: started Oct 29 20:23:11 chianode.home.lcl bash[3548]: chia_full_node: started Oct 29 20:23:11 chianode.home.lcl bash[3548]: chia_wallet: started Oct 29 20:23:11 chianode.home.lcl systemd[1]: Started Chia Service.
Lastly, any time I set something like this up, I always give the server a quick restart to ensure it starts on it’s own and does so correctly without error. Hopefully this helps!