Re: Running an application on startup in embedded linux
- From: Trastabuga <lispercat@xxxxxxxxx>
- Date: Tue, 20 Nov 2007 06:16:19 -0800 (PST)
On Nov 19, 7:40 pm, Neil Cherry <n...@xxxxxxxxxxx> 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...@xxxxxxxxxxxxxxx://www.linuxha.com/ Main sitehttp://linuxha.blogspot.com/ My HA Blog
Author of: Linux Smart Homes For Dummies
--
Linux Home Automation Neil Cherry nche...@xxxxxxxxxxxxxxx://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
.
- Follow-Ups:
- Re: Running an application on startup in embedded linux
- From: Mike McGinn
- Re: Running an application on startup in embedded linux
- References:
- Running an application on startup in embedded linux
- From: Trastabuga
- Re: Running an application on startup in embedded linux
- From: Neil Cherry
- Running an application on startup in embedded linux
- Prev by Date: Re: How to replace usb_register_dev() in a PCI driver
- Next by Date: Re: Running an application on startup in embedded linux
- Previous by thread: Re: Running an application on startup in embedded linux
- Next by thread: Re: Running an application on startup in embedded linux
- Index(es):
Relevant Pages
|