Skip to content

Instantly share code, notes, and snippets.

@dkackman
Last active July 3, 2023 03:00
Show Gist options
  • Save dkackman/517739d1affc9403c2bc8ce4c1125917 to your computer and use it in GitHub Desktop.
Save dkackman/517739d1affc9403c2bc8ce4c1125917 to your computer and use it in GitHub Desktop.
chia systemd service unit defintion
#!/bin/bash
#
# if no parameters are supplied this results in:
# . ~/chia-blochain/activate
# chia start farmer
#
if [ -z "$1" ]
then
operation=start
else
operation=$1
fi
if [ -z "$2" ]
then
chia_location=~/chia-blockchain
else
chia_location=$2
fi
if [ -z "$3" ]
then
services=farmer
else
services=$3
fi
if [ ! -d "$chia_location" ]
then
echo "chia not found: $chia_location"
exit 1
fi
# enter the venv
. $chia_location/activate
# start/stop/reload services
if [ "$operation" == "start" ]
then
chia start $services
elif [ "$operation" == "stop" ]
then
chia stop all -d
elif [ "$operation" == "reload" ]
then
chia start $services -r
else
echo "Unrecognized operation $operation"
exit 1
fi
[Unit]
Description=Chia services
Requires=network.target
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/chia start /home/USERNAME/chia-blockchain farmer
ExecStop=/usr/local/bin/chia stop /home/USERNAME/chia-blockchain
ExecReload=/usr/local/bin/chia reload /home/USERNAME/chia-blockchain farmer
User=USERNAME
[Install]
WantedBy=multi-user.target
@jcardenasy0810
Copy link

jcardenasy0810 commented Sep 19, 2021

On my Raspberry Pi I installed Chia using the ARM deb package, and, In order to autostart services in Raspberry PI, I've to do this:

create the service:

$ cd /etc/systemd/system && sudo nano chia.service

Past the following code:

[Unit]
Description=Chia Services
Requires=network.target
After=network.target

[Service]
Type=forking
ExecStart=/lib/chia-blockchain/resources/app.asar.unpacked/daemon/chia start farmer
ExecStop=/lib/chia-blockchain/resources/app.asar.unpacked/daemon/chia stop
ExecReload=/lib/chia-blockchain/resources/app.asar.unpacked/daemon/chia reload farmer
User=pi 
 
[Install]
WantedBy=multi-user.target

Then, Must execute the mentioned systemctl commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment