Discord Bot Container Keeps Getting Killed with SIGTERM After 3-4 Seconds

yaooooooooooooooo
HOBBY

a month ago

Problem:

I'm trying to deploy a Discord bot that needs to run continuously as a background service, but Railway keeps killing the container with SIGTERM after 3-4 seconds, regardless of my configuration.

What I'm Running:

- Node.js Discord bot using discord.js

- Needs to stay online 24/7 to detect Discord server joins and send webhooks

- Uses npm starttsx index.ts to run

Current Behavior:

1. Container starts successfully

2. Bot connects to Discord ("VP bot ready as Bot#2543")

3. HTTP health server starts on port 8080

4. After 3-4 seconds: "Stopping Container"

5. Process receives SIGTERM and dies

6. Cycle repeats indefinitely

What I've Tried:

  • Disabled "Enable Serverless" in Railway UI

  • Set Restart Policy to "Always"

  • Added HTTP server responding on / and /health endpoints

  • Added railway.json with worker configuration

  • Confirmed bot code works (connects to Discord successfully)

  • Upgraded to 8 vCPU / 8GB memory - no change in behavior

  • Memory usage is only 132MB during operation

  • Issue persists regardless of resource allocation

Expected Behavior:

Container should stay running continuously like a background worker/daemon process.

Question:

How do I configure Railway to keep a long-running Discord bot alive? Is there a specific service type or configuration I'm missing for background processes that don't serve HTTP traffic?

$10 Bounty

2 Replies

Railway
BOT

a month ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


colinrm000
HOBBY

a month ago

It sounds like Railway is treating your Discord bot as a web service instead of a worker, which is why the container gets SIGTERM after a few seconds. By default, Railway expects a process to serve HTTP traffic on a port, and if it doesn’t see that, it assumes the container is idle and shuts it down.

Potential fix: declare your bot as a worker service instead of a web service.

1. railway.json

Add a workers section so Railway knows this is a background process:

{
  "build": {
    "builder": "NIXPACKS"
  },
  "deploy": {
    "numReplicas": 1,
    "restartPolicyType": "ALWAYS"
  },
  "workers": {
    "bot": {
      "start": "npm start"
    }
  }
}

Replace "npm start" with whatever command you actually run.

This tells Railway to run it as a worker, not a web service. Workers are long-running background jobs and don’t need to expose an HTTP port.

2. Remove fake HTTP server

If you only added an HTTP server to keep the container alive, you can remove it once you’ve declared a worker.

Also, in the Railway dashboard, make sure “Serverless” is disabled.