From 89bf01fb53b22a62f07e51327bc88ac434284d7d Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Wed, 22 Jun 2022 17:50:17 +0200 Subject: [PATCH] Add systemd example setup --- init/README.md | 30 ++++++++++++++++++++++++++++++ init/clustercockpit.service | 18 ++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 init/README.md create mode 100644 init/clustercockpit.service diff --git a/init/README.md b/init/README.md new file mode 100644 index 0000000..ed715ab --- /dev/null +++ b/init/README.md @@ -0,0 +1,30 @@ +# How to run this as a systemd deamon + +The files in this directory assume that you install the Golang version of ClusterCockpit to `/var/clustercockpit`. If you do not like that, you can choose any other location, but make sure to replace all paths that begin with `/var/clustercockpit` in the `clustercockpit.service` file! + +If you have not installed [yarn](https://yarnpkg.com/getting-started/install) and [go](https://go.dev/doc/install) already, do that (Golang is available in most package managers). + +The `config.json` can have the optional fields *user* and *group*. If provided, the application will call [setuid](https://man7.org/linux/man-pages/man2/setuid.2.html) and [setgid](https://man7.org/linux/man-pages/man2/setgid.2.html) after having read the config file and having bound to a TCP port (so that it can take a privileged port), but before it starts accepting any connections. This is good for security, but means that the directories `frontend/public`, `var/` and `templates/` must be readable by that user and `var/` writable as well (All paths relative to the repos root). The `.env` and `config.json` files might contain secrets and should not be readable by that user. If those files are changed, the server has to be restarted. + +```sh +# 1.: Clone this repository to /var/clustercockpit +git clone git@github.com:ClusterCockpit/cc-backend.git /var/clustercockpit + +# 2.: Install all dependencies and build everything +cd /var/clustercockpit +go get && go build && (cd ./frontend && yarn install && yarn build) + +# 3.: Modify the `./config.json` file from the directory which contains this README.md to your liking and put it in the repo root +cp ./utils/systemd/config.json ./config.json +vim ./config.json # do your thing... + +# 4.: Add the systemd service unit file +sudo ln -s /var/clustercockpit/utils/systemd/clustercockpit.service /etc/systemd/system/clustercockpit.service + +# 5.: Enable and start the server +sudo systemctl enable clustercockpit.service # optional (if done, (re-)starts automatically) +sudo systemctl start clustercockpit.service + +# Check whats going on: +sudo journalctl -u clustercockpit.service +``` diff --git a/init/clustercockpit.service b/init/clustercockpit.service new file mode 100644 index 0000000..53fc429 --- /dev/null +++ b/init/clustercockpit.service @@ -0,0 +1,18 @@ +[Unit] +Description=ClusterCockpit Web Server (Go edition) +Documentation=https://github.com/ClusterCockpit/cc-backend +Wants=network-online.target +After=network-online.target +After=mariadb.service mysql.service + +[Service] +WorkingDirectory=/opt/monitoring/cc-backend +Type=notify +NotifyAccess=all +Restart=on-failure +RestartSec=30 +TimeoutStopSec=100 +ExecStart=/opt/monitoring/cc-backend/cc-backend --config ./config.json + +[Install] +WantedBy=multi-user.target