mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
Merge 0394b31630 into 29f81738df
This commit is contained in:
commit
ed5b7b9007
7 changed files with 219 additions and 0 deletions
0
docker/sidekiq-entrypoint.sh
Normal file → Executable file
0
docker/sidekiq-entrypoint.sh
Normal file → Executable file
0
docker/web-entrypoint.sh
Normal file → Executable file
0
docker/web-entrypoint.sh
Normal file → Executable file
113
systemd/README.md
Normal file
113
systemd/README.md
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
# Installing dawarich with systemd
|
||||
|
||||
This guide is based on my experience setting up dawarich on Debian 12.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
### Postgresql
|
||||
|
||||
You need a recent version of [Postgresql](https://www.postgresql.org/)
|
||||
with [PostGIS](https://postgis.net/) support.
|
||||
|
||||
In Debian you can install it with
|
||||
```sh
|
||||
apt install postgresql-postgis
|
||||
```
|
||||
|
||||
If you do not want to run the database on the same host as the
|
||||
dawarich service, you need to reconfigure Postgresql to allow
|
||||
connections from that host.
|
||||
|
||||
Dawarich will populate it's database itself and only needs a user
|
||||
account to do so. This account needs to have superuser capabilities as
|
||||
the database population includes enabling the postgis extention:
|
||||
```sh
|
||||
sudo -u postgres psql <<EOF
|
||||
CREATE USER dawarich PASSWORD 'UseAStrongPasswordAndKeepItSecret';
|
||||
ALTER USER dawarich WITH SUPERUSER;
|
||||
EOF
|
||||
```
|
||||
|
||||
|
||||
### Redis
|
||||
|
||||
Install a recent version of [Redis](https://redis.io/).
|
||||
|
||||
In Debian you can install it with
|
||||
```sh
|
||||
apt install redis-server
|
||||
```
|
||||
|
||||
If you do not want to run the redis service on the same host as the
|
||||
dawarich service, you need to reconfigure redis to accept connection
|
||||
from that host and most likely configure authentication.
|
||||
|
||||
|
||||
### System User account
|
||||
|
||||
Create an account that will run the ruby services of dawarich. Of
|
||||
course, you can choose another directory for it's HOME.
|
||||
|
||||
```sh
|
||||
adduser --system --home /service/dawarich dawarich
|
||||
```
|
||||
|
||||
### Ruby
|
||||
|
||||
Dawarich currently uses [Ruby](https://www.ruby-lang.org/) version
|
||||
3.4.1 (yes, exactly this one). At least on Debian, this version is not
|
||||
available at all in the package repositories. So I installed Ruby by
|
||||
compiling from source:
|
||||
|
||||
```sh
|
||||
apt install build-essential pkg-config libpq-dev libffi-dev libyaml-dev zlib1g-dev
|
||||
|
||||
# compile & install as unprivileged user
|
||||
sudo -u dawarich bash
|
||||
|
||||
# download
|
||||
cd ~
|
||||
mkdir src
|
||||
cd src
|
||||
wget https://cache.ruby-lang.org/pub/ruby/3.4/ruby-3.4.1.tar.gz
|
||||
|
||||
# unpack
|
||||
tar -xzf ruby-3.4.1.tar.gz
|
||||
cd ~/ruby-3.4.1
|
||||
|
||||
# build & install
|
||||
./configure --prefix $HOME/ruby-3.4.1
|
||||
make all test install
|
||||
|
||||
# allow easy replacement of used ruby installation
|
||||
ln -s ruby-3.4.1 ~dawarich/ruby
|
||||
|
||||
exit # sudo -u dawarich bash
|
||||
```
|
||||
|
||||
|
||||
## Install dawarich
|
||||
|
||||
0. Clone the repo to `/service/dawarich/dawarich` and install dependencies.
|
||||
```sh
|
||||
# install as unprivileged user
|
||||
sudo -u dawarich bash
|
||||
|
||||
cd ~
|
||||
git clone https://github.com/Freika/dawarich.git
|
||||
cd dawarich
|
||||
|
||||
# install dependencies
|
||||
bash systemd/install.sh
|
||||
|
||||
exit # sudo -u dawarich bash
|
||||
```
|
||||
|
||||
0. Install, enable and start systemd services
|
||||
```sh
|
||||
# install systemd services
|
||||
install systemd/dawarich.service systemd/dawarich-sidekiq.service /etc/systemd/system
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now dawarich.service dawarich-sidekiq.service
|
||||
systemctl status dawarich.service dawarich-sidekiq.service
|
||||
```
|
||||
14
systemd/dawarich-sidekiq.service
Normal file
14
systemd/dawarich-sidekiq.service
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[Unit]
|
||||
Description=DaWarIch SideKiq Service
|
||||
Wants=network-online.target system-postgresql.slice redis-server.service
|
||||
After=network-online.target system-postgresql.slice redis-server.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=dawarich
|
||||
WorkingDirectory=/service/dawarich/dawarich
|
||||
EnvironmentFile=-/service/dawarich/dawarich/systemd/environment
|
||||
ExecStart=/service/dawarich/dawarich/docker/sidekiq-entrypoint.sh sidekiq
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
14
systemd/dawarich.service
Normal file
14
systemd/dawarich.service
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[Unit]
|
||||
Description=DaWarIch Service
|
||||
Wants=network-online.target system-postgresql.slice redis-server.service
|
||||
After=network-online.target system-postgresql.slice redis-server.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=dawarich
|
||||
WorkingDirectory=/service/dawarich/dawarich
|
||||
EnvironmentFile=-/service/dawarich/dawarich/systemd/environment
|
||||
ExecStart=/service/dawarich/dawarich/docker/web-entrypoint.sh bin/rails server -p 3000 -b ::
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
34
systemd/environment
Normal file
34
systemd/environment
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# this file is used by systemd, do not use $VAR as it won't be expanded!
|
||||
|
||||
# set PATH and GEM_HOME for locally installed ruby
|
||||
PATH=/service/dawarich/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
GEM_HOME=/service/dawarich/ruby/lib/ruby/gems/3.4.0
|
||||
|
||||
# from docker/Dockerfile.dev
|
||||
APP_PATH=/service/dawarich/dawarich
|
||||
BUNDLE_VERSION=2.5.21
|
||||
RAILS_LOG_TO_STDOUT=true
|
||||
RAILS_PORT=3000
|
||||
RAILS_ENV=development
|
||||
SELF_HOSTED=true
|
||||
|
||||
# from docker/docker-compose.yml
|
||||
RAILS_ENV=development
|
||||
REDIS_URL=redis://localhost:6379/0
|
||||
DATABASE_HOST=localhost
|
||||
DATABASE_USERNAME=dawarich
|
||||
DATABASE_PASSWORD=ayophaing8bafohnoeGa
|
||||
DATABASE_NAME=dawarich
|
||||
MIN_MINUTES_SPENT_IN_CITY=60
|
||||
APPLICATION_HOSTS=localhost
|
||||
TIME_ZONE=Europe/London
|
||||
APPLICATION_PROTOCOL=http
|
||||
DISTANCE_UNIT=km
|
||||
PROMETHEUS_EXPORTER_ENABLED=false
|
||||
PROMETHEUS_EXPORTER_HOST=0.0.0.0
|
||||
PROMETHEUS_EXPORTER_PORT=9394
|
||||
SELF_HOSTED=true
|
||||
|
||||
# Local variables:
|
||||
# mode: sh
|
||||
# End:
|
||||
44
systemd/install.sh
Normal file
44
systemd/install.sh
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
dirname=${0%/*}
|
||||
if [ "$dirname" != "systemd" ]; then
|
||||
echo "This installed must be called in the repository root!" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# make shellcheck happy (vars are defined in while loop below)
|
||||
BUNDLE_VERSION=''
|
||||
GEM_HOME=''
|
||||
# "source" "$dirname"/environment and EXPORT all vars
|
||||
# export all vars from env
|
||||
envfile="$dirname"/environment
|
||||
while IFS='#' read -r line; do
|
||||
if [[ "$line" =~ ^([A-Z0-9_]+)=\"?(.*)\"?$ ]]; then
|
||||
k=${BASH_REMATCH[1]}
|
||||
v=${BASH_REMATCH[2]}
|
||||
export "$k"="$v"
|
||||
fi
|
||||
done < "$envfile"
|
||||
|
||||
if [ "$APP_PATH" != "$PWD" ]; then
|
||||
echo "Error: APP_PATH (defined in $envfile) != $PWD!" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -x
|
||||
|
||||
# from docker/Dockerfile.dev
|
||||
|
||||
# Update gem system and install bundler
|
||||
gem update --system 3.6.2
|
||||
gem install bundler --version "$BUNDLE_VERSION"
|
||||
rm -rf "$GEM_HOME"/cache/*
|
||||
|
||||
# Install all gems into the image
|
||||
bundle config set --local path 'vendor/bundle'
|
||||
bundle install --jobs 4 --retry 3
|
||||
rm -rf vendor/bundle/ruby/3.4.1/cache/*.gem
|
||||
|
||||
exit 0
|
||||
Loading…
Reference in a new issue