Starting YaCy on boot with systemd

YaCy is a self-hosted web search engine, that can be used to index web pages. It can also be used as an intranet search appliance. For example, it has been used to index content from the 30C3 Conference. An unique feature is that YaCy can be run as a decentralised peer-to-peer network. You can install it on your desktop computer (Windows, Mac, Linux) and make it available to the YaCy network.

Of course, you also can run it on a server. If you are running a Linux server and you want to automatically start YaCy on boot you have to add it to systemd. Most Linux distributions use systemd (or will start using it in the upcoming major release).

You probably do not want to run YaCy as root, so first add a new user. Use --system to create an system account without login:
sudo adduser --system yacy

[Update] Some systems use useradd instead:
sudo useradd --system yacy

Switch to the new user:
su - yacy

Download YaCy from the web site:
wget http://yacy.net/release/yacy_v1.72_20140506_9000.tar.gz

Unpack the downloaded file:
tar -xvf yacy_v1.72_20140506_9000.tar.gz

YaCy should now be in:
/home/yacy/yacy/

Of course, you can use a different location if you want.

Be sure Java is already installed on your server. Test if YaCy will start:
cd yacy
./startYACY.sh

If YaCy works correctly, you can add a service file to systemd:
/usr/lib/systemd/system/yacy.service


[Unit]
Description=YaCy search server
After=network.target

[Service]
Type=forking
User=yacy
ExecStart=/home/yacy/yacy/startYACY.sh
ExecStop=/home/yacy/yacy/stopYACY.sh

[Install]
WantedBy=multi-user.target

Type forking is required to run scripts. The systemd path may be different, depending on your distribution.

To test your setup, run:
sudo systemctl status yacy

To start the service on boot, run:
sudo systemctl enable yacy

[update]
If you get a message like: Failed to issue method call: Invalid argument
Try: sudo systemctl enable yacy.service

To start YaCy manually, run:
sudo systemctl start yacy

To stop YaCy manually, run:
sudo systemctl stop yacy