-2

我要做的是在启动时运行应用程序。所以我把它作为一种服务。即作为 /etc/init.d 下的 shell 脚本。我正在使用 Ubuntu .. 问题是我必须在 /var/run 目录下创建一个文件夹,如果它不存在的话。以下是我的代码。

#!/bin/sh
set -e

start() {


if [ -d "/var/run/bucardo" ]; then
    echo "Directory Exists" 
    echo -n "Starting bucardo: "
    sudo bucardo_ctl start 
    echo "done."
else
    echo "Creating Directory" 
    sudo mkdir /var/run/bucardo
    echo -n "Starting bucardo: "
    sudo bucardo_ctl start 
    echo "done."
fi
}

stop() {
echo -n "Shutting down bucardo: "
sudo bucardo_ctl stop
echo "done."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 10
start
;;
*)

esac
exit 0

所以在 /var/run 下创建一个文件夹,这是应用程序的默认文件夹。

如何在 shell 脚本中创建带密码的文件夹。这样我就可以检查文件夹并创建它。

以下是我在启动时运行脚本时遇到的错误。我使用以下命令来执行它“chkconfig --level 234 bocardo”

以下是错误..

insserv: warning: script 'K01centrifyda' missing LSB tags and overrides
insserv: warning: script 'K01cups' missing LSB tags and overrides
insserv: warning: script 'K01acpi-support' missing LSB tags and overrides
insserv: warning: script 'bucardo' missing LSB tags and overrides
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'hwclock-save' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `hwclock-save'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `hwclock-save'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'ufw' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `ufw'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `ufw'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'lightdm' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `lightdm'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `lightdm'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'acpid' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `acpid'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `acpid'
insserv: warning: script 'centrifyda' missing LSB tags and overrides
insserv: warning: script 'adnisd' missing LSB tags and overrides
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'binfmt-support' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `binfmt-support'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `binfmt-support'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'plymouth-splash' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `plymouth-splash'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `plymouth-splash'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'network-interface' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `network-interface'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `network-interface'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'plymouth-log' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `plymouth-log'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `plymouth-log'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'alsa-restore' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `alsa-restore'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `alsa-restore'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'procps' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `procps'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `procps'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'udevtrigger' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `udevtrigger'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `udevtrigger'
insserv: warning: script 'cups' missing LSB tags and overrides
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'setvtrgb' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `setvtrgb'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `setvtrgb'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.
insserv: warning: script 'udev' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `udev'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `udev'
The script you are attempting to invoke has been converted to an Upstart
job, but lsb-header is not supported for Upstart jobs.

很长...请帮助我..提前谢谢..

根据彼得的建议.. 以下是在 Ubentu 中将其作为服务的链接.. http://jonathonhill.net/2009-04-23/auto-start-a-shell-script-on-ubuntu-server/

4

1 回答 1

3

你没有说问题实际上是什么。是不是sudo mkdir要求输入密码?初始化脚本通常需要以 root 身份运行(并且将在正常启动期间运行),因此您根本不希望sudo在脚本中运行。在测试时,就sudo在您运行脚本时。

另外,考虑折叠目录存在条件,只使用mkdir -p,如果目录已经存在,则不会出错。

于 2012-05-24T15:39:28.097 回答