/etc/rc.local 未在 Ubuntu 桌面安装上运行

/etc/rc.local 未在 Ubuntu 桌面安装上运行

我一直想让 sphinx 在启动时运行,所以我添加了一些代码,/etc/rc.local但启动时什么都没发生。但如果我手动运行它,它就会正常工作。

/etc/init.d/rc.local start工作正常/etc/rc.local

它在默认运行级别中列出并且全部可执行,但它不起作用。

我正在考虑编写一个单独的 init.d 脚本来做同样的事情,但对于一个简单的任务来说,这需要做很多工作

dumbledore:/etc/init.d# ls -l rc*
-rwxr-xr-x 1 root root 8863 2009-09-07 13:58 rc
-rwxr-xr-x 1 root root  801 2009-09-07 13:58 rc.local
-rwxr-xr-x 1 root root  117 2009-09-07 13:58 rcS

dumbledore:/etc/init.d# ls /etc/rc.local  -l
-rwxr-xr-x 1 root root 491 2011-05-14 16:13 /etc/rc.local

dumbledore:/etc/init.d# runlevel
N 2

dumbledore:/etc/init.d# ls /etc/rc2.d/ -l
total 4
lrwxrwxrwx 1 root root  18 2011-04-22 18:53 K08vmware -> /etc/init.d/vmware
-rw-r--r-- 1 root root 677 2011-03-28 15:10 README
lrwxrwxrwx 1 root root  18 2011-04-22 18:53 S19vmware -> /etc/init.d/vmware
lrwxrwxrwx 1 root root  18 2011-05-15 14:09 S20ddclient -> ../init.d/ddclient
lrwxrwxrwx 1 root root  20 2011-03-10 18:00 S20fancontrol -> ../init.d/fancontrol
lrwxrwxrwx 1 root root  20 2011-03-10 18:00 S20kerneloops -> ../init.d/kerneloops
lrwxrwxrwx 1 root root  27 2011-03-10 18:00 S20speech-dispatcher -> ../init.d/speech-dispatcher
lrwxrwxrwx 1 root root  19 2011-03-10 18:00 S25bluetooth -> ../init.d/bluetooth
lrwxrwxrwx 1 root root  20 2011-03-10 18:00 S50pulseaudio -> ../init.d/pulseaudio
lrwxrwxrwx 1 root root  15 2011-03-10 18:00 S50rsync -> ../init.d/rsync
lrwxrwxrwx 1 root root  15 2011-03-10 18:00 S50saned -> ../init.d/saned
lrwxrwxrwx 1 root root  19 2011-03-10 18:00 S70dns-clean -> ../init.d/dns-clean
lrwxrwxrwx 1 root root  18 2011-03-10 18:00 S70pppd-dns -> ../init.d/pppd-dns
lrwxrwxrwx 1 root root  14 2011-05-07 11:22 S75sudo -> ../init.d/sudo
lrwxrwxrwx 1 root root  24 2011-03-10 18:00 S90binfmt-support -> ../init.d/binfmt-support
lrwxrwxrwx 1 root root  17 2011-05-12 21:18 S91apache2 -> ../init.d/apache2
lrwxrwxrwx 1 root root  22 2011-03-10 18:00 S99acpi-support -> ../init.d/acpi-support
lrwxrwxrwx 1 root root  21 2011-03-10 18:00 S99grub-common -> ../init.d/grub-common
lrwxrwxrwx 1 root root  18 2011-03-10 18:00 S99ondemand -> ../init.d/ondemand
lrwxrwxrwx 1 root root  18 2011-03-10 18:00 S99rc.local -> ../init.d/rc.local

dumbledore:/etc/init.d# 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.

# Start sphinx daemon for rails app on startup
# Added 2011-05-13
# Cannon Matthews
cd /var/www/extemp
/usr/bin/rake ts:config
/usr/bin/rake ts:start
touch ./tmp/ohyeah
cd -

exit 0

dumbledore:/etc/init.d# cat /etc/init.d/rc.local

#! /bin/sh
### BEGIN INIT INFO
# Provides:          rc.local
# Required-Start:    $remote_fs $syslog $all
# 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
        ES=$?
        [ "$VERBOSE" != no ] && log_end_msg $ES
        return $ES
    fi
}

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

答案1

/etc/rc.local 上的命令之一必须以非零状态退出。由于-e第一行中 sh 的参数,这会导致脚本立即退出。

您可以删除-e或者找到负责的命令并修复其错误。

答案2

问题可能出在更改目录。尝试将所有这些内容放在带有#!/bin/bashhashbang 的单独脚本中,然后从 rc.local 调用该脚本。

相关内容