Running Zcash via systemd on Ubuntu 16.04, just for fun!

Hey guys,

Take a look into this:


zcash@server:~ systemctl --user start zcashd zcash@server:~ systemctl --user status zcashd
● zcashd.service - Zcash Daemon
Loaded: loaded (/home/zcash/.config/systemd/user/zcashd.service; disabled; vendor preset: enabled)
Active: active (running) since Wed 2016-10-26 00:21:21 EDT; 2s ago
Process: 10038 ExecStart=/home/zcash/zcash/src/zcashd -daemon (code=exited, status=0/SUCCESS)
Main PID: 10039 (zcashd)
CGroup: /user.slice/user-1006.slice/user@1006.service/zcashd.service
└─10039 /home/zcash/zcash/src/zcashd -daemon -bind=[::]:8233


To do this, lets, say, after building zcash under your “/home/zcashuser/zcash” (home directory), you can do this:

mkdir -p ~/.config/systemd/user/
vi ~/.config/systemd/user/zcashd.service

Contents of zcashd.service:


[Unit]
Description=Zcash Daemon

[Service]
Type=forking
ExecStart=/home/zcashuser/zcash/src/zcashd -daemon -bind=[::]:8233

[Install]
WantedBy=default.target

~/zcash/src/zcash-cli stop

systemctl --user daemon-reload

systemctl --user start zcashd

systemctl --user status zcashd

~/zcash/src/zcash-cli listtransactions

:smiley:

It is dual-stack (works if you have both IPv4 and IPv6). BTW, is it 8233 the default for Zcash?

NOTE: Lets say that you added a “zcashuser” into your Ubuntu box, use “sudo su - zcashuser”, instead of just “su - zcashuser”, otherwise, systemd as a user will fail, don’t ask me why, error:

“systemctl --user status zcashd
Failed to connect to bus: No such file or directory”

So, "sudo su - " FTW! :stuck_out_tongue:

Quick question, is it possible to start zcashd in foreground (i.e., without “-daemon”), logging everything to stdout only?

Cheers!

1 Like

yes you can run it in the foreground

With messages to stdout, instead of that awesome logo and hearth? :smiley:

BTW, I just noted that systemd kills your process after logging out… damn… hehehe

For a production server, the Zcash’s systemd service, must be installed as root, here:

“/lib/systemd/system/zcashd.service”

1 Like

I was just playing with the same thing for UBOS, but I’m not sure zcashd can be easily run “in production” as you suggest. Here are the issues I have run into so far:

  • ~/.zcash-params should be moved somewhere else, like /etc/zcash/params or /var/lib/zcash/params. Unfortunately that path is currently hard-coded AFAICT.
  • fetch-params.sh should be renamed (zcash-fetch-params for example) so it can live in /usr/bin or such. Does it make sense to have the systemd service invoke this as a “pre” script before the actual daemon start or is this operation likely to take a long time?
  • it’s unclear (to me) how to cleanly shut down the daemon. kill -HUP on the PID is enough?

And finally, it seems there is an implied one-to-one mapping between a daemon and a single user with a single wallet. Is that correct? That would mean that for a real server with real users, I’d have to run one instance of zcashd for each user. That doesn’t really scale. A multi-user option would be nice.

P.S. I’m new to this, and might be getting it all wrong. Please set me straight.

When you install zcash from the debian package, it does indeed install fetch-params.sh as zcash-fetch-params…on my servers I’ve created a username “zcash” and launching zcashd in rc.local via sudo -u zcash zcashd which I know is ghetto and oldschool, but I"ve got a grey beard