start program written in c when booting linux system

0

Hello this time I created a small program written in c that I intend to run in a raspberry the same one already works correctly, but now I need to run it when I start the system (and it works without logging in), the idea would be that when starting the device the program works directly without the need to login. It should be noted that it reads information through the gpio ports.

Try adding the scrip in the following way

link

#! /bin/sh
# /etc/init.d/prototip

### BEGIN INIT INFO
# Provides:          casero
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Simple script to start a program at boot
# Description:       iniciar  servicio autana system.
### END INIT INFO

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

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting prototip"
    # run application you want to start
    /bin/prototip
    ;;
  stop)
    echo "Stopping noip"
    # kill application you want to stop
    killall prototip
    ;;
  *)
    echo "Usage: /etc/init.d/prototip {start|stop}"
    exit 1
    ;;
esac

exit 0

the same when I try it in the following way - sos /etc/init.d/prototip start executes the program correctly, but when I turn the computer off and on the program never starts. Any ideas?. Thanks

    
asked by Yoel Mendoza 11.10.2017 в 12:55
source

1 answer

1

You have to register the script as a system service:

cd /etc/init.d
sudo update-rc.d prototip defaults

Another thing that can give you conflicts in some cases is that the service has exactly the same name as the binary (the program in C), which is added to the PATH of the system and can be called from anywhere.

I advise you to rename the script, for example to " prototipd " and add the service again to avoid possible conflicts.

Besides that, the location of the binary is not the most correct, you should place it in the binaries folder of the user: /usr/bin/prototip

    
answered by 11.10.2017 в 13:14