Skip to content
Snippets Groups Projects
fresh.md 14.2 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

Daniel Ares's avatar
Daniel Ares committed
Please note that the first registered user account of your instance is subject to some restrictions and cannot be migrated, for example. Therefore, the account should not be used as a normal user account.

Mar0xy's avatar
Mar0xy committed
## With Docker

Prerequisites:

* Docker
* Compose Plugin

Refer to [Docker Engine's install
page](https://docs.docker.com/engine/install/) to get Docker and
Compose onto your machine.

Create the directories you'll need:
Mar0xy's avatar
Mar0xy committed

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/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).

You should also change the `setupPassword` value, so that your new
instance will be protected between when you start it and when you
create your first user.

Refer to [the Configuration Options page](../configuration/) for all
the various ways you can set configuration values.
Mar0xy's avatar
Mar0xy committed
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 (but also check out [all the search engine
options](../../customisation/search/)), otherwise proceed to do the
following changes in the `services:` / `web:` section:
Mar0xy's avatar
Mar0xy committed

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

It should look like this:

```yaml
services:
  web:
    image: registry.activitypub.software/transfem-org/sharkey:latest
    # build: .
    
```
Mar0xy's avatar
Mar0xy committed

Start the containers:
Mar0xy's avatar
Mar0xy committed

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

You can now open your instance's URL in your browser, to complete the
setup.
If you have problems uploading files to the drive, are *not* using S3,
you may need to run either:

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

or:

```bash
docker compose exec --user=root web chown -R sharkey:sharkey /sharkey/files
```

to fix the permissions on that directory.

Mar0xy's avatar
Mar0xy committed
## Manually

