title: Right way to make a bash script run as a service
body: <p>I have a simple script which monitors my notebook's battery level. Is anything wrong with how I set up my <strong>*.service</strong> file since I keep getting <code>(code=exited, status=1/FAILURE)</code> errors. </p>
  
  <p><strong>batterylevel-warning.sh</strong></p>
  
  <p>Permissions set to 777.</p>
  
  <pre><code>#!/bin/bash
  
  CRITICAL_PERCENTAGE=`cat /sys/class/power_supply/BAT0/capacity`
  STATUS=`cat /sys/class/power_supply/BAT0/status`
  ICON="/usr/share/icons/Paper/512x512/status/battery-low.png"
  
  if [ $STATUS == "Discharging" ]; then
      if [ $CRITICAL_PERCENTAGE -eq 20 ]; then
          notify-send -u critical -t 2000 -i $ICON "You need to charge your battery now!!! It is at $CRITICAL_PERCENTAGE%!!!"
      fi
  fi
  </code></pre>
  
  <p><strong>batterylevel.service</strong></p>
  
  <pre><code>[Unit]
  Description=Send alerts on low battery starting at 25%.
  
  [Service]
  Type=simple
  ExecStart=/bin/bash /home/myhome/.scripts/batterylevel-warning.sh
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>Implement</p>
  
  <pre><code># Create sym link
  sudo ln-s /home/myhome/.scripts/batterylevel.service /etc/systemd/system
  # Enable and start
  sudo systemctl enable batterylevel.service
  sudo systemctl start batterylevel.service
  </code></pre>
  
  <p><strong>Problem:</strong> When my battery hits 25% I run <code>sudo systemctl status batterylevel.service</code> and get:</p>
  
  <pre><code>● batterylevel.service - Send alerts on low battery starting at 25%. Designed for silverlance.
     Loaded: loaded (/home/myhome/.scripts/batterylevel.service; enabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Mon 2020-03-02 23:04:02 PST; 4s ago
    Process: 5357 ExecStart=/bin/bash /home/myhome/.scripts/batterylevel-warning.sh (code=exited, status=1/FAILURE)
   Main PID: 5357 (code=exited, status=1/FAILURE)
  </code></pre>
  
  <p>I also ran <code>sudo systemctl daemon-reload</code> somewhere in there but still no success. Sorry for the long post.</p>