Skip to main content
Deploy Faculty Bot directly on your server using Rust toolchain and system process managers for maximum control.

Prerequisites

  • Linux, macOS, or Windows Server
  • PostgreSQL 13 or later installed and running
  • 512MB RAM minimum
  • Stable internet connection

Install Rust Toolchain

1

Download and install Rust

On Linux/macOS:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
On Windows, download and run rustup-init.exeWhen prompted, choose the stable toolchain.
2

Configure your shell

Add Rust to your PATH:
source $HOME/.cargo/env
Or restart your terminal.
3

Verify installation

rustc --version
cargo --version
You should see version information for both commands.

Build the Bot

1

Clone the repository

git clone https://github.com/your-org/faculty-bot.git
cd faculty-bot
2

Build release version

cargo build --release
This compiles an optimized production build. The binary will be located at:
target/release/faculty_manager
The first build may take 5-15 minutes as Cargo downloads and compiles all dependencies.
3

Test the build

Verify the binary runs:
./target/release/faculty_manager --version

Configuration

1

Create environment file

Create a .env file in the project root:
DISCORD_TOKEN=your_discord_bot_token

DATABASE_URL=postgres://faculty_manager:password@localhost:5432/faculty_manager

PREFIX=>

SEND_FROM_ADDRESS=noreply@yourdomain.com
MAIL_USERNAME=your_email@yourdomain.com
MAIL_PASSWORD=your_email_password
SMTP_SERVER=smtp.yourdomain.com
SMTP_PORT=587

# Logging level
RUST_LOG="info,sqlx=error,sqlx::query=error,sqlx::query_as=error"
2

Configure bot settings

Edit config.json with your Discord server details. See the Docker Deployment guide for configuration examples.
3

Set up the database

Install PostgreSQL 13 and initialize the database:
# Create database and user
sudo -u postgres psql -c "CREATE USER faculty_manager WITH PASSWORD 'password';"
sudo -u postgres psql -c "CREATE DATABASE faculty_manager OWNER faculty_manager;"

# Run migrations
psql -U faculty_manager -d faculty_manager -f migrations/faculty_manager.sql
See the Database Setup guide for detailed instructions.

Process Manager Setup

Keep the bot running continuously using a process manager. systemd is the standard init system for most modern Linux distributions.
1

Create systemd service file

The repository includes faculty_manager.service:
[Unit]
Description=CourtJester bot
After=multi-user.target

[Service]
# Base settings
Type=simple
Restart=always
RestartSec=10

# Execution parameters
User=courtjester
Group=courtjester
WorkingDirectory=/home/faculty_manager/faculty_manager
Environment = "SCRIPT_ARGS=info.json"
ExecStart=/home/faculty_manager/faculty_manager/faculty_manager $SCRIPT_ARGS

# Limit damage in case something goes awry
MemoryLimit=256M
CPUQuota=200%

# Security
PrivateTmp=true
ProtectSystem=full
NoNewPrivileges=true
ProtectControlGroups=true
ProtectKernelModules=true
ProtectKernelTunables=true
PrivateDevices=true
RestrictAddressFamilies=AF_INET AF_INET6
RestrictNamespaces=true
RestrictRealtime=true
SystemCallArchitectures=native

[Install]
WantedBy=multi-user.target
Update the User, Group, and WorkingDirectory paths to match your installation.
2

Install and start the service

Use the provided script:
chmod +x launch_systemd.sh
./launch_systemd.sh
Or manually:
sudo cp faculty_manager.service /etc/systemd/system/faculty_manager.service
sudo systemctl daemon-reload
sudo systemctl enable faculty_manager
sudo systemctl start faculty_manager
3

Verify service status

sudo systemctl status faculty_manager
View logs:
sudo journalctl -u faculty_manager -f

systemd Management Commands

# Start the bot
sudo systemctl start faculty_manager

# Stop the bot
sudo systemctl stop faculty_manager

# Restart the bot
sudo systemctl restart faculty_manager

# View status
sudo systemctl status faculty_manager

# Enable auto-start on boot
sudo systemctl enable faculty_manager

# Disable auto-start
sudo systemctl disable faculty_manager

# View logs
sudo journalctl -u faculty_manager -n 100

OpenRC (Alpine Linux, Gentoo)

For systems using OpenRC as the init system.
1

Install the service

chmod +x launch_openrc.sh
./launch_openrc.sh
Or manually:
sudo cp faculty_manager.service /etc/init.d/faculty_manager
sudo chmod +x /etc/init.d/faculty_manager
sudo rc-update add faculty_manager
sudo rc-service faculty_manager start
2

Verify service status

sudo rc-service faculty_manager status

OpenRC Management Commands

# Start the bot
sudo rc-service faculty_manager start

# Stop the bot
sudo rc-service faculty_manager stop

# Restart the bot
sudo rc-service faculty_manager restart

# Check status
sudo rc-service faculty_manager status

PM2 (Cross-platform)

