Chinaunix首页 | 论坛 | 博客
  • 博客访问: 76027
  • 博文数量: 34
  • 博客积分: 1166
  • 博客等级: 少尉
  • 技术积分: 340
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-15 13:01
文章分类
文章存档

2013年(2)

2011年(15)

2010年(3)

2009年(2)

2008年(3)

2007年(9)

我的朋友

分类: LINUX

2009-09-13 19:50:51

root@thrack-vdr:/tmp# uname -a
Linux thrack-vdr 2.6.28-15-generic #49-Ubuntu SMP Tue Aug 18 18:40:08 UTC 2009 i686 GNU/Linux
root@thrack-vdr:/tmp#




root@thrack-vdr:/tmp# runlevel
N 2
root@thrack-vdr:/tmp#


root@thrack-vdr:/tmp# sysv-rc-conf --list |grep rc.local
rc.local     2:on       3:on    4:on    5:on
root@thrack-vdr:/tmp#


root@thrack-vdr:/tmp# cat /etc/init.d/rc.local
#! /bin/sh
### BEGIN INIT INFO
# Provides:          rc.local
# Required-Start:    $remote_fs
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Run /etc/rc.local if it exist
### END INIT INFO


PATH=/sbin:/usr/sbin:/bin:/usr/bin

. /lib/init/vars.sh
. /lib/lsb/init-functions

do_start() {
        if [ -x /etc/rc.local ]; then
                [ "$VERBOSE" != no ] && log_begin_msg "Running local boot scripts (/etc/rc.local)"
                /etc/rc.local >> /tmp/rc.local.log 2>&1
                ES=$?
                [ "$VERBOSE" != no ] && log_end_msg $ES
                return $ES
        fi
}

case "$1" in
    start)
        do_start
        echo "rc_local_started" >> /tmp/rc.local.log
        ;;
    restart|reload|force-reload)
        echo "Error: argument '$1' not supported" >&2
        exit 3
        ;;
    stop)
        ;;
    *)
        echo "Usage: $0 start|stop" >&2
        exit 3
        ;;
esac



root@thrack-vdr:/tmp# cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

#/bin/mount /dev/sda1 /mnt/diskc
#/bin/mount /dev/sda5 /mnt/diskd
#/bin/mount -t smbfs -o username=root,password= //192.168.50.101/thrackvdr /mnt/vdrsmb

set -x

set > /tmp/rc_local_env.log

echo "bbbbbb" >> /tmp/rc.local.log

/opt/openvpn/sbin/openvpn --config /opt/openvpn/etc/client.ovpn >> /opt/openvpn/logs/client.log  2>&1 &

echo "cccc" >> /tmp/rc.local.log

exit 0
root@thrack-vdr:/tmp#


root@thrack-vdr:/tmp# reboot

来自root@thrack-vdr的广播信息
        (/dev/pts/0) at 19:59 ...

系统现在开始为了 reboot 关机
root@thrack-vdr:/tmp#



root@thrack-vdr:/tmp# cat /tmp/rc_local_env.log
IFS='
'
OPTIND='1'
PATH='/sbin:/usr/sbin:/bin:/usr/bin'
PPID='2442'
PREVLEVEL='N'
PS1='# '
PS2='> '
PS4='+ '
PWD='/'
RUNLEVEL='2'
SPLASH_ORIG_CONSOLE='8'
TERM='linux'
UPSTART_EVENT='runlevel'
UPSTART_JOB='rc2'
UPSTART_JOB_ID='6'
VERBOSE='no'
previous='N'
runlevel='2'
root@thrack-vdr:/tmp#


root@thrack-vdr:/tmp# cat /tmp/rc.local.log
+ set
+ echo bbbbbb
bbbbbb
+ echo cccc
cccc
+ exit 0
rc_local_started
root@thrack-vdr:/tmp#

可以看到,/etc/rc.local中,仅执行了echo ,set 等命令, 启动VPN那段,根本就没出现,怪异吧:)


折腾了几个小时,重启N次,加了N多断点echo,不灵光啊:)

无奈灵光一现,发现 /etc/rc.local bash 参数 !/bin/sh -e , 是不是有古怪?
查-e,查bash,呵呵,居然找到这个dash了

root@thrack-vdr:/tmp# ll /bin/sh
lrwxrwxrwx 1 root root 4 2009-09-13 19:53 /bin/sh -> dash
root@thrack-vdr:/tmp#

发现不是bash,有嫌疑,google了一把,改成bash看下


root@thrack-vdr:/tmp# sudo dpkg-reconfigure dash
正在删除 “diversion of /bin/sh to /bin/sh.distrib by dash”
正在删除 “diversion of /usr/share/man/man1/sh.1.gz to /usr/share/man/man1/sh.distrib.1.gz by dash”
root@thrack-vdr:/tmp# reboot

来自root@thrack-vdr的广播信息
        (/dev/pts/0) at 20:02 ...

系统现在开始为了 reboot 关机


root@thrack-vdr:/tmp# cat /tmp/rc.local.log
+ set
+ echo bbbbbb
bbbbbb
+ /opt/openvpn/sbin/openvpn --config /opt/openvpn/etc/client.ovpn
+ echo cccc
cccc
+ exit 0
rc_local_started
root@thrack-vdr:/tmp#


这下一切正常了:)


备注:
root@thrack-vdr:~# set |grep SHELL=/bin/bash
SHELL=/bin/bash
root@thrack-vdr:~#

表明用户登录(终端,ssh等)后默认的shell是bash来的,故在终端执行那个启动vdpn的脚本都正常。


阅读(901) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~