- 由于自己的nginx 用了perl-cgi 脚本文件,同时也借用了网上的写的启动脚本,在手动的情况下没有任何问题,
-
但是在开机启动时就是不能启动。
-
第一种解决方法
-
1.启动perl-cgi 的perl 脚本
-
~]# cat /usr/local/nginx/sbin/start_perl_cgi.sh
-
#!/bin/bash
-
set -x
-
# Path manipulation
-
if [[ $# != 1 ]];then
-
echo "usage $0 start|stop|restart"
-
exit 1
-
fi
-
dir=/usr/local/nginx
-
stop ()
-
{
-
if [ -e $dir/logs/perl-fcgi.pid ];then
-
kill -USR1 `cat $dir/logs/perl-fcgi.pid` 2>&1> /dev/null
-
rm -f $dir/logs/perl-fcgi.pid 2>&1> /dev/null
-
fi
-
if [ -e $dir/logs/perl-fcgi.sock ];then
-
rm -f $dir/logs/perl-fcgi.sock 2>&1> /dev/null
-
fi
-
echo "stop perl-fcgi done"
-
}
-
start ()
-
{
-
rm -f $dir/now_start_perl_fcgi.sh 2>&1 >/dev/null
-
chown nobody.nobody $dir/logs
-
echo "$dir/perl-fcgi.pl -l $dir/logs/perl-fcgi.log -pid $dir/logs/perl-fcgi.pid -S $dir/logs/perl-fcgi.sock" >>$dir/now_start_perl_fcgi.sh
-
chown nobody.nobody $dir/now_start_perl_fcgi.sh
-
chmod u+x $dir/now_start_perl_fcgi.sh
-
sudo -u nobody $dir/now_start_perl_fcgi.sh #没改之前的
-
#su - nobody -c '/usr/local/nginx/now_start_perl_fcgi.sh' #修改后用这个正常
-
echo "start perl-fcgi done"
-
}
-
case $1 in
-
stop)
-
stop
-
;;
-
start)
-
start
-
;;
-
restart)
-
stop
-
start
-
;;
-
esac
-
2 然后加到rc.local文件中
-
/usr/local/nginx/sbin/start_perl_cgi.sh stop
-
/usr/local/nginx/sbin/start_perl_cgi.sh start
-
-
启动失败
-
日志没有任何信息。
-
-
第二种
-
然后我尝试用系统服务启动试试
-
我在etc 下 编辑/etc/init.d/perlcgi 启动脚本
-
]# cat /etc/init.d/perlcgi
-
#!/bin/bash
-
###BEGIN INIT INFO
-
# perl-fcgi This shell script takes care of starting and stopping perl-fcgi
-
#
-
# chkconfig: 2345 80 30
-
# description: perlfcgi
-
# processname: perlfcgi
-
# pidfile: /usr/local/nginx/perl-fcgi.pid
-
# description: start and stop perl_cgi for nginx
-
# name:feiyang
-
###END INIT INFO
-
#set -x
-
PERL=/usr/bin/perl
-
KILLALL=/usr/bin/killall
-
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
-
if [[ $# != 1 ]];then
-
echo "usage $0 start|stop|restart"
-
exit 1
-
fi
-
dir=/usr/local/nginx
-
stop ()
-
{
-
#pkill -f $dir/perl-fcgi.pl
-
kill $(cat $dir/logs/perl-fcgi.pid)
-
rm -f /usr/local/nginx/logs/perl-fcgi.pid 2>/dev/null
-
rm -f /usr/local/nginx/logs/perl-fcgi.sock 2>/dev/null
-
echo "stop perl-fcgi done"
-
}
-
start ()
-
{
-
kill $(cat $dir/logs/perl-fcgi.pid)
-
rm -f /usr/local/nginx/now_start_perl_fcgi.sh 2>/dev/null
-
rm -f /usr/local/nginx/logs/perl-fcgi.pid 2>/dev/null
-
rm -f /usr/local/nginx/logs/perl-fcgi.sock 2>/dev/null
-
chown nobody.nobody /usr/local/nginx/logs
-
echo "/usr/bin/perl /usr/local/nginx/perl-fcgi.pl -l /usr/local/nginx/logs/perl-fcgi.log -pid /usr/local/nginx/logs/perl-fcgi.pid -S /usr/local/nginx/logs/perl-fcgi.sock" >>/usr/local/nginx/now_start_perl_fcgi.sh
-
chown nobody.nobody /usr/local/nginx/now_start_perl_fcgi.sh
-
chmod u+x /usr/local/nginx/now_start_perl_fcgi.sh
-
sudo -u nobody -s "/usr/local/nginx/now_start_perl_fcgi.sh"
-
echo "start perl-fcgi done"
-
}
-
case $1 in
-
stop)
-
stop
-
;;
-
start)
-
start
-
;;
-
restart)
-
stop
-
start
-
;;
-
esac
-
-
2.添加系统服务
-
~]# chkconfig --add perlcgi
-
~]# chkconfig perlcgi on
-
~]# chkconfig --list | grep perlcgi
-
perlcgi 0:off 1:off 2:on 3:on 4:on 5:on 6:off
-
-
~]# find /etc/rc.d -name '*perl*' -print
-
/etc/rc.d/init.d/perlcgi
-
/etc/rc.d/rc6.d/K30perlcgi
-
/etc/rc.d/rc3.d/S80perlcgi
-
/etc/rc.d/rc2.d/S80perlcgi
-
/etc/rc.d/rc4.d/S80perlcgi
-
/etc/rc.d/rc5.d/S80perlcgi
-
/etc/rc.d/rc0.d/K30perlcgi
-
/etc/rc.d/rc1.d/K30perlcgi
-
-
#] service perlcgi start
-
-
没用问题
-
-
开机启动 不成功
-
但是开机启动是perl-cgi.pid 会存在 然后你启动失败,在启动之前rm -f 删除pid文件,不加-f 不能删掉,这点要记住,但是失败。
-
-
开始第三种
-
-
1.打开脚本调试信息 ‘set -x’
-
-
选项 说明
-
-a 自动向已经修改的变量或为导出后序命令的变量作出标志
-
-b 不是在原提示符之前,而是立即引发终止后台任务的状态表表
-
-e 如果命令带非零值返回,立即退出
-
-f 禁止带扩展名的路径
-
-h 定义函数时,定位和存储函数命令,当函数被执行时,通常查询 函数命令
-
-k 所有的关键词参数,而不只是那些命令名前的关键词参数,被放 在环境命令中
-
-m 监视器模式,启动任务控制.此选项默认支持系统shell交互.后 台进程以单独的进程组运行,在每次完成任务时显示包含退出的 状态行
-
-n 读取命令但不执行命令.通常监查shell脚本的句法错误.交互 shell被忽略
-
-o option-name 选项名可以是下列之一: 选
-
项 说明
-
allexport 同-a选项 braceexpand shell执行花括号扩展,在默认情况下起作用
-
emacs 使用emacs风格命令行编辑接口.除非shell以-noline-editing 选项启动,否则当shell交互时,通过默认启动该选项
-
errexit 同-e选项
-
histexpand 同-H选项
-
ignoreeof 其结果是好像shell命令IGNOREEOF=10被执行 interactive 允许单词前带#号,以使得在交互shell中忽略命令行的全部字符
-
-commands monitor 同-m选项 noclobber 同-C选项
-
noexec 同-n选项 noglob 同-f选项 nohash 同-d
-
选项 notify 同-b选项 nounset 同-u选项
-
physical 同-p选项 posix 改变BASH属性以匹配标准,默认操作不同于POSIX1003.2标准
-
verbose 同-v选项 vi 使用vi风格的命令行编辑器
-
XTRACE 同-x选项,如果没有给出选项名,显示当前选项值
-
-p 打开特权模式(在此模式,$ENV文件被处理,不能从环境中继承 shell函数.如果是有效用户ID而不是实用户组则自动启动.关闭 此选项将使得有效用户和组IDs设置实用户和组IDs)
-
-t 在读取命令并执行之后退出 -u 当执行参数括展时,把非设置变量作为错误处理(如果扩展企图 出现在非设置变量中,shell显示错误信息.如果不是交互式,则 带非凌值退出)
-
-v 输入行被读取时,显示shell输入行
-
-x 在每个简单命令被扩展之后,显示PS4扩展值,之后是要执行的命令
-
-l 保存和恢复绑定在命令中的名称
-
-d 禁止执行查找散列命令(通常,命令被保存在散列表中,一旦被找到 就不再继续查找)
-
-C 效果好像是执行了noclobber=shell命令
-
-H 使用!风格的历史替代(当shell交互时,在默认情况下,此选项有效)
-
-P 如果设置此参数,当执行改变目录命令cd时,不遵循符号链接,而是 使用实际的目录
-
-- 如果在选项后没有参数,不设置位置参数.否则,即使一些参数以a 选项开始,也要把位置参数设置为argument - 结束选项的信号,将引发其余的参数被赋值到位置参数中(-x和-v 选项被关闭.如果没有argument,位置参数将保留未改变的参数)
-
-
然后在rc.local 编辑如下
-
/usr/local/nginx/sbin/start_perl_cgi.sh stop 2> /home/aa
-
/usr/local/nginx/sbin/start_perl_cgi.sh start 2> /home/bb
-
在bb中看到如下
-
-
发现sudo 错误
-
-
-
将上面那个Defaults requiretty注释掉就ok了。
-
说明sudo 切换用户时是需要终端,或另一种是将sudo改为su 一切都ok。
-
-
最后我采用了系统服务启动的形式
-
-
~]# cat /etc/init.d/perlcgi
-
#!/bin/bash
-
###BEGIN INIT INFO
-
# perl-fcgi This shell script takes care of starting and stopping perl-fcgi
-
#
-
# chkconfig: 2345 80 30
-
# description: perlfcgi
-
# processname: perlfcgi
-
# pidfile: /usr/local/nginx/perl-fcgi.pid
-
# description: start and stop perl_cgi for nginx
-
# name:feiyang
-
###END INIT INFO
-
set -x
-
if [[ $# != 1 ]];then
-
echo "usage $0 start|stop|restart"
-
exit 1
-
fi
-
dir=/usr/local/nginx
-
stop ()
-
{
-
#pkill -f $dir/perl-fcgi.pl
-
kill $(cat $dir/logs/perl-fcgi.pid)
-
rm -f /usr/local/nginx/logs/perl-fcgi.pid 2>/dev/null
-
rm -f /usr/local/nginx/logs/perl-fcgi.sock 2>/dev/null
-
echo "stop perl-fcgi done"
-
}
-
start ()
-
{
-
rm -f /usr/local/nginx/now_start_perl_fcgi.sh 2>/dev/null
-
chown nobody.nobody /usr/local/nginx/logs
-
echo "/usr/bin/perl /usr/local/nginx/perl-fcgi.pl -l /usr/local/nginx/logs/perl-fcgi.log -pid /usr/local/nginx/logs/perl-fcgi.pid -S /usr/local/nginx/logs/perl-fcgi.sock" >>/usr/local/nginx/now_start_perl_fcgi.sh
-
chown nobody.nobody /usr/local/nginx/now_start_perl_fcgi.sh
-
chmod u+x /usr/local/nginx/now_start_perl_fcgi.sh
-
su - nobody -c '/usr/local/nginx/now_start_perl_fcgi.sh'
-
echo "start perl-fcgi done"
-
}
-
case $1 in
-
stop)
-
stop
-
;;
-
start)
-
start
-
;;
-
restart)
-
stop
-
start
-
;;
-
esac
-
-
然后一切ok了。
-
-
假如还不行的话,我给你一个脚本试试,哈哈 很简单的哦
-
-
#!/bin/bash
-
sleep 5
-
proce=`ps -ef | grep perl-fcgi.pl | grep -v grep`
-
num=`echo $?`
-
if [ $num != 0 ];then
-
/usr/local/nginx/sbin/start_perl_cgi.sh stop
-
/usr/local/nginx/sbin/start_perl_cgi.sh start
-
else
-
-
fi
- 让后将脚本放到rc.local中