Add Health Monitoring to a Plan
Habitat provides basic health monitoring for your running service; however, if you want to
perform custom tests or other status checks, you can customize your plan to do that. This is
done by using a
health_check hook, which is a script that responds to a specific event during the lifecycle
of a running service.
There are multiple hooks that you can define in your plan. For example, the
run hooks are responsible
for defining behavior during initialization and when the child service/application starts up. The Ruby scaffolding
creates the initialization for you to handle connecting to a backend database and the build script used by the Studio
creates a generic run hook. However, to create the
health_check hook, you have to perform the following operations:
Change directory to
Create a new file named
health_checkin your text editor.
Hooks use shebangs to decide which interpreter to use when running their scripts. In the case of the hook in our plan, we will use the system shell, so add the following to the
This hook performs a basic test to check whether the results of the curl command return an HTTP status code less than 400. If the curl command doesn't succeed, then this check will be denoted as "critical."
Congratulations, you have added a custom
health_check application lifecycle hook to your sample application. It's time to build your sample Rails application.