FoundKey/docs/install.md

244 lines
7.5 KiB
Markdown
Raw Normal View History

# FoundKey Setup and Installation Guide
2022-07-29 05:57:40 +00:00
This guide will assume that you have administrative rights, either as root or a user with sudo permissions. If you are using a non-root user, prefix the commands with `sudo` except when you are logged into the foundkey user with `su`.
2022-07-29 05:57:40 +00:00
This guide will also assume you're using Debian or a derivative like Ubuntu. If you are using another OS, you will need to adapt the comamnds and package names to match those that your OS uses.
2022-07-29 05:57:40 +00:00
## Install dependencies
2022-07-29 06:09:26 +00:00
FoundKey requires the following packages to run:
2022-07-29 05:57:40 +00:00
### Dependencies :package:
* **[Node.js](https://nodejs.org/en/)** (18.x)
* **[PostgreSQL](https://www.postgresql.org/)** (12.x minimum; 13.x+ is preferred)
2022-07-29 05:57:40 +00:00
* **[Redis](https://redis.io/)**
* **[Yarn](https://yarnpkg.com/)**
The following are needed to compile native npm modules:
* A C/C++ compiler like **GCC** or **Clang**
* Build tools like **make**
* **[Python](https://python.org/)** (3.x)
2022-07-29 05:57:40 +00:00
### Optional
2022-07-29 05:57:40 +00:00
* [FFmpeg](https://www.ffmpeg.org/)
To install the dependiencies on Debian (or derivatives like Ubuntu) you can use the following commands:
```sh
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
2022-07-29 06:31:48 +00:00
apt install build-essential python3 nodejs postgresql redis
corepack enable # for yarn
# Optional dependencies
apt install ffmpeg
```
## Create FoundKey user
Create a separate non-root user to run FoundKey:
```sh
adduser --disabled-password --disabled-login foundkey
```
The following steps will require logging into the `foundkey` user, so do that now.
```sh
su - foundkey
```
2022-07-29 05:57:40 +00:00
## Install FoundKey
We recommend using a local branch and merging in upstream releases as they get tagged. This allows for easy local customization of your install.
2022-07-29 05:57:40 +00:00
First, clone the FoundKey repo:
```sh
git clone https://akkoma.dev/FoundKeyGang/FoundKey
cd FoundKey
```
2022-07-29 05:57:40 +00:00
Now create your local branch. In this example, we'll be using `toast.cafe` as the local branch name and release `v13.0.0-preview1` as the tag to track. To create that branch:
```sh
git checkout tags/v13.0.0-preview1 -b toast.cafe
```
2022-07-29 05:57:40 +00:00
Updating will be covered in a later section. For now you'll want to install the dependencies using Yarn:
```sh
yarn install
```
2022-07-29 05:57:40 +00:00
## Configure FoundKey
1. Copy `.config/example.yml` to `.config/default.yml`.
2022-07-29 05:57:40 +00:00
`cp .config/example.yml .config/default.yml`
2. Edit `default.yml` with a text editor
- Make sure you set the PostgreSQL and Redis settings correctly.
- Use a strong password for the PostgreSQL user and take note of it since it'll be needed later.
2022-07-29 05:57:40 +00:00
2023-03-03 22:46:45 +00:00
### Reverse proxy
For production use and for HTTPS termination you will have to use a reverse proxy.
There are instructions for setting up [nginx](./nginx.md) for this purpose.
### Changing the default Reaction
You can change the default reaction that is used when an ActivityPub "Like" is received from '👍' to '⭐' by changing the boolean value `meta.useStarForReactionFallback` in the databse respectively.
2023-05-23 17:51:55 +00:00
### Environment variables
There are some behaviour changes which can be accomplished using environment variables.
|variable name|meaning|
|---|---|
|`FK_ONLY_QUEUE`|If set, only the queue processing will be run. The frontend will not be available. Cannot be combined with `FK_ONLY_SERVER` or `FK_DISABLE_CLUSTERING`.|
|`FK_ONLY_SERVER`|If set, only the frontend will be run. Queues will not be processed. Cannot be combined with `FK_ONLY_QUEUE` or `FK_DISABLE_CLUSTERING`.|
|`FK_NO_DAEMONS`|If set, the server statistics and queue statistics will not be run.|
|`FK_DISABLE_CLUSTERING`|If set, all work will be done in a single thread instead of different threads for frontend and queue. (not recommended)|
|`FK_WITH_LOG_TIME`|If set, a timestamp will be appended to all log messages.|
|`FK_SLOW`|If set, all requests will be delayed by 3s. (not recommended, useful for testing)|
|`FK_LOG_LEVEL`|Sets the log level. Messages below the set log level will be suppressed. Available log levels are `quiet` (suppress all), `error`, `warning`, `success`, `info`, `debug`.|
If the `NODE_ENV` environment variable is set to `testing`, then the flags `FK_DISABLE_CLUSTERING` and `FK_NO_DAEMONS` will always be set, and the log level will always be `quiet`.
## Build FoundKey
2022-07-29 05:57:40 +00:00
2022-07-29 06:09:26 +00:00
Build foundkey with the following:
2022-07-29 05:57:40 +00:00
`NODE_ENV=production yarn build`
If your system has at least 4GB of RAM, run `NODE_ENV=production yarn build-parallel` to speed up build times.
2022-07-29 05:57:40 +00:00
If you're still encountering errors about some modules, use node-gyp:
1. `npx node-gyp configure`
2. `npx node-gyp build`
3. `NODE_ENV=production yarn build`
## Setting up the database
Create the appropriate PostgreSQL users with respective passwords, and empty database as named in the configuration file.
Make sure the database connection also works correctly when run from the user that will later run FoundKey, or it could cause problems later. The encoding of the database should be UTF-8.
2022-07-29 05:57:40 +00:00
2022-07-29 06:12:30 +00:00
```sh
sudo -u postgres psql
```
2022-07-29 06:09:26 +00:00
2022-07-29 06:12:30 +00:00
```sql
create database foundkey with encoding = 'UTF8';
create user foundkey with encrypted password '{YOUR_PASSWORD}';
grant all privileges on database foundkey to foundkey;
\q
```
2022-07-29 05:57:40 +00:00
Next, initialize the database:
2022-07-29 05:57:40 +00:00
`yarn run init`
## Running FoundKey
You can either run FoundKey manually or use the system service manager to start FoundKey automatically on startup.
2022-07-29 05:57:40 +00:00
### Launching manually
Run `NODE_ENV=production npm start` to launch FoundKey manually. To stop the server, use Ctrl-C.
2022-07-29 05:57:40 +00:00
### Launch with systemd
Run `systemctl --edit --full --force foundkey.service`, and paste the following:
2022-07-29 05:57:40 +00:00
2022-07-29 06:12:30 +00:00
```ini
[Unit]
Description=FoundKey daemon
[Service]
Type=simple
User=foundkey
ExecStart=/usr/bin/npm start
WorkingDirectory=/home/foundkey/foundkey
Environment="NODE_ENV=production"
TimeoutSec=60
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=foundkey
Restart=always
[Install]
WantedBy=multi-user.target
```
2022-07-29 05:57:40 +00:00
Save the file, then enable and start FoundKey.
```sh
systemctl enable --now foundkey
```
2022-07-29 05:57:40 +00:00
2022-07-29 06:09:26 +00:00
You can check if the service is running with `systemctl status foundkey`.
2022-07-29 05:57:40 +00:00
### Launch with OpenRC
Copy the following text to `/etc/init.d/foundkey`:
2022-07-29 05:57:40 +00:00
2022-07-29 06:12:30 +00:00
```sh
#!/sbin/openrc-run
2022-07-29 05:57:40 +00:00
2022-07-29 06:12:30 +00:00
name=foundkey
description="FoundKey daemon"
2022-07-29 05:57:40 +00:00
2022-07-29 06:12:30 +00:00
command="/usr/bin/npm"
command_args="start"
command_user="foundkey"
2022-07-29 05:57:40 +00:00
2022-07-29 06:12:30 +00:00
supervisor="supervise-daemon"
supervise_daemon_args=" -d /home/foundkey/foundkey -e NODE_ENV=\"production\""
2022-07-29 05:57:40 +00:00
2022-07-29 06:12:30 +00:00
pidfile="/run/${RC_SVCNAME}.pid"
2022-07-29 05:57:40 +00:00
2022-07-29 06:12:30 +00:00
depend() {
need net
use logger
2022-07-29 05:57:40 +00:00
2022-07-29 06:12:30 +00:00
# alternatively, uncomment if using nginx reverse proxy
#use logger nginx
}
```
2022-07-29 05:57:40 +00:00
Mark the script as executable and enable the service to start on boot:
2022-07-29 05:57:40 +00:00
```sh
chmod +x /etc/init.d/foundkey
rc-update add foundkey
```
2022-07-29 05:57:40 +00:00
Start the FoundKey service:
2022-07-29 05:57:40 +00:00
```sh
rc-service foundkey start
```
2022-07-29 05:57:40 +00:00
2022-07-29 06:09:26 +00:00
You can check if the service is running with `rc-service foundkey status`.
2022-07-29 05:57:40 +00:00
### Updating FoundKey
When a new release comes out, simply fetch and merge in the new tag. If you plan on making additional changes on top of that tag, we suggest using the `--squash` option with `git merge`.
```sh
git fetch -t
git merge tags/v13.0.0-preview2
# you are now on the "next" release
```
Now you'll want to update your dependencies and rebuild:
```sh
yarn install
# Use build-parallel if your system has 4GB or more RAM and want faster builds
NODE_ENV=production yarn build
```
Next, run the database migrations:
```sh
yarn migrate
```
Then restart FoundKey if it's still running.
```sh
# Systemd
systemctl restart foundkey
# OpenRC
rc-service foundkey restart
```
2022-07-29 05:57:40 +00:00
If you encounter any problems with updating, please try the following:
1. `yarn clean` or `yarn cleanall`
2022-07-29 06:09:26 +00:00
2. Retry update (Don't forget `yarn install`)
2022-07-29 05:57:40 +00:00
## Need Help?
If you have any questions or troubles, feel free to contact us on IRC: `#foundkey` on `irc.akkoma.dev`, port `6697` with SSL