Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install Folding@home FAHClient on Linux as a systemd service unit

Install Folding@home FAHClient on Linux as a systemd service unit

Republished on my website, keeping this version here for historical reasons.

Install FAHClient as documented in the official guide. Stop the traditional init script service that was created and automatically started.

$ sudo /etc/init.d/FAHClient stop

Move the init script to another location. Path /usr/local/bin can be changed, but be sure to use the correct path in the service unit file of the next step.

$ sudo mv /etc/init.d/FAHClient /usr/local/bin

Copy the contents of the gist Systemd service unit for Folding@Home Client into (a new) file /etc/systemd/system/fahclient.service. File contents included here:

[Unit]
Description=Folding@Home V7 Client
Documentation=https://folding.stanford.edu/home/the-software/

[Service]
Type=simple
PIDFile=/var/run/fahclient.pid
ExecStart=/usr/local/bin/FAHClient -v start
ExecReload=/usr/local/bin/FAHClient -v restart
ExecStop=/usr/local/bin/FAHClient -v stop
KillMode=process

[Install]
WantedBy=multi-user.target

Then update its ownership and permissions as below

$ sudo chown root:root /etc/systemd/system/fahclient.service
$ sudo chmod u=rw,go=r /etc/systemd/system/fahclient.service

The systemd service unit for FAHClient is installed. Reload systemd manager configuration

$ sudo systemctl daemon-reload

Query the status of service unit.

$ sudo systemctl status --full fahclient.service

Start and stop as a regular systemd service

$ sudo systemctl stop fahclient.service
$ sudo systemctl start fahclient.service

Folding@home is a distributed computing project for disease research that simulates protein folding, computational drug design, and other types of molecular dynamics. See also the Volunteer Computing page.

@stumyp

This comment has been minimized.

Copy link

@stumyp stumyp commented Mar 16, 2020

Thanks, I've changed it to

[Unit]
Description=Folding@Home V7 Client
Documentation=https://folding.stanford.edu/home/the-software/

[Service]
Type=simple
PIDFile=/var/run/fahclient.pid
ExecStart=/usr/bin/FAHClient --chdir /var/lib/fahclient/ --verbose --run-as fahclient --pid-file=/var/run/fahclient.pid 
ExecReload=/usr/bin/FAHClient -v restart
ExecStop=/usr/bin/FAHClient -v stop
KillMode=process

[Install]
WantedBy=multi-user.target
root@arda:/home/tumyp/Down

so it is in line with how Debian package starts it

@lopezpdvn

This comment has been minimized.

Copy link
Owner Author

@lopezpdvn lopezpdvn commented Mar 18, 2020

Thanks for sharing!

@widget

This comment has been minimized.

Copy link

@widget widget commented Apr 13, 2020

In Ubuntu 20.04 systemd is complaining about using /var/run and preferring /run.

Also in FAHClient 7.5 at least -v restart and -v stop aren't valid commands. I can't find a restart, but stop is --send-command shutdown.

My complete file:

[Unit]
Description=Folding@Home V7 Client
Documentation=https://folding.stanford.edu/home/the-software/

[Service]
Type=simple
PIDFile=/run/fahclient.pid
ExecStart=/usr/bin/FAHClient --chdir /etc/fahclient --verbose --run-as fahclient --pid-file=/run/fahclient.pid 
ExecStop=/usr/bin/FAHClient --send-command shutdown
KillMode=process

[Install]
WantedBy=multi-user.target
@lopezpdvn

This comment has been minimized.

Copy link
Owner Author

@lopezpdvn lopezpdvn commented Apr 13, 2020

Thanks for sharing!

@chadek

This comment has been minimized.

Copy link

@chadek chadek commented Apr 19, 2020

I tuned a bit this systemd service file (adding some security parameters) and open an issue here as reloading isn't working as expected if you take a look at the init.d script: FoldingAtHome/fah-issues#1396

@vasti

This comment has been minimized.

Copy link

