1

Possible Duplicate:
Programs on startup in Linux

I have a Linux machine running a program constantly, if power is cut out, the program wont restart until i open an SSH session and type in "./GPIOServer.sh" This is just in case i lose power to the machine, and i want the program to automatically start on start up.

Thanks!

0

2 Answers 2

1

What version of OS are you using?

Depending on what it is you have essentially 2 options:

/etc/rc.local

You can either add the executable to the rc.local file which is located here on Redhat distros: /etc/rc.local. You can simply add ./GPIOServer.sh to the end of this file.

/etc/init.d/

If you want it to be a service then you'll need to add a script similar to the ones in /etc/init.d/. Again on Redhat based distros there is a tool to help manage these scripts called chkconfig. See the man-page for more info and also look at the other scripts in /etc/init.d for ideas on how to approach this.

Here's a sample to get you started:

#! /bin/sh
# Basic support for IRIX style chkconfig
###
# chkconfig: 235 98 55
# description: Manages the services you are controlling with the chkconfig command
###

case "$1" in
  start)
        echo -n "Starting new-service"
        #To run it as root:
        /path/to/command/to/start/new-service
        #Or to run it as some other user:
        /bin/su - username -c /path/to/command/to/start/new-service
        echo "."
        ;;
  stop)
        echo -n "Stopping new-service"
        #To run it as root:
        /path/to/command/to/stop/new-service
        #Or to run it as some other user:
        /bin/su - username -c /path/to/command/to/stop/new-service
        echo "."
        ;;

  *)
        echo "Usage: /sbin/service new-service {start|stop}"
        exit 1
esac

exit 0
0

With a raspberry-pi, the simplest way would be to add a line with the full path of your script to the /etc/rc.local file.

2
  • When i search for the folder /etc/rc.local all i find are folders named rc0.d rc1.d rc2.d and so on...
    – user190333
    Jan 16, 2013 at 23:14
  • As I wrote, /etc/rc.local is not a folder but a file. If it doesn't exist, you should just be able to create it.
    – jlliagre
    Jan 17, 2013 at 9:51

Not the answer you're looking for? Browse other questions tagged .