Re: Running an application on startup in embedded linux
- From: Neil Cherry <njc@xxxxxxxxxxx>
- Date: Mon, 19 Nov 2007 18:40:56 -0600
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@xxxxxxxxxxx
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@xxxxxxxxxxx
http://www.linuxha.com/ Main site
http://linuxha.blogspot.com/ My HA Blog
Author of: Linux Smart Homes For Dummies
.
- Follow-Ups:
- Re: Running an application on startup in embedded linux
- From: Trastabuga
- Re: Running an application on startup in embedded linux
- References:
- Running an application on startup in embedded linux
- From: Trastabuga
- Running an application on startup in embedded linux
- Prev by Date: Running an application on startup in embedded linux
- Next by Date: Re: lseek/write
- Previous by thread: Running an application on startup in embedded linux
- Next by thread: Re: Running an application on startup in embedded linux
- Index(es):
Relevant Pages
|