现在的位置: 首页 > 综合 > 正文

linux 未识别的服务

2012年12月24日 ⁄ 综合 ⁄ 共 862字 ⁄ 字号 评论关闭

给linux添加服务的步骤:

第一:编写服务脚本,命名为:testService

start()
{
    echo "start testService"
    /usr/local/bin/testService &   #可执行文件路径
    exit 0;
}
stop()
{
    echo -n "stop testService"
    if pkill testService
        then
        echo  "              [ok]"
    else
        echo  "              [failed]"
    fi
}
case "$1" in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
    stop
    start
    ;;
*)
    echo "usage: $0 start|stop|restart"
    exit 0;
esac

第二:把文件testService拷贝到/etc/init.d/目录下面

第三:就可以执行service testService start (stop 、 restart)来操作文件了。


但是今天遇到意见郁闷的事,

第一:检查文件是否在/usr/init.d/目录下面,文件确确实实存在

第二:执行service testService start ,报错,未识别的服务,

第三:检查脚本文件,是否正确,确确实实正确,执行其他服务都能执行

检查了下/usr/init.d/testServic的权限,如下:

[root@~]# service testService start
uapd: 未被识别的服务
[root@~]# ll /etc/init.d/testService                  #检查权限
---------- 1 root root 1025 08-30 17:47 /etc/init.d/testService #文件权限
[root@~]# 
[root@~]# chmod 033 /etc/init.d/testService           #设置文件权限
[root@~]# service uapd start
start testService  [确定]
[root@~]# 

解决:

1、先检查了文件的权限,此时即使文件在/etc/init.d/testService目录下,仍然不能使用服务

2、设置了文件权限后,服务能够正常识别了

抱歉!评论已关闭.