1. Create a service:
  2. Add your code there:
  3. Create and make sure /etc/rc.local is executable and add this code inside it:

    sudo chmod +x /etc/rc.local

  4. Enable the service:
  5. Start service and check status:
  6. If all goes well you can add your code to the /etc/rc.local file then restart it.