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.

Biffen
  • 6,249
  • 6
  • 28
  • 36
RootPhoenix
  • 1,626
  • 1
  • 22
  • 40
  • 1
    Why would you recompile the binary on reboot?? – tripleee Aug 28 '14 at 04:38
  • 1
    `sudo` is pointless and potentially harmful here. An init script already has all the privileges it needs. – tripleee Aug 28 '14 at 04: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. – tripleee Aug 28 '14 at 04: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 – RootPhoenix Aug 28 '14 at 05:20
  • Post the fixed script as an answer and accept it so that this question no longer shows up as unresolved. Thanks. – tripleee Aug 28 '14 at 06:39
  • A "/" is missing in the shebang : #!/bin/bash – Rachid K. Sep 22 '22 at 10:01

1 Answers1

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.

PlayerWet
  • 419
  • 5
  • 18
RootPhoenix
  • 1,626
  • 1
  • 22
  • 40