5

I am using an embedded linux with busybox. I would like to automatically run my app called "myApplication" (runlevel 5 after boot all the services are up).

What I have done so far:

  • I made a script under /etc/init.d/ called S90myscript
  • Then I added this line to the inittab:

::sysinit:/etc/init.d/S90myscript

The script contains the following:

! /bin/sh
### BEGIN INIT INFO
# Provides: myApplication
# Should-Start: $all
# Required-Start: $remote_fs $network $local_fs
# Required-Stop: $remote_fs
# Default-Start: 5
# Default-Stop: 0 6
# Short-Description: start myprogram at boot time
### END INIT INFO
#

set -e

. /lib/lsb/init-functions
PATH=/root:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin
PROGRAMNAME="myApplication"
case "$1" in
start)
$PROGRAMNAME
;;
stop)
skill $PROGRAMNAME
;;
esac
exit 0

Am I missing something? Symlinks? Is what I did wrong?

Thank you in advance

JigglyNaga
  • 7,706
  • 1
  • 21
  • 47
AJ GS
  • 81
  • 1
  • 8
  • 1
    [Please don't post images of text](http://meta.unix.stackexchange.com/questions/4086/psa-please-dont-post-images-of-text). Copy and paste the text itself **into your question** and format it as code by selecting it and pressing Ctrl-K or by using the editor's `{}` icon. – cas Feb 21 '18 at 01:34

2 Answers2

3

Found the solution.

  1. I placed myApplication in /usr/sbin/
  2. Created a symlink named myApp to the script located in /etc/init.d/S99myAppScript (notice that there is no .sh and I had to run sudo chmod 755 on this script)
  3. Added the following line at the end of rcS file located in /etc/init.d/ just before the command done:

    myApp &
    

After rebooting the system, myApplication autoruns.

muru
  • 69,900
  • 13
  • 192
  • 292
AJ GS
  • 81
  • 1
  • 8
0
  1. Place you app in any place. In my case full path is /root/myApplication
  2. All init scripts in /etc/init.d executing one by one in numerical order. So it is good idea to set name of your script is like S99myAppScript or S98myAppScript. Because I want execute my script after all others.
    #!/bin/sh
    # see about BusyBox init https://www.halolinux.us/embedded-systems/busybox-init.html
    
    # Make sure the application exists
    [ -f /root/myApplication ] || exit 0
    
    umask 077
    
    start() {
        echo "Start application:"
        /root/myApplication
    }
    stop() {
        killall -q myApplication
    }
    restart() {
        stop
        start
    }
    
    case "$1" in
      start)
        start
        ;;
      stop)
        stop
        ;;
      restart|reload)
        restart
        ;;
      *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
    esac
    
    exit $?

See also.