2

I want to run the following commands just after bootup of Raspberry Pi running the raspbian wheezy:

  1. sudo gcc -lpthread server.c -o wifiserver.o
  2. sudo ./wifiserver.o

I created the following files and ran the following steps:

  1. Created a script file named auto_server_start.

  2. Contents are as follows:

    #!bin/bash
    # /etc/init.d/auto_server_start
    ### BEGIN INIT INFO
    # Provides: auto_server_start
    # Required-Start: $all
    # Required-Stop: $remote_fs $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: wifi server script
    # Description: Start wifi server at bootup
    ### END INIT INFO
    
    case "$1" in
      start)
        echo "running server program"
        sudo gcc -lpthread server.c -o wifiserver.o
        sudo ./wifiserver.o
        ;;
      stop)
        echo "stopping customized script"
        ;;
      *)
        echo "Usage: /etc/init.d/auto_server_start start|stop"
        exit 1
        ;; 
    esac
    
    exit 0
    
  3. Copied this file named auto_server_start to /etc/init.d/ directory and added execute permission using chmod +x.

  4. Then sudo update-rc.d auto_server_start defaults.

It gave some warning about mathkernel but I don't think that has anything to do with my script.

However on soft reboot I checked ps -e as well as top, nowhere does my wifiserver process show up.

Please suggest.

PS: I checked that the commands gcc and ./wifiserver.o were giving no warning and errors.

6
  • 1
    Why would you recompile the binary on reboot?? Commented Aug 28, 2014 at 4:38
  • 1
    sudo is pointless and potentially harmful here. An init script already has all the privileges it needs. Commented Aug 28, 2014 at 4:39
  • 2
    Put the compiled binary into /usr/local/bin and change the script to run it from there. Examine your system log for failure or warning messages. Post them here if you need help interpreting them. Commented Aug 28, 2014 at 4:44
  • Hi it worked thanks ... I put the executable in the /usr/local/bin folder... I was not providing the file path properly...i guess it would have worked with /home/pi/wifiserver.o as well since my executable was present there. Thanks!! @tripleee Commented Aug 28, 2014 at 5:20
  • Post the fixed script as an answer and accept it so that this question no longer shows up as unresolved. Thanks. Commented Aug 28, 2014 at 6:39

1 Answer 1

3

Created a script file named auto_server_start.

Contents are as follows:

\#!bin/bash

\# /etc/init.d/auto_server_start

\### BEGIN INIT INFO

\# Provides: auto_server_start

\# Required-Start: $all

\# Required-Stop: $remote_fs $syslog

\# Default-Start: 2 3 4 5

\# Default-Stop: 0 1 6

\# Short-Description: wifi server script

\# Description: Start wifi server at bootup

\### END INIT INFO


case "$1" in

  start)

    echo "running server program"

    /usr/local/bin/wifiserver.o

    ;;

  stop)

    echo "stopping customized script"

    ;;

  *)

    echo "Usage: /etc/init.d/auto_server_start start|stop"

    exit 1

    ;; 

esac


exit 0

Copied this file named auto_server_start to /etc/init.d/ directory and added execute permission using chmod +x.

Then sudo update-rc.d auto_server_start defaults.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.