Setting up lokid as a systemd service ------------------------------------- Assuming you are using a Linux machine that uses systemd for an init system (most linux distributions nowadays do -- running `cat /proc/1/comm` should print systemd if you are unsure and want to verify), you can set up loki to be started and managed as a regular system process rather than in a screen session. Two notes before you begin: - it is currently not possible to run the `prepare_registration` command this way, so you will either want to set that up first while running lokid directly as described in the loki service node guide. It is also possible to get the node working via systemd first, stopping it, running lokid manually for the prepare_registration wizard (as described in the guide), then stopping it and restarting the systemd service. - The 1.0.0 and 1.0.1 releases have a bug that can cause a delay of an hour in sending an uptime proof to the network; with a particular timing of multiple restarts it is possible for no uptime proof to reach the network for more than 2 hours, resulting in a deregistration. It is strongly recommended that you upgrade to 1.0.2 (which fixes this issue) to reduce the risk of being deregistered. To get started, you first need to install the systemd unit file. A working sample is provided at https://jagerman.com/loki-node.service. This file needs to be placed in `/etc/systemd/system` after making some edits, described below. You can download it directly into place using this command: sudo wget https://jagerman.com/loki-node.service -O /etc/systemd/system/loki-node.service You will, however, need to make two changes, so after downloading it, edit it with: sudo nano /etc/systemd/system/loki-node.service You will need, in particular, to change two lines. First this one: User=loki needs to be changed to refer to the username under which loki runs. For example, if your username is `snode` (as suggested in the SN guide) you'd change this to `User=snode`. In my case, it runs as a user called `loki`, but the setup here will vary considerably. If you don't know your current username, the `username -un` command will print it out for you. (If this prints out `root` you are strongly encouraged to run loki under a regular user account rather than directly as root). Next you need to adjust the `ExecStart` line: ExecStart=/home/loki/nodes/bin/lokid --service-node --non-interactive Replace `/home/loki/nodes/bin/lokid` with the full path to wherever your loki binaries reside. If using the official linux binaries, you *could* use: ExecStart=/home/snode/loki-linux-x64-1.0.2/lokid but note that this will require updating the systemd service file every time you upgrade loki. Instead, I would suggest creating a directory to hold the current binaries using: mkdir ~/loki cp ~/loki-linux-x64-1.0.2/* ~/loki and using: ExecStart=/home/snode/loki/lokid (Doing this, rather than using the `loki-linux-x64-1.0.2` path will make your life easier for future releases: all you need to do for an upgrade is download and extract the binaries, copy them into ~/loki (overwriting the existing ones), and restart the loki service -- you won't have to edit the systemd service file). So, with those steps donw, your /etc/systemd/system/loki-node.service file should now look something like this: [Unit] Description=Loki Node After=network-online.target [Service] User=snode Type=simple WorkingDirectory=~ Restart=always ExecStart=/home/snode/loki/lokid --service-node --non-interactive [Install] WantedBy=multi-user.target With that in place, you want to tell systemd to reload configuration files with: sudo systemctl daemon-reload At this point, if lokid is still running in `screen`, you want to connect to your screen session and quit it by typing `exit` into the running lokid. It usually takes a few seconds to shut down cleanly. Once it has shut down, it is time to start it up using systemd: sudo systemctl start loki-node.service Once this completes, check that it is running with: sudo systemctl status loki-node.service and you should see something like: ● loki-node.service - Loki Node Loaded: loaded (/etc/systemd/system/loki-node.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2018-09-22 14:15:11 ADT; 4 days ago Main PID: 25445 (lokid) Tasks: 26 (limit: 4915) Memory: 3.1G CGroup: /system.slice/loki-node.service └─25445 /home/loki/nodes/bin/lokid --non-interactive --service-node If you see the "Active" line showing something *other* than "active (running)" this means your lokid failed to start for some reason -- possibly because of an error in the loki-node.service file. If needed, fix it (using `sudo nano /etc/systemd/system/loki-node.service` again), reload the systemd configuration with `sudo systemctl daemon-reload`, and try starting it again with `sudo systemctl start loki-node.service`. Assuming everything started up: great! There is one last step: sudo systemctl enable loki-node.service This tells sytemd that loki-node.service should be started when the system boot, which you absolutely want (otherwise a reboot would not restart your lokid and lead to a deregister if you don't notice in time!) That's it, you're done. If you want to issue commands to loki you can now use (from the shell): ~/loki/lokid status or various other commands that you would normally type directly into lokid. These will communicate with the running lokid to handle the given command. (Most commands can be issued this way--though currently not prepare_registration, as mentioned at the beginning of this guide). One particularly useful command is: ~/loki/lokid print_sn_status which should report that you are online and that your service node is registered with an last uptime proof. (But note that the service node status might take up to 35 minutes to show a received uptime proof depending on when your last service node uptime proof was received by the network). Note that if you are running a testnet rather than mainnet node you will need to add `--testnet` to the command, such as: `~/loki/lokid --testnet status`.