These instructions are very similar to [Misskey's manual installation
instructions](https://misskey-hub.net/en/docs/install/manual.html).
Mar0xy's avatar
Mar0xy committed

Prerequisites:

* more than 2GB of free RAM, we recommend at least 4GB
* Node.js version 22.11 or later, with *both* `npm` and `pnpm`
dakkar's avatar
dakkar committed
  installed (`corepack enable` should suffice, make sure you run it 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`)
* some system libraries and their development headers: pango, cairo,
  pixman (on Debian-style systems, that's `libpango1.0-dev
  libcairo2-dev libpixman-1-dev`)
Mar0xy's avatar
Mar0xy committed

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:
Mar0xy's avatar
Mar0xy committed

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

(or something like that), then clone the Sharkey repository, and copy
the example configuration file:
Mar0xy's avatar
Mar0xy committed

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)

You should also change the `setupPassword` value, so that your new
instance will be protected between when you start it and when you
create your first user.

Refer to [the Configuration Options page](../configuration/) for all
the various ways you can set configuration values, and check out [all
the search engine options](../../customisation/search/).
Build Sharkey:
Mar0xy's avatar
Mar0xy committed

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 running these
commands inside `psql`:
Mar0xy's avatar
Mar0xy committed

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 Sharkey:
Mar0xy's avatar
Mar0xy committed

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.

You can now open your instance's URL in your browser, to complete the
setup.
Mar0xy's avatar
Mar0xy committed
### 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.

You can now open your instance's URL in your browser, to complete the
setup.
Mar0xy's avatar
Mar0xy committed
## Configure the web server

### NGINX

See [Misskey's
instructions](https://misskey-hub.net/en/docs/for-admin/install/resources/nginx/)
about configuring NGINX. They provide a good starting point that can
be modified to fit your needs.
Mar0xy's avatar
Mar0xy committed

### HAProxy
> Heads up - Sharkey doesn't officially support HAProxy, but you can still find community support for it within the discord.

Add these lines to your frontend:

```haproxy
  acl sharkey hdr(Host) -i sharkey.example
  use_backend sharkey-be if sharkey
```

And these to your backend:
Kio's avatar
Kio committed

```haproxy
  backend sharkey-be
    http-reuse aggressive
    option forwarded
    option forwardfor
    mode http
    option redispatch
    timeout queue 15s
    http-request set-header X-Real-IP %[src]
    http-request set-header X-Forwarded-Proto https
    server sharkey-server <ip>:3000 check observe layer7 error-limit 10 on-error mark-down inter 2s rise 10 slowstart 10s
```
Kio's avatar
Kio committed

Kio!'s avatar
Kio! committed
Check out Latte Macchiato's [guide](https://blog.lattemacchiato.dev/how-to-make-your-fedi-instance-performance-not-suck/) to making your fedi instance not suck for more optimization tricks with HAProxy.

### Traefik
> Heads up - Sharkey doesn't officially support Traefik, but you can still find community support for it within the discord.

Our configs will make the assumptions that sharkey is listening to port `3000`, your https(443) entrypoint is called ``webSecure`` and that you have a certificate resolver ready called ``myResolver``. Change these as necessary. Remember to change ``sharkey.example`` to your instances domain name.

#### Docker Labels
Append these labels to your sharkey service in docker-compose.yml:
Kio's avatar
Kio committed

```yml
    ...[your docker config]...
    labels:
      - "traefik.http.routers.sharkey.rule=Host(`sharkey.example`)"
      - "traefik.http.services.sharkey.loadbalancer.server.port=3000"
      - "traefik.http.routers.sharkey.tls=true"
      - "traefik.http.routers.sharkey.tls.certresolver=myResolver"
    ...[your docker config]...
```
Kio's avatar
Kio committed

#### Dynamic Config
insert this into your dynamic config:
Kio's avatar
Kio committed

```yml
http:
  routers:
      sharkey:
        entryPoints: ["web", "webSecure"]
        service: "sharkey-be"
        tls:
          certresolver: myResolver

  services:
    sharkey-be:
      loadBalancer:
        servers:
          - url: "http://<ip>:3000"
```

### Caddy
> Heads up - Sharkey doesn't officially support Caddy, but you can still find community support for it within the discord.

In your Caddyfile, insert the following instructions. Change sharkey.example to your instance domain. Change the port specified if you changed the host port for your Docker container.
Kio's avatar
Kio committed

```Caddyfile
sharkey.example {
reverse_proxy localhost:3000
}
### Apache

Something like this works for Apache 2.4.47 or later:

```apacheconf
<VirtualHost *>
 DocumentRoot /var/empty
 ServerName sharkey.example

 SSLEngine On
dakkar's avatar
dakkar committed
 RequestHeader set X-Forwarded-Proto "https"

 AllowEncodedSlashes NoDecode

dakkar's avatar
dakkar committed
 ProxyPreserveHost On

 ProxyPass "/" "http://127.0.0.1:3000/" upgrade=websocket
dakkar's avatar
dakkar committed
 ProxyPassReverse "/" "https://sharkey.example/"
 ProxyPassReverse "/" "http://127.0.0.1:3000/"

 # or, if your Sharkey listens on a UNIX socket
 # ProxyPass "/" "unix:/opt/sharkey/sharkey.sock|http://127.0.0.1/" upgrade=websocket
dakkar's avatar
dakkar committed
 # ProxyPassReverse "/" "https://sharkey.example/"
 # ProxyPassReverse "/" "unix:/opt/sharkey/sharkey.sock|http://127.0.0.1/"
Mar0xy's avatar
Mar0xy committed
## Update Sharkey
Mar0xy's avatar
Mar0xy committed

Fetch the latest image, restart:

```bash
docker compose 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 bash
dakkar's avatar
dakkar committed
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.
**NOTE**: if you are upgrading from 2024.9.4 or earlier, Sharkey now
needs Node.js 22.11, and you will almost certainly need to run `pnpm
run clean-all` before `pnpm install`, otherwise you'll end up with
some dependencies (e.g. `re2`) linked to the wrong libraries.

**NOTE**: if you upgrading from 2024.11.2 or earlier, Sharkey now
needs some system libraries and their development headers: pango,
cairo, pixman (on Debian-style systems, that's `libpango1.0-dev
libcairo2-dev libpixman-1-dev`)

### Caching issues

It's possible that the web server (or the CDN, if you've configured
one) caches some of our assets for longer than needed, which may show
up as broken icons after updating to a new Sharkey release. You may
therefore need to clear whatever cache you have.

#### Clear NGINX cache

You may clear NGINX's cache by manually deleting the cache directory
or all of the cached files within it.

* First, we must locate the cache directory. This is a configured by
  the `proxy_cache_path` directive, which is found in the global
  section of any NGINX configuration file. Under typical
  circumstances, there should only be one directive and it should be
  located in the primary configuration file. Some templates and
  example configurations have erroneously placed the directive within
  a virtual host, so you should check all configuration files to be
  sure. When you've found the directive, the cache directory will be
  listed in the first parameter. Here's an example:

  # Here, the cache directory is "/var/cache/nginx".
  proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=cache1:16m max_size=1g inactive=720m use_temp_path=off;
  ```

* Next, we need to stop the NGINX server. We cannot clear the cache
  while NGINX is running; this can cause corruption and failed
  requests. Steps to exit the server will vary by operating system,
  but the follow command can be used under systemd environments:
  `systemctl stop nginx`. For the rare platforms that use systemd
  services with a different init system (notably, WSL), this alternate
  command should be used: `service nginx stop`.
* Now we can actually clear the cache. As mentioned above, this is
  done by removing all files from the cache directory that we located
  in step 1. You will likely need root permissions to modify this
  directory. You can use this command to remove the directory:

  ```bash
dakkar's avatar
dakkar committed
  sudo rm ${path_to_cache:?}
dakkar's avatar
dakkar committed
  Make sure to replace `${path_to_cache:?}` with the actual path we
  determined in step 1!
* We're done! It's finally time to re-start NGINX. As before, the
  commands will vary between platforms. Systemd environments can use
  `systemctl start nginx`, others can use `service nginx start`. On
  startup, NGINX will automatically re-create the empty cache and
  resume using it.