### Setup PostgreSQL (Arch) Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Installs and starts the PostgreSQL service on Arch-based systems. Includes steps for manual data directory initialization if needed. ```bash sudo pacman -S postgresql sudo systemctl start postgresql # If the systemctl command errors, then run the following sudo mkdir /var/lib/postgres/data sudo chown postgres:postgres /var/lib/postgres/data sudo -u postgres initdb -D /var/lib/postgres/data sudo systemctl start postgresql ``` -------------------------------- ### Setup PostgreSQL (Debian) Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Installs and starts the PostgreSQL service on Debian-based systems. ```bash sudo apt install postgresql sudo systemctl start postgresql ``` -------------------------------- ### Setup PostgreSQL (macOS) Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Installs PostgreSQL using Homebrew and starts the service. Also creates a superuser role. ```bash brew install postgresql brew services start postgresql $(brew --prefix postgresql)/bin/createuser -s postgres ``` -------------------------------- ### Install Frontend Dependencies and Run Dev Server Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Installs frontend dependencies using pnpm and starts the lemmy-ui development server. The UI connects to the backend on localhost:8536 and is accessible at localhost:1234. ```bash pnpm i pnpm dev ``` -------------------------------- ### Copy and Edit Environment File Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/on_aws.md Copy the example environment file and edit it with your site settings before proceeding with the installation. ```shell cp example.env.local .env.local # edit .env.local ``` -------------------------------- ### Install Docker and Clone Lemmy Repository (Arch) Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/03-docker-development.md Installs necessary packages like git and docker-compose, and starts the Docker service on Arch-based systems. Cloning the repository is a separate step. ```bash sudo pacman -S git docker-compose sudo systemctl start docker ``` -------------------------------- ### Install Docker and Clone Lemmy Repository (Debian) Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/03-docker-development.md Installs necessary packages like git and docker-compose, starts the Docker service, and clones the Lemmy repository with submodules on Debian-based systems. ```bash sudo apt install git docker-compose sudo systemctl start docker git clone https://github.com/LemmyNet/lemmy --recursive ``` -------------------------------- ### Enable and Start Tor Daemon Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/tor_hidden_service.md Enables the Tor service to start on boot and starts it immediately. ```bash systemctl enable --now tor ``` -------------------------------- ### Enable and Start Lemmy UI Service Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/from_scratch.md Reloads the systemd daemon, enables the Lemmy UI service to start on boot, and then starts the service. ```bash sudo systemctl daemon-reload sudo systemctl enable lemmy-ui sudo systemctl start lemmy-ui ``` -------------------------------- ### Install AWS CDK and Deploy Lemmy Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/on_aws.md Install the AWS CDK globally, install project dependencies, bootstrap the CDK, and deploy the stack to your AWS account. ```shell npm install -g aws-cdk npm install cdk bootstrap cdk deploy ``` -------------------------------- ### Enable and Start Lemmy Service Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/from_scratch.md Reloads the systemd daemon, enables the Lemmy service to start on boot, and then starts the service immediately. ```bash sudo systemctl daemon-reload sudo systemctl enable lemmy sudo systemctl start lemmy ``` -------------------------------- ### Install Prerequisite Packages Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/tor_hidden_service.md Installs necessary packages for adding external APT repositories. ```bash apt install -y apt-transport-https ca-certificates gpg lsb-release wget ``` -------------------------------- ### Install pgFormatter (Arch) Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Installs the pgFormatter tool on Arch-based systems. ```bash sudo pacman -S pgformatter ``` -------------------------------- ### Community List Example Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/04-api.md Example of how to list communities using the API with a GET request. ```APIDOC ## GET /api/{version}/community/list ### Description Retrieves a list of communities, sortable by various criteria. ### Method GET ### Endpoint `/api/{version}/community/list` ### Parameters #### Query Parameters - **sort** (string) - Optional - The sorting criteria for the community list (e.g., 'Hot'). ### Request Example ```bash curl "https://lemmy.ml/api/{version}/community/list?sort=Hot" ``` ``` -------------------------------- ### Install Node.js (macOS) Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Installs Node.js using Homebrew on macOS. ```bash brew install node ``` -------------------------------- ### Start Local Federation Instances Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/03-docker-development.md Starts multiple local Lemmy instances for testing federation functionality. Navigate to the 'docker/federation' directory before running. ```bash cd docker/federation ./start-local-instances.bash ``` -------------------------------- ### Install Taplo CLI Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Installs the Taplo TOML toolkit command-line interface using Cargo. ```bash cargo install taplo-cli --locked ``` -------------------------------- ### Install pgFormatter (Debian) Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Installs the pgFormatter tool on Debian-based systems. ```bash sudo apt install pgformatter ``` -------------------------------- ### Install PostgreSQL Dependencies Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/from_scratch.md Installs necessary packages for PostgreSQL and adds the official PostgreSQL repository. Ensure you have wget and GPG keys configured. ```bash sudo apt install -y wget ca-certificates pkg-config wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" >> /etc/apt/sources.list.d/pgdg.list' sudo apt update sudo apt install libssl-dev libpq-dev postgresql ``` -------------------------------- ### Install pgFormatter (macOS) Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Installs the pgFormatter tool on macOS using Homebrew. ```bash brew install pgformatter ``` -------------------------------- ### Install Build Requirements (Arch) Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Installs necessary build tools and libraries for Arch-based systems. ```bash sudo pacman -S git cargo pkg-config postgresql-libs curl jq ``` -------------------------------- ### Install Tor Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/tor_hidden_service.md Updates package lists and installs the Tor daemon. ```bash apt update && apt install -y tor ``` -------------------------------- ### Install Build Requirements (Fedora) Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Installs necessary build tools and libraries for Fedora-based systems. ```bash sudo dnf install git cargo pkg-config libpq-devel curl postgresql-server postgresql-contrib jq ``` -------------------------------- ### Setup Lemmy PostgreSQL Database Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/from_scratch.md Creates a dedicated user and database for Lemmy in PostgreSQL. Remember to replace 'db-passwd' with a strong, unique password. ```bash sudo -iu postgres psql -c "CREATE USER lemmy WITH PASSWORD 'db-passwd';" sudo -iu postgres psql -c "CREATE DATABASE lemmy WITH OWNER lemmy;" ``` -------------------------------- ### Starting Lemmy_server HTTP servers Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/horizontal_scaling.md These commands start Lemmy_server processes configured to handle HTTP requests, disabling activity sending and scheduled tasks for each instance. ```bash # 3 http servers lemmy_server --disable-activity-sending --disable-scheduled-tasks lemmy_server --disable-activity-sending --disable-scheduled-tasks lemmy_server --disable-activity-sending --disable-scheduled-tasks ``` -------------------------------- ### Install Build Requirements (Debian) Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Installs necessary build tools and libraries for Debian-based systems. ```bash sudo apt install git cargo pkg-config libpq-dev curl jq ``` -------------------------------- ### Install pnpm Globally Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Installs the pnpm package manager globally using npm. ```bash npm install -g pnpm ``` -------------------------------- ### Install Node.js 20 and pnpm Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/from_scratch.md Installs Node.js version 20 and the pnpm package manager on Ubuntu systems, as repository versions are often outdated. ```bash # nodejs sudo apt install -y ca-certificates curl gnupg sudo mkdir -p /etc/apt/keyrings curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list sudo apt update sudo apt install nodejs # pnpm npm i -g pnpm ``` -------------------------------- ### Install Nginx and Certbot Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/from_scratch.md Installs Nginx and Certbot for managing web server and TLS certificates. ```bash sudo apt install nginx certbot python3-certbot-nginx ``` -------------------------------- ### Comment Like Example Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/04-api.md Example of how to like a comment using the API with a POST request. ```APIDOC ## POST /api/{version}/comment/like ### Description Allows a user to like or unlike a comment. ### Method POST ### Endpoint `/api/{version}/comment/like` ### Parameters #### Request Body - **comment_id** (integer) - Required - The ID of the comment to like. - **score** (integer) - Required - The score to apply (1 for like, -1 for dislike). - **auth** (string) - Required - Authentication token. ### Request Example ```json { "comment_id": 374, "score": 1, "auth": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MiwiaXNzIjoidGVzdC5sZW1teS5tbCJ9.P77RX_kpz1a_geY5eCp29sl_5mAm-k27Cwnk8JcIZJk" } ``` ``` -------------------------------- ### Install ImageMagick for pict-rs (AppImage) Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/from_scratch.md Installs ImageMagick version 7 using an AppImage, which is required for pict-rs image hosting. Note that AppImage installations may not work in standard LXC containers due to FUSE limitations. ```bash sudo apt install ffmpeg exiftool libgexiv2-dev --no-install-recommends # save the file to a working folder it can be verified before copying to /usr/bin/ wget https://download.imagemagick.org/ImageMagick/download/binaries/magick # compare hash with the "message digest" on the official page linked above sha256sum magick sudo mv magick /usr/bin/ sudo chmod 755 /usr/bin/magick ``` -------------------------------- ### Clone and Build Lemmy UI Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/from_scratch.md Clones the lemmy-ui repository, checks out a specific version, installs dependencies using pnpm, and builds the production version. ```bash # dont compile as admin cd /opt/lemmy sudo -u lemmy bash git clone https://github.com/LemmyNet/lemmy-ui.git --recursive cd lemmy-ui git checkout 0.18.5 # replace with the version you want to install pnpm i pnpm build:prod exit ``` -------------------------------- ### Download Default Configuration Files Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/install_docker.md Download the default Docker Compose file, configuration template, and Nginx configuration files. These files serve as the base for your Lemmy installation. ```bash wget https://raw.githubusercontent.com/LemmyNet/lemmy-docs/main/assets/docker-compose.yml wget https://raw.githubusercontent.com/LemmyNet/lemmy-ansible/main/examples/config.hjson -O lemmy.hjson wget https://raw.githubusercontent.com/LemmyNet/lemmy-ansible/main/templates/nginx_internal.conf wget https://raw.githubusercontent.com/LemmyNet/lemmy-ansible/main/files/proxy_params ``` -------------------------------- ### Install Rust Build Dependencies Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/from_scratch.md Installs essential build tools for Rust compilation, including protobuf-compiler and GCC. This is necessary for compiling Lemmy and its dependencies. ```bash sudo apt install protobuf-compiler gcc ``` -------------------------------- ### Add ruby annotations Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/users/02-media.md Use curly brace syntax or ruby tags to add pronunciation or translation guides. ```markdown {Ruby|text} ``` ```html Rubytext ``` -------------------------------- ### Start Lemmy Docker Containers Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/install_docker.md Start all the Docker containers defined in the docker-compose.yml file in detached mode. This command brings up the Lemmy instance and its associated services. ```bash docker compose up -d ``` -------------------------------- ### Compile and Install Lemmy Server Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/from_scratch.md Updates Rust toolchain, pulls the latest Lemmy code, checks out a specific version, builds the release binary, and replaces the running server binary. ```bash rustup update cd lemmy git checkout main git pull --tags git checkout 0.18.5 # replace with version you are updating to git submodule update cargo build --release # copy compiled binary to destination # the old file will be locked by the already running application, so this sequence is recommended: sudo -- sh -c 'systemctl stop lemmy && cp target/release/lemmy_server /opt/lemmy/lemmy-server/lemmy_server && systemctl start lemmy' ``` -------------------------------- ### Starting Lemmy_server scheduled tasks process Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/horizontal_scaling.md This command starts a Lemmy_server process dedicated to scheduled tasks, disabling its HTTP server and activity sending capabilities. ```bash # scheduled tasks lemmy_server --disable-http-server --disable-activity-sending ``` -------------------------------- ### List Communities (GET) Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/04-api.md Use this endpoint to list communities. The `sort` parameter can be used to order the results. ```bash curl "https://lemmy.ml/api/{version}/community/list?sort=Hot" ``` -------------------------------- ### Image Proxy Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/09-api-v4.md Image proxying is now handled by `GET /api/v4/image/proxy`. ```APIDOC ## Image Proxy ### Description Proxies an image request. ### Method GET ### Endpoint /api/v4/image/proxy ``` -------------------------------- ### Upgrade Lemmy UI Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/from_scratch.md Updates Lemmy UI to the latest version by pulling changes, installing dependencies, and rebuilding the production assets. Assumes running as the `lemmy` user. ```bash cd /opt/lemmy/lemmy-ui sudo -u lemmy bash git checkout main git pull --tags git checkout 0.18.5 # replace with the version you are updating to git submodule update pnpm install pnpm build:prod exit sudo systemctl restart lemmy-ui ``` -------------------------------- ### Initialize PostgreSQL Database Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Creates a 'lemmy' user and database with specified password and sets the database URL environment variable. ```bash psql -c "create user lemmy with password 'password' superuser;" -U postgres psql -c 'create database lemmy with owner lemmy;' -U postgres export LEMMY_DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy ``` -------------------------------- ### Create Lemmy Directories Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/from_scratch.md Sets up the required directory structure in `/opt/lemmy` for the Lemmy server and its associated files, including directories for pict-rs. ```bash sudo mkdir /opt/lemmy sudo mkdir /opt/lemmy/lemmy-server sudo mkdir /opt/lemmy/pictrs sudo mkdir /opt/lemmy/pictrs/files sudo mkdir /opt/lemmy/pictrs/sled-repo sudo mkdir /opt/lemmy/pictrs/old sudo chown -R lemmy:lemmy /opt/lemmy ``` -------------------------------- ### Create Lemmy Directory Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/install_docker.md Create a directory for Lemmy files and navigate into it. This is the first step in setting up the Docker environment. ```bash mkdir lemmy cd lemmy ``` -------------------------------- ### Run Federation and API Tests Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Navigates to the `api_tests` directory and runs the federation test script. ```bash cd api_tests ./run-federation-test.sh ``` -------------------------------- ### Download Database Optimization Tool Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/install_docker.md Download a configuration file for optimizing the PostgreSQL database. This file can be used with tuning tools to adjust database parameters based on system specifications. ```bash wget https://raw.githubusercontent.com/LemmyNet/lemmy-ansible/main/examples/customPostgresql.conf ``` -------------------------------- ### Configure Hosts for Federation Tests Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Adds entries to the `/etc/hosts` file to map hostnames to localhost for federation and API testing. ```bash 127.0.0.1 lemmy-alpha 127.0.0.1 lemmy-beta 127.0.0.1 lemmy-gamma 127.0.0.1 lemmy-delta 127.0.0.1 lemmy-epsilon ``` -------------------------------- ### Get My User Information Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/09-api-v4.md The `my_user` field has been removed from the `/api/v4/site` endpoint. User-specific information is now available via the `GET /api/v4/account` endpoint. ```APIDOC ## Get My User Information ### Description Retrieves the current authenticated user's information. ### Method GET ### Endpoint /api/v4/account ``` -------------------------------- ### Enable Tor Repository Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/tor_hidden_service.md Configures APT to use the official deb.torproject.org repository for Tor packages. ```bash bash -c 'dist=$(lsb_release -s -c); /bin/echo -e "deb [signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] \ https://deb.torproject.org/torproject.org $dist main\n\ndeb-src [signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] https://deb.torproject.org/torproject.org $dist main" > /etc/apt/sources.list.d/tor.list' ``` -------------------------------- ### Sample Backup Script Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/backup_and_restore.md A script to perform both database backup via SSH and volume folder backup using rsync. Ensure `MY_USER`, `MY_IP`, `LEMMY_LOCATION`, `BACKUP_LOCATION`, and `INSTANCE_NAME` are correctly configured. ```bash #!/bin/sh # DB Backup ssh MY_USER@MY_IP "docker compose exec postgres pg_dumpall -c -U lemmy" | gzip > ~/BACKUP_LOCATION/INSTANCE_NAME_dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql.gz # Volumes folder Backup rsync -avP -zz --rsync-path="sudo rsync" MY_USER@MY_IP:/LEMMY_LOCATION/volumes ~/BACKUP_LOCATION/FOLDERNAME ``` -------------------------------- ### Image Retrieval Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/09-api-v4.md Image retrieval is now handled by `GET /api/v4/image/{filename}`. ```APIDOC ## Image Retrieval ### Description Retrieves an image file. ### Method GET ### Endpoint /api/v4/image/{filename} ``` -------------------------------- ### Get Hidden Service Hostname Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/tor_hidden_service.md Retrieves the `.onion` address assigned to the Tor hidden service. ```bash cat /var/lib/tor/hidden_lemmy_service/hostname ``` -------------------------------- ### Restore Database from .sql.gz Backup Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/backup_and_restore.md Commands to restore a PostgreSQL database from a compressed SQL dump. Ensure the postgres container is running and then use `gunzip` and `psql` to import the data. Adjust permissions if necessary. ```bash docker compose up -d postgres # Restore from the .sql.gz backup gunzip < db_dump.sql | docker compose exec -T postgres psql -U lemmy # Note: You may need to change the permissions on the postgres directory, depending on your system. chown -R $USER volumes docker compose restart postgres # Continue with the startup docker compose up -d ``` -------------------------------- ### Pictrs Image Deletion Token Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/04-api.md This is an example of a delete token returned after an image upload, used for subsequent deletion requests. ```json { "files": [ { "delete_token": "{token}", "file": "{file}.jpg" } ], "msg": "ok" } ``` -------------------------------- ### Full Lemmy Configuration with Defaults Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/configuration.md This snippet displays the complete configuration structure for Lemmy, including all default values. It serves as a reference for available settings. ```hjson {{#include ../../lemmy/config/defaults.hjson}} ``` -------------------------------- ### Become Root User Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/tor_hidden_service.md Commands to switch to the root user for administrative tasks. Use `exit` to return to your account. ```bash sudo -i Password: [authenticate with current user password] ``` ```bash su - Password: [authenticate with root's password] ``` -------------------------------- ### Query Federation Queue State Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/troubleshooting.md Execute this SQL query to get detailed information about the federation queue state for each instance. This helps identify instances that are not up to date. ```sql select domain,currval('sent_activity_id_seq') as latest_id, last_successful_id,fail_count,last_retry from federation_queue_state join instance on instance_id = instance.id order by last_successful_id asc; ``` -------------------------------- ### Configure Plugins in lemmy.hjson Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/08-plugins.md Specify plugins to be loaded by Lemmy in the configuration file. Includes plugin file URL, hash for verification, and allowed hosts. ```json plugins: [{ file: "https://github.com/LemmyNet/lemmy-plugins/releases/download/0.1.3/rust_lingua.wasm", hash: "e1f58029f2ecca5127a4584609494120683b691fc63a543979ea071f32cf690f", allowed_hosts: ["0.0.0.0"] }] ``` -------------------------------- ### Example Prometheus Metrics Output Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/prometheus.md Sample output from the /metrics endpoint, illustrating HTTP request duration histograms and connection pool metrics. Note that each endpoint/method/status combination generates a histogram. ```text lemmy_api_http_requests_duration_seconds_bucket{endpoint="/api/v3/post/list",method="GET",status="200",le="0.005"} 0 lemmy_api_http_requests_duration_seconds_bucket{endpoint="/api/v3/post/list",method="GET",status="200",le="0.01"} 0 lemmy_api_http_requests_duration_seconds_bucket{endpoint="/api/v3/post/list",method="GET",status="200",le="0.025"} 5 lemmy_api_http_requests_duration_seconds_bucket{endpoint="/api/v3/post/list",method="GET",status="200",le="0.05"} 10 lemmy_api_http_requests_duration_seconds_bucket{endpoint="/api/v3/post/list",method="GET",status="200",le="0.1"} 12 lemmy_api_http_requests_duration_seconds_bucket{endpoint="/api/v3/post/list",method="GET",status="200",le="0.25"} 12 lemmy_api_http_requests_duration_seconds_bucket{endpoint="/api/v3/post/list",method="GET",status="200",le="0.5"} 12 lemmy_api_http_requests_duration_seconds_bucket{endpoint="/api/v3/post/list",method="GET",status="200",le="1"} 12 lemmy_api_http_requests_duration_seconds_bucket{endpoint="/api/v3/post/list",method="GET",status="200",le="2.5"} 12 lemmy_api_http_requests_duration_seconds_bucket{endpoint="/api/v3/post/list",method="GET",status="200",le="5"} 12 lemmy_api_http_requests_duration_seconds_bucket{endpoint="/api/v3/post/list",method="GET",status="200",le="10"} 12 lemmy_api_http_requests_duration_seconds_bucket{endpoint="/api/v3/post/list",method="GET",status="200",le="+Inf"} 12 lemmy_api_http_requests_duration_seconds_sum{endpoint="/api/v3/post/list",method="GET",status="200"} 0.3834808429999999 lemmy_api_http_requests_duration_seconds_count{endpoint="/api/v3/post/list",method="GET",status="200"} 12 lemmy_api_http_requests_total{endpoint="/api/v3/post/list",method="GET",status="200"} 12 # HELP lemmy_db_pool_available_connections Number of available connections in the pool # TYPE lemmy_db_pool_available_connections gauge lemmy_db_pool_available_connections 2 # HELP lemmy_db_pool_connections Current number of connections in the pool # TYPE lemmy_db_pool_connections gauge lemmy_db_pool_connections 2 # HELP lemmy_db_pool_max_connections Maximum number of connections in the pool # TYPE lemmy_db_pool_max_connections gauge lemmy_db_pool_max_connections 5 # HELP process_cpu_seconds_total Total user and system CPU time spent in seconds. # TYPE process_cpu_seconds_total counter process_cpu_seconds_total 14 # HELP process_max_fds Maximum number of open file descriptors. # TYPE process_max_fds gauge process_max_fds 1073741816 # HELP process_open_fds Number of open file descriptors. # TYPE process_open_fds gauge process_open_fds 91 ``` -------------------------------- ### Build Lemmy Backend Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/from_scratch.md Compiles the Lemmy backend in release mode using Cargo. This command should be run from the root of the cloned Lemmy repository. ```bash cargo build --release ``` -------------------------------- ### Download Traefik Docker Compose File Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/separate_subdomains.md Use this command to download the Traefik Docker Compose file for setting up Lemmy on separate subdomains. ```bash wget https://raw.githubusercontent.com/LemmyNet/lemmy-docs/main/assets/separate_subdomains/traefik/compose.yml ``` -------------------------------- ### Configure Lemmy UI Backend URL Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/1.0_upgrade.md Adjust Lemmy UI environment variables to point to the correct backend service. Ensure LEMMY_UI_BACKEND_INTERNAL points to the internal service address and LEMMY_UI_BACKEND to the public-facing URL. ```sh - LEMMY_UI_BACKEND_INTERNAL=http://lemmy:8536 - LEMMY_UI_BACKEND=https://voyager.lemmy.ml ``` -------------------------------- ### Full Database Backup Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/backup_and_restore.md Use this command to create a compressed SQL dump of the entire PostgreSQL database. The backup file is named with a timestamp. ```bash docker compose exec postgres pg_dumpall -c -U lemmy | gzip > lemmy_dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql.gz ``` -------------------------------- ### Run Multiple Lemmy Servers for Federation Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/horizontal_scaling.md Configure multiple lemmy_server instances to distribute federation processing. Each instance should have a unique federate-process-index and the same federate-process-count. ```bash lemmy_server --disable-http-server --disable-scheduled-tasks --federate-process-index=1 --federate-process-count=3 lemmy_server --disable-http-server --disable-scheduled-tasks --federate-process-index=2 --federate-process-count=3 lemmy_server --disable-http-server --disable-scheduled-tasks --federate-process-index=3 --federate-process-count=3 ``` -------------------------------- ### Create Lemmy System User Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/from_scratch.md Creates a dedicated system user account for the lemmy_server application. This user will run the Lemmy backend process. ```bash sudo adduser lemmy --system --disabled-login --no-create-home --group ``` -------------------------------- ### Instance Object Structure (ActivityPub) Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/05-federation.md Defines the structure of an Instance object in ActivityPub format, used for representing Lemmy instances in federated communication. Includes fields like name, summary, content, icon, inbox, and publicKey. ```json { "@context": [ "https://www.w3.org/ns/activitystreams", { "@language": "en" } ], "type": "Application", "name": "string", "summary": "string", "content": "string", "icon": { "type": "Image", "url": "string" }, "image": { "type": "Image", "url": "string" }, "inbox": "string", "endpoints": { "sharedInbox": "string" }, "published": "string", "updated": "string", "publicKey": { "id": "string", "owner": "string", "publicKeyPem": "string" } } ``` -------------------------------- ### Verify Architecture Support Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/tor_hidden_service.md Check if your system's architecture is supported by the Tor package repository. ```bash dpkg --print-architecture ``` -------------------------------- ### Automate Let's Encrypt Certificate Renewal Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/from_scratch.md Adds a daily cron job to renew Let's Encrypt certificates and reload Nginx. Replace `example.com` with your domain. ```bash @daily certbot certonly --nginx --cert-name example.com -d example.com --deploy-hook 'nginx -s reload' ``` -------------------------------- ### Download NGINX Internal Configuration Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/separate_subdomains.md Use this command to download the NGINX internal configuration file. Remember to edit it to replace the resolver placeholder. ```bash wget https://raw.githubusercontent.com/LemmyNet/lemmy-docs/main/assets/separate_subdomains/nginx/nginx_internal.conf ``` -------------------------------- ### ActivityPub Context for Lemmy Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/05-federation.md The ActivityPub context is identical for all activities and objects in Lemmy. ```json "@context": [ "https://join-lemmy.org/context.json", "https://www.w3.org/ns/activitystreams" ], ``` -------------------------------- ### Run Prometheus Server (Local) Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/prometheus.md Command to run a Prometheus server locally, mounting a configuration file. ```shell docker run -p 9090:9090 -v prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus ``` -------------------------------- ### Test Lemmy Federation with Curl Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/first_steps.md Use this command to verify that your instance's federation is working correctly. It should return JSON data, not an HTML file. ```bash curl -H 'Accept: application/activity+json' https://your-instance.com/u/your-username ``` ```bash curl -H 'Accept: application/activity+json' https://lemmy.ml/u/nutomic ``` -------------------------------- ### Useful CDK Commands Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/on_aws.md A list of common AWS CDK commands for managing the Lemmy deployment, including building, watching, testing, deploying, diffing, and synthesizing. ```shell npm run build npm run watch npm run test cdk deploy cdk diff cdk synth ``` -------------------------------- ### Nginx Configuration for ActivityPub Federation Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/troubleshooting.md Set up your Nginx reverse proxy to correctly route ActivityPub requests, specifically those with 'application/activity+json' or 'application/ld+json' accept headers, to the appropriate Lemmy backend port. ```nginx set $proxpass "http://0.0.0.0:{{ lemmy_ui_port }}"; if ($http_accept = "application/activity+json") { set $proxpass "http://0.0.0.0:{{ lemmy_port }}"; } if ($http_accept = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"") { set $proxpass "http://0.0.0.0:{{ lemmy_port }}"; } proxy_pass $proxpass; ``` -------------------------------- ### Clone Lemmy Repositories Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Clones the backend and frontend repositories, ensuring submodules are initialized. ```bash git clone https://github.com/LemmyNet/lemmy.git --recursive git clone https://github.com/LemmyNet/lemmy-ui.git --recursive ``` -------------------------------- ### Build Custom Docker Image for Lemmy Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/03-docker-development.md Builds a custom Docker image from the local Lemmy source code, tagging it with the current branch name. Use this to test modifications to the source code. ```bash sudo docker build . -f docker/Dockerfile --build-arg RUST_RELEASE_MODE=release -t "lemmy:${git rev-parse --abbrev-ref HEAD}" ``` -------------------------------- ### Minimal Lemmy Configuration Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/from_scratch.md Provides a basic configuration file for the Lemmy server. Ensure to replace placeholder values like database password and hostname. ```hjson { database: { # put your db-passwd from above password: "db-passwd" } # replace with your domain hostname: example.com bind: "127.0.0.1" federation: { enabled: true } # remove this block if you don't require image hosting pictrs: { url: "http://localhost:8080/" } } ``` -------------------------------- ### Format and Lint Lemmy Backend Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Formats the Rust code using `cargo fmt` and runs the linter script. ```bash cargo +nightly fmt --all ./scripts/lint.sh ``` -------------------------------- ### Prometheus Configuration for Lemmy (Local) Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/prometheus.md Minimal Prometheus server configuration to scrape metrics from a locally running Lemmy instance. ```yaml global: scrape_configs: - job_name: lemmy scrape_interval: 1m static_configs: - targets: - localhost:10002 ``` -------------------------------- ### Testing ActivityPub Endpoint Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/troubleshooting.md Verify that your reverse proxy is correctly serving ActivityPub content by using curl to fetch local objects. Ensure these commands return valid JSON. ```bash curl -H "Accept: application/activity+json" https://your-instance.com/u/some-local-user curl -H "Accept: application/activity+json" https://your-instance.com/c/some-local-community curl -H "Accept: application/activity+json" https://your-instance.com/post/123 # the id of a local post curl -H "Accept: application/activity+json" https://your-instance.com/comment/123 # the id of a local comment ``` -------------------------------- ### Configure Cargo for Faster Compilation Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/02-local-development.md Adds configuration to `~/.cargo/config.toml` to use sccache and mold for faster Rust compilation. Note: `-Zthreads` requires nightly Rust. ```toml [build] rustc-wrapper = "/usr/bin/sccache" [target.x86_64-unknown-linux-gnu] linker = "clang" rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold", "-Z", "threads=16"] ``` -------------------------------- ### Initialize and Update Git Submodules Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/03-docker-development.md Initializes and updates git submodules, which can resolve 'translations missing' errors during the Docker build process. ```bash git submodule init && git submodule update ``` -------------------------------- ### Obtain Let's Encrypt TLS Certificate Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/from_scratch.md Requests a TLS certificate from Let's Encrypt. Follow the interactive prompts. ```bash sudo certbot certonly --nginx ``` -------------------------------- ### Apply subscript formatting Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/users/02-media.md Use tilde syntax or sub tags for subscript text. ```markdown Some ~subscript~ text ``` ```html Some subscript text ``` -------------------------------- ### Run SQL Migration Down Script Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/troubleshooting.md Execute a specific SQL migration script to reverse database changes during a downgrade. Ensure the path to the migrations directory is correct. ```bash downfolder=2024-02-28-144211_hide_posts psql -d lemmy -a -f /path/to/migrations/${downfolder}/down.sql ``` -------------------------------- ### Announce Create Post Activity Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/contributors/05-federation.md Forwards a 'Create' activity (like a new post) to a community's followers. The community acts as the 'actor' in this announcement. ```json { "@context": "https://www.w3.org/ns/activitystreams", "type": "Announce", "actor": "https://sh.itjust.works/c/community_name", "to": [ "https://sh.itjust.works/u/user_name/followers" ], "object": { "@context": [ "https://www.w3.org/ns/activitystreams", { "lemmy": "https://joinlemmy.org/ns" } ], "type": "Create", "actor": "https://sh.itjust.works/u/post_author", "to": [ "https://sh.itjust.works/c/community_name" ], "cc": [ "https://sh.itjust.works/u/post_author/followers" ], "object": { "type": "Note", "content": "This is a new post.", "id": "https://sh.itjust.works/c/community_name/@post_author/post_id", "url": "https://sh.itjust.works/c/community_name/@post_author/post_id", "attributedTo": "https://sh.itjust.works/u/post_author", "to": [ "https://sh.itjust.works/c/community_name" ], "cc": [ "https://sh.itjust.works/u/post_author/followers" ], "published": "2023-01-01T12:00:00Z", "inbox": "https://sh.itjust.works/u/post_author/inbox" } } } ``` -------------------------------- ### Set Pictrs Folder Permissions Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/install_docker.md Create the directory for pictrs uploads and set the correct ownership and permissions. This ensures that the Lemmy instance can properly handle image uploads. ```bash mkdir -p volumes/pictrs sudo chown -R 991:991 volumes/pictrs ``` -------------------------------- ### Clear Existing Database Source: https://github.com/lemmynet/lemmy-docs/blob/main/src/administration/backup_and_restore.md Commands to drop the public schema and recreate it, or to change the user password. These are useful if you encounter issues during restoration or when importing with a different password. ```bash # Drop the existing DB docker exec -i FOLDERNAME_postgres_1 psql -U lemmy -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;" # This also might be necessary when doing a db import with a different password. docker exec -i FOLDERNAME_postgres_1 psql -U lemmy -c "alter user lemmy with password 'bleh'" ```