Skip to content

Latest commit

 

History

History
42 lines (33 loc) · 1015 Bytes

sytemd_run_script.md

File metadata and controls

42 lines (33 loc) · 1015 Bytes

run any script at startup with systemd

  1. Create a new unit file in /lib/systemd/system/ called rpi-lcd.service:

    sudo vim /lib/systemd/system/rpi-lcd.service
  2. Copy and paste the following in the new unit file:

    [Unit]
    Description=RPi Python script for a 16x2 LCD
    
    [Service]
    Type=simple
    ## Edit the following according to the script permissions
    User=root 
    #User=pi
    #Group=users
    
    ## Edit the following with the full path to the compatible Python version and your script
    ExecStart=/usr/bin/python3 /home/stereosonic/raspi-lcd-16x2/lcd.py
    
    Restart=always
    RestartSec=5
    
    KillMode=process
    KillSignal=SIGINT
    
    [Install]
    WantedBy=multi-user.target
  3. Enable the service and start it:

    sudo systemctl enable rpi-lcd.service
    sudo systemctl start rpi-lcd.service
  4. Check that the LCD is displaying the correct information; otherwise, check the service status:

    systemctl status rpi-lcd.service