Skip to content
Snippets Groups Projects
fresh.md 6.17 KiB
Newer Older
Mar0xy's avatar
Mar0xy committed
---
title: "Fresh Installation"
weight: 1100
toc: true
---

Before you start, you really need:

* an always-on machine that can receive connections from the Internet
* a domain name to dedicate to your Sharkey instance, resolving to the
  address(es) of that machine
* a web server running on that machine, with valid TLS certificates
  for the domain name

## With Docker

Prerequisites:

* Docker
* Compose Plugin

Create multiple directories:

dakkar's avatar
dakkar committed
```bash
mkdir Sharkey && mkdir Sharkey/.config
```
Mar0xy's avatar
Mar0xy committed

Fetch all required examples and enter directory:

dakkar's avatar
dakkar committed
```bash
wget -O Sharkey/docker-compose.yml https://activitypub.software/TransFem-org/Sharkey/-/raw/stable/docker-compose_example.yml
wget -O Sharkey/.config/default.yml https://activitypub.software/TransFem-org/Sharkey/-/raw/stable/.config/docker_example.yml
wget -O Sharkey/.config/docker.env https://activitypub.software/TransFem-org/Sharkey/-/raw/stable/.config/docker_example.env
dakkar's avatar
dakkar committed
cd Sharkey
```
Mar0xy's avatar
Mar0xy committed

Edit `.config/default.yml`, there are comments explaining what each
option means. In particular, we're going to assume you have:

dakkar's avatar
dakkar committed
```yaml
url: https://{YOUR DOMAIN NAME}/
```
Mar0xy's avatar
Mar0xy committed

(replace `{YOUR DOMAIN NAME}` with the domain name we talked about
at the start).

Edit `docker-compose.yml`, there are multiple comments there as
well. If you want to set up note search with meilisearch, uncomment
all of meilisearch options, otherwise proceed to do the following
changes in the `services:` / `web:` section:

* uncomment the line that starts with `image:`
* remove the line `build: .`

Starting:

dakkar's avatar
dakkar committed
```bash
docker compose up -d
```
Mar0xy's avatar
Mar0xy committed

## Manually

