Scalingo adds UNIX signal support for apps

February 08, 2023 - 3 min read
Scalingo adds UNIX signal support for apps

We are excited to announce that a new feature has been released !

It is now possible to send a signal to an application hosted by Scalingo.

On the Scalingo platform, sending signals is a useful way to trigger events while being the owner or collaborator of an application. This can be particularly useful for debugging purposes.

In this article we will talk about how to send a user-defined signal (SIGUSR1 and SIGUSR2) to a Scalingo hosted application.For more information, you can check the Scalingo documentation about Send-Signal.

Why sending a signal to an application ?

At Scalingo we often use signals handler to:

  • Dump heap allocations
  • Dump all stack traces
  • Print the number of Goroutines
  • Print the memory consumption
  • etc…

How to send a signal to an application ?

A signal can be send with our CLI:

$ scalingo -a my-app ps
+-------+---------+-------------+------+---------------------+
| NAME  | STATUS  |   COMMAND   | SIZE |     CREATED AT      |
+-------+---------+-------------+------+---------------------+
| web-1 | running | sample-test | M    | 2023/01/05 09:24:33 |
| web-2 | running | sample-test | M    | 2023/01/05 09:24:33 |
+-------+---------+-------------+------+---------------------+

$ scalingo -a my-app send-signal --signal SIGUSR1 web-1
-----> Sent signal 'SIGUSR1' to 'web-1' container.

Example on Node.js Express application

The following example is a sample that can be found on our Scalingo's GitHub account and quickly deployed on the platform.

In this example, we will catch a SIGUSR1 and print the memory usage of our process.

The catch part can be resumed by this code:

process.on("SIGUSR1", () => {
  const used = process.memoryUsage();

  console.log("Printing memory usage")
  for (let key in used) {
    console.log(`-  ${key} ${Math.round(used[key] / 1024 / 1024 * 100) / 100} MB`);
  }
});

var express = require('express')
var app = express()
// ...

Here we will need to write our entry point in the Procfile. If we did not, the default entry point of a node application will be npm start which does not forward signals to app.js. More information on which process catches the signal can be found in our Scalingo documentation.

web: node app.js

Once deployed on Scalingo we can easily send a signal to our containerized application:

$ scalingo -a my-app send-signal --signal SIGUSR1 web-1
-----> Sent signal 'SIGUSR1' to 'web-1' container.

This will produce the following log in our application:

2023-01-10 15:13:22.147625033 +0100 CET [web-1] Printing memory Usage
2023-01-10 15:13:22.147633815 +0100 CET [web-1] - heapTotal 6.7 MB
2023-01-10 15:13:22.147633065 +0100 CET [web-1] - rss 38.89 MB
2023-01-10 15:13:22.147634619 +0100 CET [web-1] - heapUsed 4.59 MB
2023-01-10 15:13:22.147635164 +0100 CET [web-1] - external 1.39 MB
2023-01-10 15:13:22.147635509 +0100 CET [web-1] - arrayBuffers 0.03 MB

In short

In this article we discovered the new functionality about sending signal to an application hosted by Scalingo. As we seen this is a very useful feature for debugging purposes. Now, a new field of possibility is opened toward us. Go explore it.

Share the article
Quentin Escudier
Quentin Escudier
Quentin is Junior Developer and recently joined the Infrastructure Team.

Try Scalingo for free

30-day free trial / No credit card required / Hosted in Europe