Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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!

share|improve this question

marked as duplicate by studiohack Jan 16 '13 at 6:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

add comment

2 Answers 2

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
share|improve this answer
add comment

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.

share|improve this answer
    
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 '13 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 '13 at 9:51
add comment

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