Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

procsd

> DevOps
Open source

Manage your application processes in production similar to Heroku CLI with Procfile and Systemd

190 stars0 likes3 views
WebsiteGitHub

About

Manage your application processes in production similar to Heroku CLI with Procfile and Systemd

Procsd

I really like how simple it is to manage application processes in production on Heroku with Procfile. How easily you can access application logs with the heroku logs command. Just type heroku create and you're good to go.

Can we have something similar on a cheap Ubuntu VPS from DigitalOcean? Yes we can, all we need is a systemd wrapper that exports application processes from Procfile to system services, and controls them/checks status/accesses logs using simple commands.

These days most Linux distributions (including Ubuntu) have systemd as their default system processes manager. That's why it is a good idea to use systemd for managing application processes in production (for simple cases).

Getting started

Install procsd first: $ gem install procsd. Required Ruby version is >= 3.2.0.

Let's say you have following application's Procfile:

yaml
web: bundle exec rails server -p $PORT
worker: bundle exec sidekiq -e $RAILS_ENV

and you want to have one instance of the web process and two instances of the worker process. Create a procsd.yml config file inside the application directory:

yaml
app: sample_app
formation: web=1,worker=2
environment:
  PORT: 2501
  RAILS_ENV: production
  RAILS_LOG_TO_STDOUT: true

The only required option in procsd.yml is app (application name). Also you can provide custom Systemd directory path (systemd_dir option, default is /etc/systemd/system)

Configuration is done.

Create an application (export to Systemd)

To disable and remove application from Systemd there is command $ procsd destroy.

…

You can provide additional options for create command:

  • --user - name of the user, default is current $USER env variable
  • --dir - application's working directory, default is current $PWD env variable
  • --path - $PATH to include in each service. Default is current $PATH env variable
  • --add-to-sudoers - if this option is present, procsd will create a sudoers rule file /etc/sudoers.d/app_name which allows starting/stopping/restarting app services without a password prompt (passwordless sudo).
  • --or-restart - if this option is provided and services are already created, procsd will skip creation and call the restart command instead. Otherwise (if services are not present), they will be created and additionally started. This is a useful option for deployment tools like Capistrano, Mina, etc.

Start application

Other control commands: stop and restart

You can start/stop/restart a particular process by providing its name, e.g.: $ procsd restart worker

deploy@server:~/sample_app$ procsd start

Started app services (sample_app.target)

Check the status

You can filter processes, like $ procsd status worker (show status only for worker processes) or $ procsd status worker.2 (show status only for worker.2 process)

To show status of the main application target: $ procsd status --target

…

Also you can see status in short format:

deploy@server:~/sample_app$ procsd status --short

sample_app-web.1.service    loaded active running sample_app-web.1.service
sample_app-worker.1.service loaded active running sample_app-worker.1.service
sample_app-worker.2.service loaded active running sample_app-worker.2.service

Check the logs

Like with command status, you can filter logs by passing the name of process as an argument: $ procsd logs web (show logs only for web processes, if any)

…

Systemd provides a lot of possibilities to display and manage application logs (journalctl command). Procsd supports following options:

  • -n - Specify how many last lines to print. Default is 100
  • -t - Tail, display recent logs and leave the session open for real-time logs to stream in
  • --system - Show only systemd messages about services (start/stop/restart/fail etc.)
  • --priority - Filter messages by a particular log level. For example show only error messages: procsd logs --priority err
  • --grep - Filter output to messages where message matches the provided query (may not work for some Linux distributions)

Execute processes defined in Procfile

Currently, procsd can not run all processes in development like foreman start does. But you can run one single process using procsd exec command:

deploy@server:~/sample_app$ procsd exec web

=> Booting Puma
=> Rails 5.2.1 application starting in production
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.0 (ruby 2.3.0-p0), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: production
* Listening on tcp://localhost:2501
Use Ctrl-C to stop

procsd exec requires all the environment variables defined in environment section of procsd.yml config file.

Sometimes in development mode you need different environment configuration. For that you can add additional environment section dev_environment and require it as well using --dev flag, example:

yaml
app: sample_app
environment:
  PORT: 2501
  RAILS_ENV: production
  RAILS_LOG_TO_STDOUT: true
dev_environment:
  RAILS_ENV: development
  SOME_OTHER_DEV_ENV_VARIABLE: value
# Run web process with all environment & dev_environment variables included:

deploy@server:~/sample_app$ procsd exec web --dev

If dev_environment has an env variable with the same name as one in environment, it will be overwritten with the value from dev_environment.

Nginx integration (with automatic HTTPS)

First, make sure that you have Nginx installed (sudo apt install nginx) and running (sudo systemctl status nginx).

