Safe Shutdown Procedure From Within a Container

HI Balena Team,

I think this question is best asked in the forum so others may benefit from the answer.

I have a custom carrier board that is using Crucial P3 NVMe drives and I have had 3 drive failures this year. When I run the nvme smart-log /dev/nvme0n1 -H command I see that most of my power downs are considered unsafe. See below.

I have 2 questions:

  1. What is the process to safe shutdown a device from within a container?
  2. Are we able to get a signal in a container that a shutdown action from the UI has occurred?
Smart Log for NVME device:nvme0n1 namespace-id:ffffffff
critical_warning                        : 0
      Available Spare[0]             : 0
      Temp. Threshold[1]             : 0
      NVM subsystem Reliability[2]   : 0
      Read-only[3]                   : 0
      Volatile mem. backup failed[4] : 0
      Persistent Mem. RO[5]          : 0
temperature                             : 46 C
available_spare                         : 100%
available_spare_threshold               : 5%
percentage_used                         : 0%
endurance group critical warning summary: 0
data_units_read                         : 1265
data_units_written                      : 3759
host_read_commands                      : 104368
host_write_commands                     : 184706
controller_busy_time                    : 3
power_cycles                            : 39
power_on_hours                          : 33
unsafe_shutdowns                        : 37
media_errors                            : 0
num_err_log_entries                     : 9
Warning Temperature Time                : 0
Critical Composite Temperature Time     : 0
Temperature Sensor 1           : 46 C
Temperature Sensor 2           : 51 C
Temperature Sensor 8           : 46 C
Thermal Management T1 Trans Count       : 0
Thermal Management T2 Trans Count       : 0
Thermal Management T1 Total Time        : 0
Thermal Management T2 Total Time        : 0

Hi,

As far as I’m aware, the general way of shutting down your device, is to call the supervisor API.

I’m not entirely sure what you mean with your second question.
I don’t think there is any status information available on requested shutdowns.

Hi, just confirming that the recommended mechanism to shutdown a device is by using the supervisor API as mentioned above.

What will happen is that the supervisor will tell the engine to bring containers down. Properly implemented containers, that is, those that have an init system like tiny or a single running application as PID 1, will handle the SIGTERM sent by the engine to perform a safe shutdown. The engine will follow-up unresponsive containers with a SIGKILL. Then, the system will be issued a reboot command.

Are we able to get a single in a container that a shutdown action from the UI has occurred?

If I understand the question correctly, you are asking whether a container can receive a signal to specify that the shutdown action has occured. As I mentioned above, it will get a SIGTERM followed by a SIGKILL.

Thank you very much for the help.