I was following this tutorial to add a power button to my raspberry pi. I created a script that will start and stop a python script called shutdown.sh. When reboot the system and push the button, it doesn't shut down. I opened ssh and looked for all the services running with the command sudo service --status-all. This is my partial list.

List of Services

Noticed that shutdown.shis not running. Based on the tutorial, the command I used to register the script is sudo update-rc.d shutdown.sh defaults. I tried manually running the service by adding this command: sudo /etc/init.d/listen-for-shutdown.sh start

I get an error: sudo: unable to execute /etc/init.d/shutdown.sh: No such file or directory. However, the file is there and the filename is correct. I changed the permissions so that it has execution permissions. Just FYI, the python script is where it is supposed to be also. Also, I tested the python script also manually, so I know that works.

  1. How can I get shutdown.shservice to run on boot?
  2. Why can't run the script manually when the file is there?

shutdown.sh script:

#! /bin/sh

# Provides:          shutdown.py
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6

# If you want a command to always run, put it here

# Carry out specific functions when asked to by the system
case "$1" in
    echo "Starting shutdown.py"
    /usr/local/bin/shutdown.py &
    echo "Stopping shutdown.py"
    pkill -f /usr/local/bin/shutdown.py
    echo "Usage: /etc/init.d/shutdown.sh {start|stop}"
    exit 1

exit 0

What OS???

Apart from the obvious error that you are "adding" /etc/init.d/listen-for-shutdown.sh but the error in /etc/init.d/shutdown.sh

You are using obsolete SysV scripts and commands - you should use systemd (although the OS will attempt to convert SysV scripts to systemd services).

systemctl status will show current services.

There is also NO NEED on a system running latest Raspbian (or any system using latest firmware) which includes a module dtoverlay=gpio-shutdown to perform this function.

  • i renamed my script is called shutdown.sh.. i am using this on an older version of retropie on top of raspbian.. i probably should use a more updated version huh? – Peter Sun Mar 30 '18 at 2:20
  • Unless you specify OS and version, and post CONSISTENT detail of what you are doing, no one can help. Depends on how old, but you are unlikely to get answers on uncommon OS and very old versions. – Milliways Mar 30 '18 at 3:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.