@vasti vasti commented Apr 19, 2020

Here's systemd unit file for 7.6.x on Debian 10:

[Unit]
Description=Folding@home V7 Client
Documentation=https://foldingathome.org/support/faq/installation-guides/linux/

[Service]
Type=simple
PIDFile=/run/fahclient.pid
ExecStart=/usr/bin/FAHClient --config /etc/fahclient/config.xml --chdir /var/lib/fahclient --run-as fahclient --pid-file=/run/fahclient.pid --verbose --daemon
ExecStop=/usr/bin/FAHClient --send-command shutdown
KillMode=process

[Install]
WantedBy=multi-user.target

I haven't noticed any weirdness with it not stopping properly or something like that.

Couple of notes:
Setting WorkingDirectory=/var/lib/fahclient in unit file does not work. It either kind of started for me, but FAHControl (or web ui) would not connect to it, or it just died as it was unable to write to log.txt. Passing --chdir /var/lib/fahclient makes it work.
As mentioned above - I had to change PID file path to /run/fahclient.pid (on Debian 10 there's a symlink /var/run -> /run).

@chadek

This comment has been minimized.

Copy link

@chadek chadek commented Apr 20, 2020

Setting WorkingDirectory=/var/lib/fahclient in unit file does not work.

That's because with your configuration you start fahclient as root user (which is not really good from my point of view). It is only when you start fahclient with run-as option that you actually use fahclient user. Everything else will be perform with root user. If you set user to be fahclient in you service file, you can use WorkingDirectory option and get rid of the chdir option while starting your daemon. Note that you'll also need the RuntimeDirectory option as fahclient user won't have permission to create his pid file without it. I just added it to the service file I wrote here and it is working like a charm: FoldingAtHome/fah-issues#1396

I'll just put it here too:

[Unit]
Description=Folding@Home V7 Client
Documentation=https://folding.stanford.edu/home/the-software/
After=syslog.target network.target remote-fs.target

[Service]
Type=simple
User=fahclient
RuntimeDirectory=fahclient
RuntimeDirectoryMode=0755
PIDFile=/run/fahclient/fahclient.pid
WorkingDirectory=/var/lib/fahclient
#--run-as is optional as we already set the user to use inside this service
# --chdir /var/lib/fahclient/ is optional as we already set the workingdir inside this service
ExecStart=/usr/bin/FAHClient /etc/fahclient/config.xml --chdir /var/lib/fahclient/ --pid-file=/run/fahclient/fahclient.pid --run-as fahclient
#Actually not working, sending sigusr1 will stop fahclient instead off reloading config
#ExecReload=/bin/kill -SIGUSR1 $MAINPID 
ExecStop= /bin/kill $MAINPID
KillMode=process
NoNewPrivileges=True
CPUSchedulingPriority=1
ProtectSystem=strict
ProtectKernelTunables=yes
ReadWritePaths=/var/lib/fahclient/ /etc/fahclient/
MemoryDenyWriteExecute=yes

[Install]
WantedBy=multi-user.target
@vasti

This comment has been minimized.

Copy link

@vasti vasti commented Aug 4, 2020

I have adopted the unit file as suggested while upgrading to the latest fahclient. Following were required to make it work on Debian 10 with NVIDIA drivers & kernel installed from backports:

MemoryDenyWriteExecute=yes somehow prevents f@h from running on GeForce 20 GPU. f@h would just stop immediately after trying to start on GPU. There were little to nothing in the logs what the actual issue was. GPU and CUDA/OpenCL devices were detected normally by the fahclient.

libOpenCL.so was not getting loaded with a unit file like this until i created a config file under /etc/ld.so.conf.d as described here. The fahclient user is in video group and clinfo reports everything as expected if executed as said user even before the ld.so.conf.d config file was added.

@lopezpdvn

This comment has been minimized.

Copy link
Owner Author

@lopezpdvn lopezpdvn commented Aug 12, 2020

Thanks for sharing, folks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.