How to run your own grain 🌾 nostr relay

This article will serve as the official guide for running a grain nostr relay. This article will be continually updated to reflect any changes in the software.

OceanSlim

19. März 2025March 19, 2025 · 14 Min. Lesezeit14 min read

grain is a nostr relay built using Go, currently utilizing MongoDB as its database. Binaries are provided for AMD64 Windows and Linux. grain is Go Relay Architecture for Implementing Nostr

Introduction

grain is a nostr relay built using Go, currently utilizing MongoDB as its database. Binaries are provided for AMD64 Windows and Linux. grain is Go Relay Architecture for Implementing Nostr

Prerequisites

Download Grain

Download the latest release for your system from the GitHub releases page

amd64 binaries provided for Windows and Linux, if you have a different CPU architecture, you can download and install go to build grain from source

Installation and Execution

Run Grain

on linux you will first have to make the program executable

chmod +x grain_linux_amd64

Then you can run the program

./grain_linux_amd64

(alternatively on windows, you can just double click the grain_windows_amd64.exe to start the relay)

You should see a terminal window displaying the port on which your relay and frontend are running.

If you get

Failed to copy app/static/examples/config.example.yml to config.yml: open app/static/examples/config.example.yml: no such file or directory

Then you probably forgot to put the app folder in the same directory as your executable or you did not unzip the folder.

Congrats! You're running grain 🌾!

You may want to change your NIP11 relay information document (relay_metadata.json) This informs clients of the capabilities, administrative contacts, and various server attributes. It's located in the same directory as your executable.

Configuration Files

Once Grain has been executed for the first time, it will generate the default configuration files inside the directory where the executable is located. These files are:

config.yml
whitelist.yml
blacklist.yml

Prerequisites:

Download Grain:

Download the latest release for your system from the GitHub releases page

amd64 binaries provided for Windows and Linux, if you have a different CPU architecture, you can download and install go to build grain from source

Installation and Execution:#

Run Grain:#

on linux you will first have to make the program executable

chmod +x grain_linux_amd64

Then you can run the program

./grain_linux_amd64

(alternatively on windows, you can just double click the grain_windows_amd64.exe to start the relay)

You should see a terminal window displaying the port on which your relay and frontend are running.

If you get

Failed to copy app/static/examples/config.example.yml to config.yml: open app/static/examples/config.example.yml: no such file or directory

Then you probably forgot to put the app folder in the same directory as your executable or you did not unzip the folder.

Congrats! You're running grain 🌾!

You may want to change your NIP11 relay information document (relay_metadata.json) This informs clients of the capabilities, administrative contacts, and various server attributes. It's located in the same directory as your executable.

Configuration Files:#

Once Grain has been executed for the first time, it will generate the default configuration files inside the directory where the executable is located. These files are:

config.yml
whitelist.yml
blacklist.yml

Configuration Documentation#

You can always find the latest example configs on my site or in the github repo here: config.yml

blacklist.yml

Config.yml#

This config.yml file is where you customize how your Grain relay operates. Each section controls different aspects of the relay's behavior.

1. mongodb (Database Settings)

2. server (Relay Server Settings)

3. resource_limits (System Resource Limits)

4. auth (Authentication Settings)

5. UserSync (User Synchronization)

6. backup_relay (Backup Relay)

7. event_purge (Event Purging)

8. event_time_constraints (Event Time Constraints)

9. rate_limit (Rate Limiting)

By understanding these settings, you can tailor your Grain Nostr relay to meet your specific needs and resource constraints.

whitelist.yml#

The whitelist.yml file is used to control which users, event kinds, and domains are allowed to interact with your Grain relay. Here's a breakdown of the settings:

1. pubkey_whitelist (Public Key Whitelist)

2. kind_whitelist (Event Kind Whitelist)

3. domain_whitelist (Domain Whitelist)

blacklist.yml#

The blacklist.yml file allows you to block specific content, users, and words from your Grain relay. Here's a breakdown of the settings:

1. enabled: true

2. permanent_ban_words:

3. temp_ban_words:

4. max_temp_bans: 3

5. temp_ban_duration: 3600

6. permanent_blacklist_pubkeys:

7. permanent_blacklist_npubs:

8. mutelist_authors:

Running Grain as a Service:#

Windows Service:#

To run Grain as a Windows service, you can use tools like NSSM (Non-Sucking Service Manager). NSSM allows you to easily install and manage any application as a Windows service.

* For instructions on how to install NSSM, please refer to this article: [Link to NSSM install guide coming soon].
  1. Open Command Prompt as Administrator:

    • Open the Windows Start menu, type "cmd," right-click on "Command Prompt," and select "Run as administrator."
  2. Navigate to NSSM Directory:

    • Use the cd command to navigate to the directory where you extracted NSSM. For example, if you extracted it to C:\nssm, you would type cd C:\nssm and press Enter.
  3. Install the Grain Service:

    • Run the command nssm install grain.
    • A GUI will appear, allowing you to configure the service.
  4. Configure Service Details:

    • In the "Path" field, enter the full path to your Grain executable (e.g., C:\grain\grain_windows_amd64.exe).
    • In the "Startup directory" field, enter the directory where your Grain executable is located (e.g., C:\grain).
  5. Install the Service:

    • Click the "Install service" button.
  6. Manage the Service:

    • You can now manage the Grain service using the Windows Services manager. Open the Start menu, type "services.msc," and press Enter. You can start, stop, pause, or restart the Grain service from there.

Linux Service (systemd):#

To run Grain as a Linux service, you can use systemd, the standard service manager for most modern Linux distributions.

  1. Create a Systemd Service File:

    • Open a text editor with root privileges (e.g., sudo nano /etc/systemd/system/grain.service).
  2. Add Service Configuration:

    • Add the following content to the grain.service file, replacing the placeholders with your actual paths and user information:
    [Unit]
    Description=Grain Nostr Relay
    After=network.target
    
    [Service]
    ExecStart=/path/to/grain_linux_amd64
    WorkingDirectory=/path/to/grain/directory
    Restart=always
    User=your_user #replace your_user
    Group=your_group #replace your_group
    
    [Install]
    WantedBy=multi-user.target
    
    • Replace /path/to/grain/executable with the full path to your Grain executable.
    • Replace /path/to/grain/directory with the directory containing your Grain executable.
    • Replace your_user and your_group with the username and group that will run the Grain service.
  3. Reload Systemd:

    • Run the command sudo systemctl daemon-reload to reload the systemd configuration.
  4. Enable the Service:

    • Run the command sudo systemctl enable grain.service to enable the service to start automatically on boot.
  5. Start the Service:

    • Run the command sudo systemctl start grain.service to start the service immediately.
  6. Check Service Status:

    • Run the command sudo systemctl status grain.service to check the status of the Grain service. This will show you if the service is running and any recent logs.
    • You can run sudo journalctl -f -u grain.service to watch the logs

More guides are in the works for setting up tailscale to access your relay from anywhere over a private network and for setting up a cloudflare tunnel to your domain to deploy a grain relay accessible on a subdomain of your site eg wss://relay.yourdomain.com

#1#2#3#4#5#6#7#8#9#blacklistyml#configuration#configyml#congrats#download#guide#howto#installation#introduction#linux#more#nostr#prerequisites#relay#replace#run#running#whitelistyml#windows

Written by

Comments

No comments yet. Start the conversation.

Contents

5 sections

  1. Installation and Execution:
  2. Run Grain:
  3. Configuration Files:
  4. Configuration Documentation
  5. Running Grain as a Service: