How to run a Linux Program on Startup

Here are the steps to have a program or script start on boot on a linux machine using Systemctl. I’m currently using this start several services on my raspberry pi. DigitalOcean wrote an article that goes into more detail on Systemctl.

  1. Run this command
    sudo nano /etc/systemd/system/YOUR_SERVICE_NAME.service
  2. Paste in the command below. Press ctrl + x then y to save and exit
  3. Reload services

    sudo systemctl daemon-reload
  4. Enable the service

    sudo systemctl enable YOUR_SERVICE_NAME
  5. Start the service
    sudo systemctl start YOUR_SERVICE_NAME
  6. Check the status of your service
    systemctl status YOUR_SERVICE_NAME
  7. Reboot your device and the program/script should be running. If it crashes it will attempt to restart

Also published on Medium.

9 thoughts to “How to run a Linux Program on Startup”

  1. Thanks for this Tim – your articles helped me getting homebridge working perfectly! I was so lost without these articles – really appreciate it.

    I’m trying to take these learnings and get the alexa > sonos node.js service running explained here

    They give not so detailed instructions on how to get it up and running..

    Optional: You probably want to set this up to auto-start in the event it dies. Auto-launch is one of many solutions to make that happen. –

    As you may guess i’m completely lost!

    1. This is what I created – assuming I usually go to the folder home/pi/node_modules/sonos-http-api/
      then just type “npm start” and it starts..

      Description=Sonos Alexa Node Server

      ExecStart=home/pi/node_modules/sonos-http-api/npm start


      1. Thanks glad they have helped! I think you would want your command to first change to the directory then run npm start.

        You could also try npm start –prefix path/to/your/app


    What command is this? No one says what this command is supposed to be. Am I supposed to just “know” what goes there?

  3. Thank you for this straight-forward article – it’s exactly what I’ve been searching for. I’ve written a daemon process in C but was having trouble with other complicated instructions in getting it to run as a system process. This worked first time!
    I hope you can understand the simple delight of an engineer of some thirty years experience on seeing a System OK LED start flashing on boot!

    Best regards,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.