[Same as
Misskey](https://misskey-hub.net/en/docs/install/manual.html).

Prerequisites:

Minneyar's avatar
Minneyar committed
* Node.js version 20.4 or later, with *both* `npm` and `pnpm`
Mar0xy's avatar
Mar0xy committed
  installed (`corepack enable` should suffice, make sure you run it
Minneyar's avatar
Minneyar committed
  as `root` if you're using your system Node.js)
Mar0xy's avatar
Mar0xy committed
* PostgreSQL version 15 or later
* Redis
* FFmpeg
* all the various packages to compile and build C code, and Python (on
  Debian-style systems, that's `build-essential` & `python`)

Create a `sharkey` user:

dakkar's avatar
dakkar committed
```bash
adduser --disabled-password --disabled-login sharkey
```
Mar0xy's avatar
Mar0xy committed

start a shell as that user:

dakkar's avatar
dakkar committed
```bash
sudo -u sharkey -i
```
Mar0xy's avatar
Mar0xy committed

(or something like that), then:

dakkar's avatar
dakkar committed
```bash
git clone --recurse-submodules -b stable https://activitypub.software/TransFem-org/Sharkey.git
dakkar's avatar
dakkar committed
cd Sharkey
pnpm install --frozen-lockfile
cp .config/example.yml .config/default.yml
```
Mar0xy's avatar
Mar0xy committed

Edit `.config/default.yml`, there are comments explaining what each
option means. In particular, we're going to assume you have:

dakkar's avatar
dakkar committed
```yaml
url: https://{YOUR DOMAIN NAME}/
db:
  host: localhost
  port: 5432
  db: sharkey
  user: sharkey
  pass: {YOUR PASSWORD}
```
Mar0xy's avatar
Mar0xy committed

(replace `{YOUR PASSWORD}` with an actual password you make up for
this, and `{YOUR DOMAIN NAME}` with the domain name we talked about
at the start)

Building:

dakkar's avatar
dakkar committed
```bash
pnpm run build
```
Mar0xy's avatar
Mar0xy committed

Create the PostgreSQL user and database, either with `createuser`
and `createdb` or with `sudo -u postgres psql` and then:

dakkar's avatar
dakkar committed
```sql
CREATE DATABASE sharkey WITH ENCODING = 'UTF8';
CREATE USER sharkey WITH ENCRYPTED PASSWORD '{YOUR_PASSWORD}';
GRANT ALL PRIVILEGES ON DATABASE sharkey TO sharkey;
ALTER DATABASE sharkey OWNER TO sharkey;
\q
```
Mar0xy's avatar
Mar0xy committed

(replace `{YOUR PASSWORD}` with the same password as before)

Then create the schema:

dakkar's avatar
dakkar committed
```bash
pnpm run init
```
Mar0xy's avatar
Mar0xy committed

And start it:

dakkar's avatar
dakkar committed
```bash
pnpm start
```
Mar0xy's avatar
Mar0xy committed

you should see a series of colourful lines, ending with something
like:

dakkar's avatar
dakkar committed
```text
Now listening on port 3000 on https://example.tld
```
Mar0xy's avatar
Mar0xy committed

but with a different URL at the end (you *did* change the `url`
setting in the config file, right?). Stop that process (control-C is
enough), and set up a system service for Sharkey.

### With systemd

Create a file `/etc/systemd/system/sharkey.service` containing:

dakkar's avatar
dakkar committed
```ini
[Unit]
Description=Sharkey daemon

[Service]
Type=simple
User=sharkey
ExecStart=/usr/bin/pnpm start
WorkingDirectory=/home/sharkey/Sharkey
Environment="NODE_OPTIONS=--max-old-space-size=8192"
Environment="NODE_ENV=production"
TimeoutSec=60
StandardOutput=journal
StandardError=journal
SyslogIdentifier=sharkey
Restart=always

[Install]
WantedBy=multi-user.target
```
Mar0xy's avatar
Mar0xy committed

(you may need to change that `/usr/bin/pnpm` if you're not using
Minneyar's avatar
Minneyar committed
your system Node.js).
dakkar's avatar
dakkar committed
```bash
sudo systemctl daemon-reload
sudo systemctl enable sharkey
sudo systemctl start sharkey
```
Mar0xy's avatar
Mar0xy committed

After that, `systemctl status sharkey` should show that it's
running.

### With OpenRC

Create a file `/etc/init.d/sharkey` containing:

dakkar's avatar
dakkar committed
```bash
#!/sbin/openrc-run
Mar0xy's avatar
Mar0xy committed

dakkar's avatar
dakkar committed
name=sharkey
description="Sharkey daemon"
Mar0xy's avatar
Mar0xy committed

dakkar's avatar
dakkar committed
command="/usr/bin/pnpm"
command_args="start"
command_user="sharkey"
Mar0xy's avatar
Mar0xy committed

dakkar's avatar
dakkar committed
supervisor="supervise-daemon"
supervise_daemon_args=" -d /home/sharkey/Sharkey -e NODE_ENV=production -e \"NODE_OPTIONS=--max-old-space-size=8192\""
Mar0xy's avatar
Mar0xy committed

dakkar's avatar
dakkar committed
pidfile="/run/${RC_SVCNAME}.pid"
Mar0xy's avatar
Mar0xy committed

dakkar's avatar
dakkar committed
depend() {
  need net
  use logger nginx
}
```
Mar0xy's avatar
Mar0xy committed

(you may need to change that `/usr/bin/pnpm` if you're not using
Minneyar's avatar
Minneyar committed
your system Node.js).
dakkar's avatar
dakkar committed
```bash
sudo rc-update add sharkey
sudo rc-service sharkey start
```
Mar0xy's avatar
Mar0xy committed

After that, `rc-service sharkey status` should show that it's
running.

## Configure the web server

### NGINX

See [Misskey's
instructions](https://misskey-hub.net/en/docs/admin/nginx.html)

Mar0xy's avatar
Mar0xy committed
## Update Sharkey
Mar0xy's avatar
Mar0xy committed

Fetch the latest image, restart:

```bash
docker compose down && docker compose build --pull && docker compose up -d
```

**NOTE**: if you are upgrading from 2024.3.1 or earlier, and are *not*
using S3 or similar, you will have to change the ownership of the
files on your disk, otherwise uploads won't work anymore. This is
because previous versions ran Sharkey as the root user, but we no
longer do that.

Run either:

```bash
sudo chown -R 991:991 Sharkey/files/
```

or:

```bash
docker compose exec --user=root web chown -R sharkey:sharkey /sharkey/files
```
Mar0xy's avatar
Mar0xy committed
Very similar to the installation process:

dakkar's avatar
dakkar committed
```bash
sudo -u sharkey -i
cd Sharkey
git checkout stable
git pull --recurse-submodules
pnpm install --frozen-lockfile
pnpm run build
pnpm run migrate
```
Mar0xy's avatar
Mar0xy committed

Then restart the service (`sudo systemctl restart sharkey` or
`rc-service sharkey restart`).

If there's problems with updating, you can run `pnpm run clean`
and/or `pnpm run clean-all` which will remove all the effects of a
Mar0xy's avatar
Mar0xy committed
previous build, then you can install+build+migrate+restart again.