From 323e07df4672e443225978c468a993ef93224f56 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 5 Aug 2020 23:26:40 +0800 Subject: [PATCH] fixed systemd inconsistencies --- Makefile | 91 ++++++++++---- documentation/en/install-systemd-services.md | 115 +++++++++++++++++- ...watch.service => lotus-chainwatch.service} | 0 3 files changed, 178 insertions(+), 28 deletions(-) rename scripts/{chainwatch.service => lotus-chainwatch.service} (100%) diff --git a/Makefile b/Makefile index 581c906db..a84a02330 100644 --- a/Makefile +++ b/Makefile @@ -98,26 +98,17 @@ an existing lotus binary in your PATH. This may cause problems if you don't run .PHONY: build -install: +install: install-daemon install-miner install-worker + +install-daemon: install -C ./lotus /usr/local/bin/lotus + +install-miner: install -C ./lotus-storage-miner /usr/local/bin/lotus-storage-miner + +install-worker: install -C ./lotus-seal-worker /usr/local/bin/lotus-seal-worker - -install-services: install - mkdir -p /usr/local/lib/systemd/system - mkdir -p /var/log/lotus - install -C -m 0644 ./scripts/lotus-daemon.service /usr/local/lib/systemd/system/lotus-daemon.service - install -C -m 0644 ./scripts/lotus-miner.service /usr/local/lib/systemd/system/lotus-miner.service - systemctl daemon-reload - @echo - @echo "lotus-daemon and lotus-miner services installed. Don't forget to 'systemctl enable lotus-daemon|lotus-miner' for it to be enabled on startup." - -clean-services: - rm -f /usr/local/lib/systemd/system/lotus-daemon.service - rm -f /usr/local/lib/systemd/system/lotus-miner.service - rm -f /usr/local/lib/systemd/system/chainwatch.service - systemctl daemon-reload - + # TOOLS lotus-seed: $(BUILD_DEPS) @@ -161,13 +152,6 @@ chainwatch: .PHONY: chainwatch BINS+=chainwatch -install-chainwatch-service: chainwatch - install -C ./chainwatch /usr/local/bin/chainwatch - install -C -m 0644 ./scripts/chainwatch.service /usr/local/lib/systemd/system/chainwatch.service - systemctl daemon-reload - @echo - @echo "chainwatch installed. Don't forget to 'systemctl enable chainwatch' for it to be enabled on startup." - bench: rm -f bench go build -o bench ./cmd/lotus-bench @@ -196,6 +180,65 @@ testground: .PHONY: testground BINS+=testground +install-chainwatch: chainwatch + install -C ./chainwatch /usr/local/bin/chainwatch + +# SYSTEMD + +install-daemon-service: install-daemon + mkdir -p /etc/systemd/system + mkdir -p /var/log/lotus + install -C -m 0644 ./scripts/lotus-daemon.service /etc/systemd/system/lotus-daemon.service + systemctl daemon-reload + @echo + @echo "lotus-daemon service installed. Don't forget to run 'sudo systemctl start lotus-daemon' to start it and 'sudo systemctl enable lotus-daemon' for it to be enabled on startup." + +install-miner-service: install-miner install-daemon-service + mkdir -p /etc/systemd/system + mkdir -p /var/log/lotus + install -C -m 0644 ./scripts/lotus-miner.service /etc/systemd/system/lotus-miner.service + systemctl daemon-reload + @echo + @echo "lotus-miner service installed. Don't forget to run 'sudo systemctl start lotus-miner' to start it and 'sudo systemctl enable lotus-miner' for it to be enabled on startup." + +install-chainwatch-service: install-chainwatch install-daemon-service + mkdir -p /etc/systemd/system + mkdir -p /var/log/lotus + install -C -m 0644 ./scripts/lotus-chainwatch.service /etc/systemd/system/lotus-chainwatch.service + systemctl daemon-reload + @echo + @echo "chainwatch service installed. Don't forget to run 'sudo systemctl start lotus-chainwatch' to start it and 'sudo systemctl enable lotus-chainwatch' for it to be enabled on startup." + +install-main-services: install-miner-service + +install-all-services: install-main-services install-chainwatch-service + +install-services: install-main-services + +clean-daemon-service: clean-miner-service clean-chainwatch-service + -systemctl stop lotus-daemon + -systemctl disable lotus-daemon + rm -f /etc/systemd/system/lotus-daemon.service + systemctl daemon-reload + +clean-miner-service: + -systemctl stop lotus-miner + -systemctl disable lotus-miner + rm -f /etc/systemd/system/lotus-miner.service + systemctl daemon-reload + +clean-chainwatch-service: + -systemctl stop chainwatch + -systemctl disable chainwatch + rm -f /etc/systemd/system/lotus-chainwatch.service + systemctl daemon-reload + +clean-main-services: clean-daemon-service + +clean-all-services: clean-main-services + +clean-services: clean-all-services + # MISC buildall: $(BINS) diff --git a/documentation/en/install-systemd-services.md b/documentation/en/install-systemd-services.md index 0bc23cfae..a18620ea7 100644 --- a/documentation/en/install-systemd-services.md +++ b/documentation/en/install-systemd-services.md @@ -1,17 +1,120 @@ # Use Lotus with systemd -Lotus is capable of running as a systemd service daemon. You can find installable service files for systemd in the [lotus repo scripts directory](https://github.com/filecoin-project/lotus/tree/master/scripts) as files with `.service` extension. In order to install these service files, you can copy these `.service` files to the default systemd service path. +Lotus is capable of running as a systemd service daemon. You can find installable service files for systemd in the [lotus repo scripts directory](https://github.com/filecoin-project/lotus/tree/master/scripts) as files with `.service` extension. In order to install these service files, you can copy these `.service` files to the default systemd unit load path. -## Installing via `make` +The services expect their binaries to be present in `/usr/local/bin/`. You can use `make` to install them by running: -NOTE: Before using lotus and lotus-miner as systemd services, don't forget to `sudo make install` to ensure the binaries are accessible by the root user. +```sh +$ sudo make install +``` -If your host uses the default systemd service path, it can be installed with `sudo make install-services`: +for `lotus(-daemon)` and `lotus-storage-miner` and + +```sh +$ sudo make install-chainwatch +``` + +for the `chainwatch` tool. + +## Installing services via `make` + +If your host uses the default systemd unit load path, the `lotus-daemon` and `lotus-miner` services can be installed by running: ```sh $ sudo make install-services ``` +To install the the `lotus-chainwatch` service run: + +```sh +$ sudo make install-chainwatch-service +``` + +You can install all services together by running: + +```sh +$ sudo make install-all-services +``` + +The `lotus-daemon` and the `lotus-miner` services can be installed individually too by running: + +```sh +$ sudo make install-daemon-service +``` + +and + +```sh +$ sudo make install-miner-service +``` + +### Notes + +When nstalling the `lotus-miner` and/or `lotus-chainwatch` service the `lotus-daemon` service gets automatically installed since the other two services depend on it being installed to run. + +All `install *service*` commands will install the latest binaries in the lotus build folders to `/usr/local/bin/`. If you do not want to use the latest build binaries please copy the `*.service` files by hand. + +## Removing via `make` + +All services can beremoved via `make`. To remove all services together run: + +```sh +$ sudo make clean-all-services +``` + +Individual services can be removed by running: + +```sh +$ sudo make clean-chainwatch-services +$ sudo make clean-miner-services +$ sudo make clean-daemon-services +``` + +### Notes + +Removing the `lotus-daemon` service will automatically remove the depending services `lotus-miner` and `lotus-chainwatch` + + +## Controlling services +### Start/Stop + +You can start the services by running: + +```sh +$ sudo systemctl start lotus-daemon +$ sudo systemctl start lotus-miner +$ sudo systemctl start lotus-chainwatch +``` + +and can be stopped by running: + +```sh +$ sudo systemctl stop lotus-daemon +$ sudo systemctl stop lotus-miner +$ sudo systemctl stop lotus-chainwatch +``` + +### Enabling services on startup + +To enable the services to run automatically on startup execute: + +```sh +$ sudo systemctl enable lotus-daemon +$ sudo systemctl enable lotus-miner +$ sudo systemctl enable lotus-chainwatch +``` + +To disable the services on startup run: + +```sh +$ sudo systemctl disable lotus-daemon +$ sudo systemctl disable lotus-miner +$ sudo systemctl disable lotus-chainwatch +``` +### Notes + +Systemd will not let services be enabled or started without their dependencies. Starting the `lotus-chainwatch` and/or `lotus-miner` service with automatically start the `lotus-daemon` service (if installed!). Stopping the `lotus-daemon` service will stop the other two services. The same pattern is executed for enabling and disabling the services. + ## Interacting with service logs Logs from the services can be reviewed using `journalctl`. @@ -27,3 +130,7 @@ $ sudo journalctl -u lotus-daemon -f ```sh $ sudo journalctl -u lotus-miner -r ``` + +### Log files + +Besides the systemd service logs all services save their own log files in `/var/log/lotus/`. diff --git a/scripts/chainwatch.service b/scripts/lotus-chainwatch.service similarity index 100% rename from scripts/chainwatch.service rename to scripts/lotus-chainwatch.service