Blog

Scalingo adds UNIX signal support for apps

Chargement...

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. Sending signals on Scalingo is a useful way to trigger events while being the owner or collaborator of an application. This can be particularly useful for debugging purposes.

How Scalingo makes migrating from Heroku easy

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'

$ 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'

$ 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'

$ 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'

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()
// ...
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()
// ...
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()
// ...
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
web: node app.js
web: node app.js
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'

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

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

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

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

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

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

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

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.

Quentin Escudier

Quentin is Junior Developer and recently joined the Infrastructure Team.

Stay Updated

Get articles and platform updates in your inbox.

Ready to Deploy with Confidence?

Experience zero-downtime deployments, intelligent auto-scaling, and fully managed infrastructure. Start deploying your applications on Scalingo today.

No credit card required • Deploy in minutes • Cancel anytime

Deploy your first app or database

Let's start building together

Join developers who chose a platform built for fast delivery and calm production, with European values and human support.

Deploy your first app or database

Let's start building together

Join developers who chose a platform built for fast delivery and calm production, with European values and human support.

Deploy your first app or database

Let's start building together

Join developers who chose a platform built for fast delivery and calm production, with European values and human support.