This page documents the process of setting up P2Pool as a service with systemd.
I authored the wrapper script to actually start P2Pool, but I found the solution to using a named pipe and P2Pool service definition in this Reddit post by Krewlar. Kudos to Krewlar for doing the heavy lifting for this solution.
This solution uses two distinct systemd files to start P2Pool.
This file is installed in /etc/systemd/system and is called p2pool.socket. A full listing of the file is shown below:
[Unit]
Description=P2Pool Socket
[Socket]
ListenFIFO=/opt/prod/p2pool/p2pool.stdin
RemoveOnStop=true
[Install]
WantedBy=sockets.target
This file is installed in /etc/systemd/system and is called p2pool.service. A full listing of the file is shown below:
[Unit]
Description=P2Pool Full Node
After=network.target p2pool.socket
#Requires=monerod.service
BindsTo=p2pool.socket
[Service]
StandardInput=socket
Sockets=p2pool.socket
WorkingDirectory=/opt/prod/p2pool/
Type=simple
Restart=always
ExecStartPre=sysctl vm.nr_hugepages=3072
ExecStart=/opt/prod/p2pool/start-p2pool-mini.sh
TimeoutStopSec=60
StandardOutput=file:/opt/prod/p2pool/p2pool.log
StandardError=file:/opt/prod/p2pool/p2pool.err
[Unit]
Description=P2Pool Full Node
After=network.target p2pool.socket
#Requires=monerod.service
BindsTo=p2pool.socket
[Service]
StandardInput=socket
Sockets=p2pool.socket
WorkingDirectory=/opt/prod/p2pool/
Type=simple
Restart=always
ExecStartPre=sysctl vm.nr_hugepages=3072
ExecStart=/opt/prod/p2pool/start-p2pool-mini.sh
TimeoutStopSec=60
StandardOutput=file:/opt/prod/p2pool/p2pool.log
StandardError=file:/opt/prod/p2pool/p2pool.err
[Install]
WantedBy=multi-user.target
[Install]
WantedBy=multi-user.target
To refresh systemd’s configuration after creating the service and socket definitions use the command below:
sudo systemd daemon-reload
To have the P2Pool daemon automatically start at boot time use the command below:
sudo systemd enable p2pool.service
To actually start the service without rebooting use the command below:
sudo systemd start p2pool.service
chave the P2Pool service run at boot
The shell script below can be used to start the P2Pool daemon. A few points about the startup script:
#!/bin/bash
# Monero daemon settings
MONERO_NODE="192.168.0.176"
ZMQ_PORT="20083"
RPC_PORT="20081"
# P2Pool settings
ANY_IP="0.0.0.0"
STRATUM_PORT=3333
P2P_PORT=37889
P2P_DIR="/opt/prod/p2pool"
WALLET="48wY74LjoNnvT8ZWJFHi6U6G3X5dCtk1YsQNSw7v9zcijE7JN2ucDEG"
LOG_LEVEL=0
IN_PEERS=10
OUT_PEERS=10
DATA_API_DIR="${P2P_DIR}/json"
P2P_LOG="${P2P_DIR}/p2pool.log"
USER=$(whoami)
if [ "$USER" != "root" ]; then
echo "ERROR: Run the p2pool daemon as root, exiting.."
exit 1
fi
./p2pool \
--host ${MONERO_NODE} \
--wallet ${WALLET} \
--mini \
--stratum ${ANY_IP}:${STRATUM_PORT} \
--p2p ${ANY_IP}:${P2P_PORT} \
--loglevel ${LOG_LEVEL} \
--zmq-port ${ZMQ_PORT} \
--rpc-port ${RPC_PORT} \
--in-peers ${IN_PEERS} \
--out-peers ${OUT_PEERS} \
--data-api ${DATA_API_DIR} | tee -a ${P2P_LOG}