If one of your application processes is a web process, you can automatically set up an Nginx (reverse proxy) config for it. Why? For example, to serve static files (assets, images, and all other files located in public folder or another custom folder) directly using Nginx, rather than the application server. Or to enable SSL support (see below).

Add to your procsd.yml nginx section with server_name option defined:

If you don't have a domain for an application (or don't need it), you can add server IP instead: server_name: 159.159.159.159.

If your application use multiple domains/subdomains, add all of them separated with space: server_name: my-domain.com us.my-domain.com uk.my-domain.com

yaml
app: sample_app
processes:
  web: bundle exec rails server -p $PORT
  worker: bundle exec sidekiq -e $RAILS_ENV
formation: web=1,worker=2
environment:
  PORT: 2501 # PORT will be used by Nginx to proxy requests from 0.0.0.0:80/443 to 127.0.0.1:PORT (required)
  HOST: localhost # Make sure that your application server in production running on 127.0.0.1, not 0.0.0.0
  RAILS_ENV: production
  RAILS_LOG_TO_STDOUT: true
nginx:
  server_name: my-domain.com
  public_folder_path: public # path is relative to the main project directory, default value is `public`.

Configuration is done! Run procsd create to create app services with Nginx reverse proxy config:

…

/etc/nginx/sites-available/sample_app

…

Everything is done. Start app services (procsd start) and go to http://my-domain.com where you'll see your application proxying with Nginx.

Auto SSL using Certbot

To generate Nginx config with free SSL certificate (from Let’s Encrypt) included, you need to install Certbot on the remote server first. For Ubuntu (check here instructions for other versions https://certbot.eff.org/instructions?ws=nginx&os=snap):

bash
$ sudo snap install --classic certbot
$ sudo ln -s /snap/bin/certbot /usr/local/bin/certbot

When you install certbot, it automatically setup a cron job (twice per day) to renew expiring certificates (Automated Renewals), so you don't have to worry about renewing certificates manually.

Then update procsd.yml by adding ssl: true:

yaml
# ...
nginx:
  server_name: my-domain.com
  ssl: true # added

Configuration is done. Make sure that all domains defined in procsd (nginx.server_name) are pointing to the server IP where application is hosted. Then run procsd create (you will probably need first run procsd destroy if app services already exists) as usual:

By default Certbot obtaining certificate from Let's Encrypt without a contact email. If you want to provide contact email, define env variable CERTBOT_EMAIL with your email in the .env file.

Output

…

That's it. Start app services (procsd start) and go to https://my-domain.com where you'll see your application proxying with Nginx and SSL enabled.

Note about using Cloudflare CDN

If you use Cloudflare CDN, that means the process of obtaining Let's Encrypt SSL Certificate will fail. To fix it, install python-certbot-dns-cloudflare package:

bash
$ sudo apt install certbot python-certbot-dns-cloudflare

Read instructions here how to get Cloudflare API Token and obtain certificates. In short,

1) Go to https://dash.cloudflare.com/profile/api-tokens and get your API Token.

2) Create on the server ~/.secrets/certbot/ directory with cloudflare.ini file inside:

bash
$ mkdir -p ~/.secrets/certbot/
$ chmod 0700 ~/.secrets/
$ touch ~/.secrets/certbot/cloudflare.ini
$ chmod 0400 ~/.secrets/certbot/cloudflare.ini

3) Put inside cloudflare.ini file your Cloudflare token:

bash
$ sudo nano ~/.secrets/certbot/cloudflare.ini
bash
# ~/.secrets/certbot/cloudflare.ini

# Cloudflare API token (example) used by Certbot:
dns_cloudflare_api_token = 0123456789abcdef0123456789abcdef01234567

4) Obtain certificates for all your domains declared in procsd.yml using certbot-dns-cloudflare plugin:

bash
# Example command for my-domain.com domain:

$ sudo certbot certonly --dns-cloudflare --dns-cloudflare-credentials ~/.secrets/certbot/cloudflare.ini -d my-domain.com

5) If all went fine, update Nginx application config with new certificates (using certbot command). To get required certbot command type $ procsd config certbot_command, then execute it:

bash
# Example command for my-domain.com domain:

$ sudo certbot --agree-tos --no-eff-email --redirect --non-interactive --nginx -d my-domain.com --register-unsafely-without-email

All is done!

All available commands

…

Difference with Foreman

Foreman itself is designed for development (not production) usage only and does it great. Yes, Foreman allows you to export Procfile to Systemd, but that's all. After export you have to manually use systemctl and journalctl to manage/check exported services. Procsd not only exports the application, but provides simple commands to manage the exported target.

  • Foreman systemd export uses dynamic services templates and as a result generates quite a lot of files/folders in the systemd directory even for a simple application.

  • Services generated using Foreman contain the $PORT variable in their names (and it's [undocum

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyautomationcapistranoclideployment

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理