Chinaunix

标题: 【求助】linux中启动自己的应用程序 [打印本页]

作者: xinuaile2003    时间: 2009-03-16 17:15
标题: 【求助】linux中启动自己的应用程序
我自己写的一个应用程序tree放在/usr目录下,如何让该应用程序在开机启动之后自动运行?我的系统是arm linux
我在网上和论坛里面找了很多资料,基本都是说在/etc/rc.loacl或者在/etc/rc.d/rc.loacl写上自己的命令,可是我的系统没有/etc/rc.loacl文件和/etc/rc.d目录,都无法进行,网上说的自己的命令是怎么理解?
谢谢了。

[root@boad:/etc]# ls
boa          hosts        issue.net    passwd       rc3.d        securetty
fstab        init.d       ld.so.conf   profile      rc5.d        services
group        inittab      mime.types   protocols    rcS.d        udhcpc
hostname     issue        network      rc2.d        resolv.conf

[root@boad:/etc]# cat inittab
#####################################################################
#
# INIT Configuration Table
#
# @version  $Revision: 1.1 $
#
#####################################################################
# Run the System Initialization Script
::sysinit:/etc/init.d/rcS
# Start the Terminal Shell Session. -r option to automatically login as root.
#::respawn:/sbin/getty 115200 ttyS0 vt100
#::respawn:/sbin/getty 115200 console vt100
#ttyS0:3:respawn:/sbin/getty -L tts/0 115200 vt100
tts/0:2345:respawn:/sbin/getty -L console 115200 vt100
#::restart:/sbin/init
#::shutdown:/bin/umount -a -r

[root@boad:/etc/init.d]# cat rcS
#!/bin/sh
###################################################################$
#
# Filename: /etc/init.d/mainsetup
#
# File Description: System Startup Script
#
#
#
###################################################################$
# run main startup here (coming soon)
#  for all in /etc/rcS.d/*  run scripts in numerical order.
#
    /etc/init.d/rc S
#
#  Start the main rc script after running setup.
#  /etc/initr.d/rc #    # = runlevel
    /etc/init.d/rc 3
ln -s /dev/tts/0 /dev/ttyS0
ln -s /dev/tts/1 /dev/ttyS1

[root@boad:/etc/init.d]# cat rc
#!/bin/sh
##################################################################$
#
# Filename: /etc/init.d/rc
#
# File Description: System Startup Script
#
#
#   Some code borrowed from ubuntu /etc/init.d/rc. Fixed rc.user running when RLS
#  is called. This was causing rc.user to run twice.
#
#################################################################$

## Put startup.txt into tmpfs as root is readonly
runlevel=$RUNLEVEL
# Get first argument. Set new runlevel to this argument.
# borrowed from ubuntu
[ "$1" != "" ] && runlevel=$1
if [ "$runlevel" = "" ]
then
      echo "Usage: $0 <runlevel>" >&2
      exit 1
fi

runscripts() {
        action=$1
        shift
        scripts="$@"
        for script in $scripts
          do
          case "$script" in
                  *.sh)
                          echo "Ran script " $script
                          sh "$script" $action &
                          ;;
                  *)
                          echo "Ran script " $script
                          "$script" $action &
                          ;;
          esac
    done
    wait
}

# Scan the rc*.d where * is the value passed to rc script.
# then run each of the scripts with S*_ values equal in parrallel
ACTION="start"
CURLEVEL=""
for files in /etc/rc$runlevel.d/S*
do
        level=$(echo $files | sed 's/.*\/S\([0-9][0-9]\).*/\1/')
        if [ "$level" = "$CURLEVEL" ]
        then
            continue
        fi
        CURLEVEL=$level
        SCRIPTS=""
        for i in /etc/rc$runlevel.d/S$level*
        do
            SCRIPTS="$SCRIPTS $i"
        done
        runscripts $ACTION $SCRIPTS
done
if [ $runlevel != "S" ]
then
        # If there is a rc.local then run it.
        if [ -r /etc/rc.local ]; then
               . /etc/rc.local
        fi
fi

[ 本帖最后由 xinuaile2003 于 2009-3-16 17:18 编辑 ]
作者: kns1024wh    时间: 2009-03-16 23:07
标题: 回复 #1 xinuaile2003 的帖子
这个还是要放在rc.loacl这里
作者: xinuaile2003    时间: 2009-03-17 08:08
原帖由 kns1024wh 于 2009-3-16 23:07 发表
这个还是要放在rc.loacl这里



好的,谢谢!我先试试,要是不明白的,还要请教你了。
作者: xinuaile2003    时间: 2009-03-17 11:03
原帖由 kns1024wh 于 2009-3-16 23:07 发表
这个还是要放在rc.loacl这里



整了半天了,还是没法整出来,能否给个脚本示例?
作者: bxfqing    时间: 2009-03-17 11:20
截取至:linuxrc
#execute the  XXXX install file
./home/XXXX/install 我自启动脚本
exec /sbin/init
使用环境 kernel 2.6.24 ARM9
原帖由 xinuaile2003 于 2009-3-17 11:03 发表



整了半天了,还是没法整出来,能否给个脚本示例?

作者: xinuaile2003    时间: 2009-03-17 11:40
原帖由 bxfqing 于 2009-3-17 11:20 发表
截取至:linuxrc
#execute the  XXXX install file
./home/XXXX/install 我自启动脚本
exec /sbin/init
使用环境 kernel 2.6.24 ARM9


我在/etc下面建了一个rc.loacl文件,文件内容为
#!/bin/sh
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
echo "start boa server"
./usr/tree

echo "end boa server"

启动结果是
start boa server
: not found/rc: /etc/rc.local: line
6: ./usr/tree
end boa server

echo可以运行,但是我的应用程序就是运行不起来。
作者: bxfqing    时间: 2009-03-17 11:52
1,确认 文件名是否正确
2,启动脚本添加可执行权限
3,如果是用户态的执行文件 如: lead.out 要增加执行权限
原帖由 xinuaile2003 于 2009-3-17 11:40 发表


我在/etc下面建了一个rc.loacl文件,文件内容为
#!/bin/sh
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
...

作者: xinuaile2003    时间: 2009-03-17 11:56
原帖由 bxfqing 于 2009-3-17 11:52 发表
1,确认 文件名是否正确
2,启动脚本添加可执行权限
3,如果是用户态的执行文件 如: lead.out 要增加执行权限


文件名肯定正确的。
启动脚本是指rc.loacl文件吗?要是的话,肯定有执行权限,tree是我写的应用程序。
我的应用程序tree是一个执行文件,也增加了执行权限了。
作者: bxfqing    时间: 2009-03-17 14:30
标题: 回复 #8 xinuaile2003 的帖子
不行把你写的脚本放在linuxrc文件启动吧;
作者: xinuaile2003    时间: 2009-03-17 15:07
原帖由 bxfqing 于 2009-3-17 14:30 发表
不行把你写的脚本放在linuxrc文件启动吧;


linuxrc是指向busybox的一个链接,无法修改的。
作者: xinuaile2003    时间: 2009-03-17 17:23
问题解决,每一句的换行符错误,我使用的是windows下的
谢谢大家。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2