Managing Applications with Monit and Systemd


Engine Yard implements a specific way of handling its managed applications, which include the application servers, as well as a selection of utility applications. In this article we review the process to do so through the use of Monit and Systemd.


Managing the applications

The following precautions should be taken:

  • When dealing with the app server or utility applications, manage them through Monit or Systemd.
  • If Monit or Systemd are misbehaving, consider managing them via the control script.
    • This script is used by Systemd and Monit to control the managed applications. 
    • You can find the control script under /engineyard/bin/, and it contains commands such as 'status', 'start', 'stop', etc.
    • During the deployment process, this script is used to restart the workers.
  • Changes done manually to Monit and Systemd will normally be overwritten with a Chef run, as it manages their scripts.

Note that, at present, only Puma and Sidekiq in v7 are managed by Systemd.


The following commands are useful when dealing with a Monit-managed application:

  • monit summary: Shows the running apps managed by Monit.
  • monit status <app_name>: Shows information about the specific application.
  • monit start, stop <app_name>: Used to manage the app.

The config files with which Monit manages apps are under /etc/monit.d/<app_name>.monitrc:

  • The file is managed by Chef.
  • The file contains the scripts to start and stop the app.
  • The PID file with the process currently monitored is also present.
  • Contains the condition for restart if the memory usage goes over a certain threshold.


In the case of Systemd, the control script will contain the scripts required to check status, start, stop, etc. While you should reference the script as required, here are some useful commands:

  • systemctl status <app_name>: Shows the status of the application running. Since this may return a JSON object, you can run this instead to get human-readable data:
    /engineyard/bin/<app_name> status | tail -n 1 | json_pp
  • systemctl start, stop <app_name>: Used to manage the app

The config file with which Systemd manages an app is /lib/systemd/system/<app_name>.service:

  • The file is managed by Chef.
  • The file contains the start and pre-start scripts.
  • The MemoryMax can be configured to set a memory limit.
  • the 'env' file contains information about how the process is executed (ports used, workers launched, etc.).

Other useful commands

Aside from the above, some general Linux commands can be used to debug the status of the application servers:

  • free -m: Shows memory usage.
  • ps -faux: Shows the process tree.


This article covers the usage of Monit and Systemd when troubleshooting applications managed by Engine Yard, such as the application servers and the utility applications.


Article is closed for comments.