Script that starts with boot and auto-restart on failure

What your script needs to perform in such a manner is systemd sevice.

An example would be the one below:

[Unit]
Description=My Script


[Service]
Type=forking    
ExecStart=/path/to/script
Restart=on-failure

[Install]
WantedBy=multi-user.target

This can be done in several ways:

  1. Place your script in another location and access it from your systemd service files.

  2. Place the code directly in the systemd service file.

I believe the first option is ideal in your situation. Now once done enable at boot with the normal systemctl commands, such as:

sudo systemctl enable myscript.service
sudo systemctl status myscript.service
sudo systemctl stop myscript.service
sudo systemctl start myscript.service

Sources:

https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files

https://www.freedesktop.org/software/systemd/man/systemd.unit.html