PM2 is a process manager for Node.js applications but works great with any executable.
1

Install PM2

npm install -g pm2
2

Create PM2 ecosystem file

Create ecosystem.config.js:
module.exports = {
  apps: [{
    name: 'faculty_manager',
    script: './target/release/faculty_manager',
    cwd: '/path/to/faculty-bot',
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: '512M',
    env: {
      NODE_ENV: 'production',
      RUST_LOG: 'info,sqlx=error'
    },
    error_file: './logs/err.log',
    out_file: './logs/out.log',
    log_date_format: 'YYYY-MM-DD HH:mm:ss Z'
  }]
};
3

Start with PM2

pm2 start ecosystem.config.js
pm2 save
pm2 startup
Follow the instructions from pm2 startup to enable auto-start on boot.

PM2 Management Commands

# Start the bot
pm2 start faculty_manager

# Stop the bot
pm2 stop faculty_manager

# Restart the bot
pm2 restart faculty_manager

# View status
pm2 status

# View logs
pm2 logs faculty_manager

# Monitor resources
pm2 monit

# Delete from PM2
pm2 delete faculty_manager

Windows Deployment

1

Build the bot

Open PowerShell and navigate to the project directory:
cd faculty-bot
cargo build --release
The executable will be at target\release\faculty_manager.exe
2

Use the launch script

Run the provided PowerShell script:
.\launch_windows.ps1
3

Set up as Windows Service (Optional)

Use NSSM (Non-Sucking Service Manager):
# Download NSSM from https://nssm.cc/
nssm install FacultyManager "C:\path\to\faculty_manager.exe"
nssm set FacultyManager AppDirectory "C:\path\to\faculty-bot"
nssm start FacultyManager

Troubleshooting

Symptoms: Compilation fails during linking phaseSolutions:
  • Install required build dependencies:
    # Debian/Ubuntu
    sudo apt-get install build-essential pkg-config libssl-dev cmake
    
    # CentOS/RHEL
    sudo yum groupinstall "Development Tools"
    sudo yum install openssl-devel cmake
    
    # macOS
    xcode-select --install
    brew install cmake
    
  • Clear build cache and retry: cargo clean && cargo build --release
Symptoms: Connection refused or authentication failed errorsSolutions:
  • Verify PostgreSQL is running: sudo systemctl status postgresql
  • Test connection manually: psql -U faculty_manager -d faculty_manager
  • Check DATABASE_URL format in .env
  • Ensure database migrations have been run
  • Check PostgreSQL logs: sudo tail -f /var/log/postgresql/postgresql-13-main.log
Symptoms: Cannot read config files or write to directoriesSolutions:
  • Ensure the bot user has appropriate permissions:
    sudo chown -R botuser:botuser /path/to/faculty-bot
    chmod 644 config.json .env
    chmod 755 images/ logs/
    
  • If using systemd, verify the User and Group in the service file
Symptoms: Bot doesn’t start after system rebootSolutions:
  • For systemd: sudo systemctl enable faculty_manager
  • For OpenRC: sudo rc-update add faculty_manager default
  • For PM2: pm2 startup && pm2 save
  • Check service logs for startup errors
Symptoms: Bot consuming excessive RAMSolutions:
  • Reduce logging verbosity: RUST_LOG=warn in .env
  • Set memory limits in service file (systemd example):
    MemoryLimit=512M
    MemoryAccounting=true
    
  • Monitor with: systemctl status faculty_manager or pm2 monit

Updating the Bot

1

Stop the bot

# systemd
sudo systemctl stop faculty_manager

# OpenRC
sudo rc-service faculty_manager stop

# PM2
pm2 stop faculty_manager
2

Pull latest changes

git pull origin main
3

Rebuild

cargo build --release
4

Run database migrations (if any)

psql -U faculty_manager -d faculty_manager -f migrations/faculty_manager.sql
5

Restart the bot

# systemd
sudo systemctl start faculty_manager

# OpenRC
sudo rc-service faculty_manager start

# PM2
pm2 restart faculty_manager

Security Best Practices

Follow these security guidelines for production deployments:
  • Run the bot as a dedicated non-root user
  • Set restrictive file permissions on .env and config.json
  • Use firewall rules to restrict database access
  • Enable systemd security features (see service file example)
  • Keep Rust toolchain and dependencies updated
  • Regularly backup your database and configuration
  • Use environment-specific Discord tokens (dev/prod)
  • Enable audit logging for administrative commands

Performance Optimization

Compile with Additional Optimizations

# Edit Cargo.toml
[profile.release]
opt-level = 3
lto = true
codegen-units = 1
panic = 'abort'
strip = true

# Rebuild
cargo build --release

Enable CPU-specific Optimizations

RUSTFLAGS="-C target-cpu=native" cargo build --release

Next Steps

Database Setup

Configure PostgreSQL and run migrations

Configuration

Set up bot features and integrations

Build docs developers (and LLMs) love