Ubuntu Server – How to Execute Commands After Hard Reboot

Ubuntu

I am facing an issue that everytime I hard restart my server (maybe went bananas due to out of memory, ddosed etc) supervisor fails to run.
And the reason for that is identified and simply /var/run/supervisor directory is deleted.

I learned that /var/run folders are deleted on hard reboot (via ec2 panel for instance force stop then start), so my humble question is:

How can I execute this mkdir /var/run/supervisor after every hard reboot ?
Where is the perfect place to add such logic. I guess it is not /etc/profile for sure

(the rest works fine, supervisor is configured as service + uses unix sock at var/run/supervisor/supervisor.sock)

My ubuntu version:

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:        20.04
Codename:       focal

Best Answer

In Ubuntu 20 I would expect that supervisor is started as a systemd service unit.

In the service unit for supervisor you need to specify that the directory is created: (the unit name might be different)

https://serverfault.com/a/779648 & https://serverfault.com/a/840999

sudo systemctl edit --full supervisor

and add a directive:

RuntimeDirectory=supervisor