免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 3931 | 回复: 11
打印 上一主题 下一主题

关于Service启动脚本的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-02-12 14:31 |只看该作者 |倒序浏览
按照网上的一个脚本启动Nginx
service nginx start启动服务后(确定启动了,ps能看到进程,web服务也能访问)
但使用service nginx status来查看运行状态时,总是显示Nginx is stopped。咋回事啊?

还有这里status $prog语句中的status是什么命令?
status)
        status $prog
        RETVAL=$?
        ;;

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
2 [报告]
发表于 2009-02-12 14:37 |只看该作者
你可以输入man status
应该是查看服务状态的

论坛徽章:
0
3 [报告]
发表于 2009-02-12 15:03 |只看该作者
这个命令在那个路径下?

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
4 [报告]
发表于 2009-02-12 15:08 |只看该作者
[root@localhost bin]# whereis status
status: /sbin/status /usr/share/man/man8/status.8.gz
[root@localhost bin]#

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
5 [报告]
发表于 2009-02-12 15:09 |只看该作者
[root@localhost bin]# whereis status
status: /sbin/status /usr/share/man/man8/status.8.gz
[root@localhost bin]# file /sbin/status
/sbin/status: symbolic link to `initctl'
[root@localhost bin]# file /sbin/initctl
/sbin/initctl: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped
[root@localhost bin]#

论坛徽章:
0
6 [报告]
发表于 2009-02-12 16:53 |只看该作者
$prog 这个在哪里设定的?完整的启动脚本是什么

论坛徽章:
0
7 [报告]
发表于 2009-02-12 17:25 |只看该作者
完整脚本

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# this script create it by jackbillow at 2007.10.15.
# it is v.0.0.2 version.
# if you find any errors on this scripts,please contact jackbillow.
# and send mail to jackbillow at gmail dot com.
#
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /usr/local/nginx/logs/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf

nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid

RETVAL=0
prog="nginx"

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -x $nginxd ] || exit 0


# Start nginx daemons functions.
start() {

if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi

   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL

}


# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}


# reload nginx service functions.
reload() {

    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo

}

# See how we were called.
case "$1" in
start)
        start
        ;;

stop)
        stop
        ;;

reload)
        reload
        ;;

restart)
        stop
        start
        ;;

status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac

exit $RETVAL

论坛徽章:
0
8 [报告]
发表于 2009-02-12 17:27 |只看该作者
我用whereis没有找到status这个文件

晕啊

是不是pid文件一定生成在/var/run/下面?
我在那下面创建了nginx.pid的软链接,似乎还是不行啊

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
9 [报告]
发表于 2009-02-12 18:04 |只看该作者
原帖由 四不象 于 2009-2-12 17:27 发表
我用whereis没有找到status这个文件

晕啊

是不是pid文件一定生成在/var/run/下面?
我在那下面创建了nginx.pid的软链接,似乎还是不行啊

>是不是pid文件一定生成在/var/run/下面?
不见得

论坛徽章:
0
10 [报告]
发表于 2009-02-12 21:35 |只看该作者
搞明白了,原来这个status是/etc/init.d/functions里的一个函数

status() {                                                                  # 注释 :下面的 status 函数是判断服务的状态,总共有4种
local base=${1##*/}
local pid

# Test syntax.
if [ "$#" = 0 ] ; then
  echo $"Usage: status {program}"
  return 1
fi

# First try "pidof"                                                        # 同样是查找 pid 先。直接使用 pidof 命令
pid=`pidof -o $$ -o $PPID -o %PPID -x $1 || \               
      pidof -o $$ -o $PPID -o %PPID -x ${base}`
if [ -n "$pid" ]; then                                                    # 如果 pid 变量的值不为空,则表示找到进程,
         echo $"${base} (pid $pid) is running..."                 # 则打印 "xxx (pid nnn) is running " ,
         return 0                                                             # 并返回 0
fi

# Next try "/var/run/*.pid" files                                    # 如果 pidof 命令没有找到,则尝试从 pid 文件找
if [ -f /var/run/${base}.pid ] ; then
         read pid < /var/run/${base}.pid
         if [ -n "$pid" ]; then                                                # 如果 pidof 命令找不到,但从 pid 文件找到了 pid ,则
                 echo $"${base} dead but pid file exists"                # 打印 "xxx dead but pid file exists",
                 return 1                                                             # 并返回 1
         fi
fi
# See if /var/lock/subsys/${base} exists                            # 如果 pidof 命令和 pid 文件都没有找到 pid ,则
if [ -f /var/lock/subsys/${base} ]; then                              # 如果在 /var/lock/subsys 下存在对应的文件,则
  echo $"${base} dead but subsys locked"                                # 打印 “xxxx dead but subsys locked”,
  return 2                                                                            # 并返回 2
fi
echo $"${base} is stopped"                                                # 如果 pidof 命令、pidf 文件都没有找到pid ,且没有别锁,则打印 “xxx is stopped”
return 3                                                                           # 并返回3
}

评分

参与人数 1可用积分 +6 收起 理由
luo118 + 6 我很赞同

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP