Hey all! I run a linux server and every service on the machine so far is run through a systemd script.
I tried doing one for Chia but it is NOT working out. I think it has to do with the whole venv thing.
I’ve Googled the topic and even the solutions pitched in these topics.
The two most common issues I run into:
The services keep restarting. Watching my console output, I see all my Chia services (wallet, node, etc.) come online, immediately followed by another message saying they are all coming online. This restarts forever AFAIK.
When trying to write a systemd script that directly uses the chia binary in git-repo/venv/bin/chia, I would typically see “failed to start” next to every service I was trying to start.
If not, you may need to post your script to get more help. You can start chia multiple ways, I have been using the chia start farmer version, which starts the required daemons and then exits. This requires setting the correct type in systemd service. Assuming you’ve got that figured out, I’ve setup many python virutalenvs, and your strategy of using the explicit binary (err script) will work. Something like /home/me/chia/venv/bin/chia farmer start will execute with the correct python libraries.
My suggestions:
Check the user you are starting the service as. Chia expects a ~/.chia and ~/.local to exist and to contain the chia db state and your signing keys. If those do not exist for the user that is starting the process, chia will just bomb saying it is not initialized.
Turn on file logging to get output, there might be more info in there.
[]$ cat ~/scripts/starter.sh
#!/bin/bash
#.... other stuff I start..
screen -dm -S chia bash -c "/home/'your username'/scripts/chia.sh; exec bash"
As you can see, I start chia in a screen so I can go there and check farming, logs…
“screen -rd chia” takes you to the screen. [Ctrl+A D] detaches you from the screen.
Just remember that the first time you attach to that screen you have to go through “. activate” to be able to issue chia commands.
Wow, great stuff, I’ll actually try this out tomorrow. A few initial thoughts:
I wouldn’t use screen here, that may be causing the issue. You probably don’t want your logs going to stdout, services typically write to a logfile or the syslog, and chia will do this for you. Update your chia config.yaml to make sure it’s sending logs to a file, and you should get them at ~/.chia/mainnet/logs.
With that said, I think the starter.sh script is all you need, something like this should do it:
#!/bin/bash
# this should point to the chia script in the bin directory of your virtual env
/home/abc/chia-blockchain/venv/bin/chia start farmer
Sourcing the activate virtual env script is normally just to get your shell setup, it’s not necessary if you are just starting a python program (I’ve been coding python on and off for ~10 years).