Skip to content

Running In Background

TermBeam is designed as a lightweight, on-demand tool — start it when you need terminal access, stop it when you’re done. But if you want it always available (e.g., on a home server or dev machine), here’s how to keep it running reliably using standard process managers.

The simplest way to keep TermBeam running after you close your terminal:

Terminal window
nohup termbeam --no-tunnel --password mysecret > ~/.termbeam.log 2>&1 &
echo $! > ~/.termbeam.pid

To stop it:

Terminal window
kill $(cat ~/.termbeam.pid)

PM2 is the most popular Node.js process manager. It handles restarts, logging, and monitoring out of the box.

TermBeam includes a built-in interactive installer that configures PM2 for you:

Terminal window
termbeam service install

The wizard checks if PM2 is installed (and offers to install it globally if not), then walks you through 8 configuration steps:

StepQuestionOptions / Default
1. Service nameName for the PM2 processDefault: termbeam
2. PasswordHow to protect the serviceAuto-generate (recommended), enter custom, or no password
3. PortServer portDefault: 3456
4. Access modeHow to reach the serviceDevTunnel (from anywhere), LAN (local network), or Localhost only
5. Working directoryDefault terminal directoryDefault: current directory
6. Log levelLogging verbosityinfo (default), debug, warn, or error
7. Boot auto-startStart on system boot?Default: Yes — runs pm2 startup
8. ConfirmReview and proceedProceed or cancel

If you choose DevTunnel access, a follow-up question asks whether the tunnel should be private (Microsoft login required) or public (anyone with the link). Choosing public with no password will auto-generate one for safety.

After confirming, the wizard generates an ecosystem config file, starts the PM2 process, and saves the process list.

After installation, manage the service with these subcommands:

Shows detailed PM2 process information (equivalent to pm2 describe <name>), including uptime, restarts, memory usage, and log file paths.

Terminal window
termbeam service status

Tails the PM2 log output, showing the last 200 lines and streaming new output in real time. Press Ctrl+C to stop.

Terminal window
termbeam service logs

Restarts the PM2 process. Useful after editing the ecosystem config file or updating TermBeam.

Terminal window
termbeam service restart

Stops the PM2 process, removes it from PM2, and deletes the ecosystem config file. Prompts for confirmation before proceeding.

Terminal window
termbeam service uninstall
Terminal window
# Install PM2 globally
npm install -g pm2
# Start TermBeam
pm2 start termbeam -- --no-tunnel --password mysecret
# Or with specific options
pm2 start termbeam -- --port 8080 --password mysecret --tunnel
Terminal window
# Check status
pm2 status
# View logs
pm2 logs termbeam
# Restart
pm2 restart termbeam
# Stop
pm2 stop termbeam
# Remove from PM2
pm2 delete termbeam
Terminal window
# Generate startup script (run the command it outputs)
pm2 startup
# Save current process list
pm2 save

This ensures TermBeam starts automatically after a system reboot. 🎉

Create a service file at /etc/systemd/system/termbeam.service:

[Unit]
Description=TermBeam - Web Terminal
After=network.target
[Service]
Type=simple
User=your-username
Environment=TERMBEAM_PASSWORD=your-secret
ExecStart=/usr/bin/env termbeam --host 0.0.0.0
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target

Then enable and start:

Terminal window
sudo systemctl daemon-reload
sudo systemctl enable termbeam
sudo systemctl start termbeam
# Check status
sudo systemctl status termbeam
# View logs
journalctl -u termbeam -f

Create a plist at ~/Library/LaunchAgents/com.termbeam.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.termbeam</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/termbeam</string>
<string>--host</string>
<string>0.0.0.0</string>
</array>
<key>EnvironmentVariables</key>
<dict>
<key>TERMBEAM_PASSWORD</key>
<string>your-secret</string>
</dict>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/Users/you/Library/Logs/termbeam.log</string>
<key>StandardErrorPath</key>
<string>/Users/you/Library/Logs/termbeam.err</string>
</dict>
</plist>

Then load it:

Terminal window
launchctl load ~/Library/LaunchAgents/com.termbeam.plist
# To stop
launchctl unload ~/Library/LaunchAgents/com.termbeam.plist
  1. Open Task SchedulerCreate Task
  2. General: Name it “TermBeam”, check “Run whether user is logged on or not”
  3. Triggers: “At startup” (or “At log on” for user-level)
  4. Actions: Start a program
    • Program: node
    • Arguments: C:\Users\you\AppData\Roaming\npm\node_modules\termbeam\bin\termbeam.js --no-tunnel --password mysecret
  5. Settings: Check “Restart on failure”, set retry to 1 minute

A background service is only useful if the machine stays reachable. If your computer sleeps, the network adapter powers down, or the lid closes, your tunnel and LAN connection drop — even though TermBeam itself is configured to restart.

Pick the lightest-touch option for your OS:

Recommended: Amphetamine (free, App Store) — pair it with a process trigger so your Mac only stays awake while TermBeam is actually running.

  1. Install Amphetamine → enable Triggers in Preferences.
  2. Add trigger: “While a specific process is running” → select node (or the full path to your termbeam binary — find it with which termbeam).
  3. In the trigger’s session options:
    • Allow display sleep (saves power; the screen doesn’t need to be on)
    • Allow system sleep when display is closed — keep this off for MacBooks (clamshell-mode safe)
    • Prevent system sleep when on battery (only if you need it unplugged)

Alternative: built-in caffeinate — no app needed. Bake it straight into your launchd plist or PM2 ecosystem config:

Terminal window
# Wrap termbeam so the system stays awake only while termbeam runs
caffeinate -dims termbeam --tunnel --persisted-tunnel

For the launchd example above, replace the ProgramArguments with caffeinate -dims /usr/local/bin/termbeam .... Flags: -d display, -i idle, -m disk, -s system (AC only).

TCP keepalive across brief sleeps — recommended for tunnel stability:

Terminal window
sudo pmset -a tcpkeepalive 1
pmset -g | grep -E 'sleep|womp|tcpkeepalive' # verify

Recommended: PowerToys Awake (free, Microsoft) — official, integrates cleanly with the system tray, no third-party trust required.

  1. Install PowerToys → enable the Awake module.
  2. Set mode to Keep awake indefinitely with Keep screen on: off.
  3. Optionally configure Awake to launch at startup so it pairs with your Task Scheduler / NSSM service.

Also disable network adapter power saving (otherwise Wi-Fi sleeps even when the system doesn’t):

  • Device Manager → Network adapters → your adapter → Properties → Power Management → uncheck “Allow the computer to turn off this device to save power”.
  • Settings → System → Power → Screen and sleep → “When plugged in, put my device to sleep after”Never.

Alternative: built-in power plan only — Control Panel → Power Options → choose High performance → set sleep to “Never” on AC. No extra software.

For a dedicated server, mask the sleep targets entirely:

Terminal window
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

For laptops where you only want to inhibit sleep while TermBeam is running, use systemd-inhibit in your unit file’s ExecStart:

ExecStart=/usr/bin/systemd-inhibit --what=sleep:idle --why="TermBeam is running" /usr/bin/env termbeam --host 0.0.0.0

For lid-close behavior, edit /etc/systemd/logind.conf:

HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore

Then sudo systemctl restart systemd-logind.


  • Configuration — CLI flags, environment variables, and defaults
  • Resume & List — reconnect to running sessions from your terminal