Running an application on startup in embedded linux - Linux

This is a discussion on Running an application on startup in embedded linux - Linux ; I need to run an application when the linux boots up which provides the UPnP functionality of the box. During development it was easy to boot the system, login as a root and start the app from command line. Moving ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Running an application on startup in embedded linux

  1. Running an application on startup in embedded linux

    I need to run an application when the linux boots up which provides
    the UPnP functionality of the box.
    During development it was easy to boot the system, login as a root and
    start the app from command line.
    Moving to the production I started to think what would be the best
    approach to start the app during booting.
    1) Autologin to linux and run it from .bash_profile. This way seems
    very flexible to me because I can always connect to the box via the
    serial port and kill the app, modify it and run again. The problem is
    I don't really know how to implement autologin on the sytem we have.
    Should it be some special app for this or it's possible to do just
    with /etc/inittab?
    2) Make a daemon out of the app. This way autologin is not neccessary
    and I still can connect to the system and have control over it. I'll
    have no way to print out to the standard output, that's the minus.
    3) Run the app straight from /etc/inittab. This is the easiest way,
    but in this case the app will block the bash and it's going to be hard
    to have a control over the system because now the app is blocking out
    the bash.

    I need an advise which way to go and maybe what to read to know more
    about the way applications in embedded systems should work.

    Thank you,
    Andrew

  2. Re: Running an application on startup in embedded linux

    In comp.os.linux.development.system, you wrote:
    > I need to run an application when the linux boots up which provides
    > the UPnP functionality of the box.
    > During development it was easy to boot the system, login as a root and
    > start the app from command line.
    > Moving to the production I started to think what would be the best
    > approach to start the app during booting.
    > 1) Autologin to linux and run it from .bash_profile. This way seems
    > very flexible to me because I can always connect to the box via the
    > serial port and kill the app, modify it and run again. The problem is
    > I don't really know how to implement autologin on the sytem we have.
    > Should it be some special app for this or it's possible to do just
    > with /etc/inittab?
    > 2) Make a daemon out of the app. This way autologin is not neccessary
    > and I still can connect to the system and have control over it. I'll
    > have no way to print out to the standard output, that's the minus.
    > 3) Run the app straight from /etc/inittab. This is the easiest way,
    > but in this case the app will block the bash and it's going to be hard
    > to have a control over the system because now the app is blocking out
    > the bash.
    >
    > I need an advise which way to go and maybe what to read to know more
    > about the way applications in embedded systems should work.


    You don't need to login to run your app. You can start it up from the
    startup scripts. I do this on my NSLU2, WRT54G and an embedded Linux
    board. I don't know what distribution you're using but to start up a
    upnp daemon (your application) you can use an RC script. Under a
    Redhat or Fedora system you would do something like this file called
    /etc/rc.d/rc3.d/S91mh :

    #!/bin/sh
    #
    # chkconfig: - 91 35
    # description: Starts and stops the cpuxa daemon
    # mrHouse This shell script takes care of starting and stopping \
    # MisterHouse Home Automation Software.
    #
    # processname: /usr/local/mh/bin/mh
    #

    RELEASE=$(uname -r)

    # Source function library.
    if [ -f /etc/init.d/functions ] ; then
    . /etc/init.d/functions
    elif [ -f /etc/rc.d/init.d/functions ] ; then
    . /etc/rc.d/init.d/functions
    else
    exit 2
    fi

    # Source function library.
    #. /etc/rc.d/init.d/functions

    # Source networking configuration and check that networking is up.
    if [ -f /etc/sysconfig/network ] ; then
    . /etc/sysconfig/network
    [ ${NETWORKING} = "no" ] && exit 0
    fi

    [ -x /usr/local/mh/bin/mh ] || exit 0

    prog=mh

    RETVAL=0

    start () {
    # I need this!
    if [ -f /lib/modules/${RELEASE}/kernel/drivers/char/moxa.ko ]; then
    modprobe moxa
    #echo Moxa.ko driver found
    else
    echo Warning moxa.ko driver not found
    fi

    # start daemon
    # Isn't this a problem for mh?
    export LANG=en_US
    cd /usr/local/mh/bin/
    daemon /usr/local/mh/bin/mh -tk 0 2>&1 >>/var/log/mh.log &
    # /usr/local/mh/bin/mh -tk 0 2>&1 >>/var/log/mh.log &

    RETVAL=$?
    echo -n $"Starting $prog: "
    echo
    # success $"$base startup"
    [ $RETVAL = 0 ] && touch /var/lock/subsys/mh
    return $RETVAL
    }

    stop () {
    # stop daemon
    killproc /usr/local/mh/bin/mh
    RETVAL=$?
    echo -n $"Stopping $prog: "
    echo
    [ $RETVAL = 0 ] && rm -f /var/lock/subsys/mh
    return $RETVAL
    }

    restart () {
    stop
    start
    RETVAL=$?
    return $RETVAL
    }

    # See how we were called.
    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    status)
    status /usr/local/mh/bin/mh
    RETVAL=$?
    ;;
    restart)
    restart
    ;;
    *)
    echo $"Usage: $0 {start|stop|restart|status}"
    RETVAL=1
    esac

    exit $RETVAL


    --
    Linux Home Automation Neil Cherry ncherry@linuxha.com
    http://www.linuxha.com/ Main site
    http://linuxha.blogspot.com/ My HA Blog
    Author of: Linux Smart Homes For Dummies


    --
    Linux Home Automation Neil Cherry ncherry@linuxha.com
    http://www.linuxha.com/ Main site
    http://linuxha.blogspot.com/ My HA Blog
    Author of: Linux Smart Homes For Dummies

  3. Re: Running an application on startup in embedded linux

    On Nov 19, 7:40 pm, Neil Cherry wrote:
    > In comp.os.linux.development.system, you wrote:
    > > I need to run an application when the linux boots up which provides
    > > the UPnP functionality of the box.
    > > During development it was easy to boot the system, login as a root and
    > > start the app from command line.
    > > Moving to the production I started to think what would be the best
    > > approach to start the app during booting.
    > > 1) Autologin to linux and run it from .bash_profile. This way seems
    > > very flexible to me because I can always connect to the box via the
    > > serial port and kill the app, modify it and run again. The problem is
    > > I don't really know how to implement autologin on the sytem we have.
    > > Should it be some special app for this or it's possible to do just
    > > with /etc/inittab?
    > > 2) Make a daemon out of the app. This way autologin is not neccessary
    > > and I still can connect to the system and have control over it. I'll
    > > have no way to print out to the standard output, that's the minus.
    > > 3) Run the app straight from /etc/inittab. This is the easiest way,
    > > but in this case the app will block the bash and it's going to be hard
    > > to have a control over the system because now the app is blocking out
    > > the bash.

    >
    > > I need an advise which way to go and maybe what to read to know more
    > > about the way applications in embedded systems should work.

    >
    > You don't need to login to run your app. You can start it up from the
    > startup scripts. I do this on my NSLU2, WRT54G and an embedded Linux
    > board. I don't know what distribution you're using but to start up a
    > upnp daemon (your application) you can use an RC script. Under a
    > Redhat or Fedora system you would do something like this file called
    > /etc/rc.d/rc3.d/S91mh :
    >
    > #!/bin/sh
    > #
    > # chkconfig: - 91 35
    > # description: Starts and stops the cpuxa daemon
    > # mrHouse This shell script takes care of starting and stopping \
    > # MisterHouse Home Automation Software.
    > #
    > # processname: /usr/local/mh/bin/mh
    > #
    >
    > RELEASE=$(uname -r)
    >
    > # Source function library.
    > if [ -f /etc/init.d/functions ] ; then
    > . /etc/init.d/functions
    > elif [ -f /etc/rc.d/init.d/functions ] ; then
    > . /etc/rc.d/init.d/functions
    > else
    > exit 2
    > fi
    >
    > # Source function library.
    > #. /etc/rc.d/init.d/functions
    >
    > # Source networking configuration and check that networking is up.
    > if [ -f /etc/sysconfig/network ] ; then
    > . /etc/sysconfig/network
    > [ ${NETWORKING} = "no" ] && exit 0
    > fi
    >
    > [ -x /usr/local/mh/bin/mh ] || exit 0
    >
    > prog=mh
    >
    > RETVAL=0
    >
    > start () {
    > # I need this!
    > if [ -f /lib/modules/${RELEASE}/kernel/drivers/char/moxa.ko ]; then
    > modprobe moxa
    > #echo Moxa.ko driver found
    > else
    > echo Warning moxa.ko driver not found
    > fi
    >
    > # start daemon
    > # Isn't this a problem for mh?
    > export LANG=en_US
    > cd /usr/local/mh/bin/
    > daemon /usr/local/mh/bin/mh -tk 0 2>&1 >>/var/log/mh.log &
    > # /usr/local/mh/bin/mh -tk 0 2>&1 >>/var/log/mh.log &
    >
    > RETVAL=$?
    > echo -n $"Starting $prog: "
    > echo
    > # success $"$base startup"
    > [ $RETVAL = 0 ] && touch /var/lock/subsys/mh
    > return $RETVAL
    >
    > }
    >
    > stop () {
    > # stop daemon
    > killproc /usr/local/mh/bin/mh
    > RETVAL=$?
    > echo -n $"Stopping $prog: "
    > echo
    > [ $RETVAL = 0 ] && rm -f /var/lock/subsys/mh
    > return $RETVAL
    >
    > }
    >
    > restart () {
    > stop
    > start
    > RETVAL=$?
    > return $RETVAL
    >
    > }
    >
    > # See how we were called.
    > case "$1" in
    > start)
    > start
    > ;;
    > stop)
    > stop
    > ;;
    > status)
    > status /usr/local/mh/bin/mh
    > RETVAL=$?
    > ;;
    > restart)
    > restart
    > ;;
    > *)
    > echo $"Usage: $0 {start|stop|restart|status}"
    > RETVAL=1
    > esac
    >
    > exit $RETVAL
    >
    > --
    > Linux Home Automation Neil Cherry nche...@linuxha.comhttp://www.linuxha.com/ Main sitehttp://linuxha.blogspot.com/ My HA Blog
    > Author of: Linux Smart Homes For Dummies
    >
    > --
    > Linux Home Automation Neil Cherry nche...@linuxha.comhttp://www.linuxha.com/ Main sitehttp://linuxha.blogspot.com/ My HA Blog
    > Author of: Linux Smart Homes For Dummies


    Thank you, Neil. To use a script like this does my app have to be a
    daemon? If it's so, I'll have to convert it from a plain app to a
    daemon. Also, how do you debug a daemon? Can you use a printf to print
    to a standard output from it?

    Andrew

  4. Re: Running an application on startup in embedded linux

    On 2007-11-20, Trastabuga wrote:
    > On Nov 19, 7:40 pm, Neil Cherry wrote:
    >> In comp.os.linux.development.system, you wrote:
    >> > I need to run an application when the linux boots up which provides
    >> > the UPnP functionality of the box.
    >> > During development it was easy to boot the system, login as a root and
    >> > start the app from command line.
    >> > Moving to the production I started to think what would be the best
    >> > approach to start the app during booting.
    >> > 1) Autologin to linux and run it from .bash_profile. This way seems
    >> > very flexible to me because I can always connect to the box via the
    >> > serial port and kill the app, modify it and run again. The problem is
    >> > I don't really know how to implement autologin on the sytem we have.
    >> > Should it be some special app for this or it's possible to do just
    >> > with /etc/inittab?
    >> > 2) Make a daemon out of the app. This way autologin is not neccessary
    >> > and I still can connect to the system and have control over it. I'll
    >> > have no way to print out to the standard output, that's the minus.
    >> > 3) Run the app straight from /etc/inittab. This is the easiest way,
    >> > but in this case the app will block the bash and it's going to be hard
    >> > to have a control over the system because now the app is blocking out
    >> > the bash.

    >>
    >> > I need an advise which way to go and maybe what to read to know more
    >> > about the way applications in embedded systems should work.

    >>

    >
    > Thank you, Neil. To use a script like this does my app have to be a
    > daemon? If it's so, I'll have to convert it from a plain app to a
    > daemon. Also, how do you debug a daemon? Can you use a printf to print
    > to a standard output from it?
    >
    > Andrew


    by definition a daemon has no controlling terminal --- so obviously
    printf() is out for that. I suggest you start by coding your app as a
    regular program to make sure the functionality of the program is
    working. Once you get this working, you can alter it so it runs as a
    deamon. Strongly suggest you read up on daemon initialization too. W.
    Richard Stevens "Advanced Programming in a Unix Environment" would be a
    good place to start.

    --
    Mike McGinn
    "more kidneys than eyes"
    Registered Linux User 377849

  5. Running an application on startup in embedded linux

    MM> by definition a daemon has no controlling terminal --- so
    MM> obviously printf() is out for that.

    False. "Has no controlling terminal" is not the same as "has no
    standard output".

    http://homepages.tesco.net./~J.deBoy...A/unix-daemon-
    design-mistakes-to-avoid.html>

+ Reply to Thread