战魂小筑

讨论群:309800774 知乎关注:http://zhihu.com/people/sunicdavy 开源项目:https://github.com/davyxu

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  257 随笔 :: 0 文章 :: 506 评论 :: 0 Trackbacks
#!/bin/bash
# chkconfig: 3 3 1
# description: svclauncher
ServicePath=/usr/local/bin

ServiceList=(
"wkcenterd --toc /home/davy/dev/kaze/Config/CenterService.toc --logfile /tmp/centerd.log"
"wkagentd --toc /home/davy/dev/kaze/Config/AgentService.toc --logfile /tmp/agentd.log"
)

StartAll()
{
    for((i = 0;i<${#ServiceList[*]};i=i+1))
    do

     echo "start:" $ServicePath/${ServiceList[i]}
     $ServicePath/${ServiceList[i]} > /dev/null &

    done
}

StopAll()
{
    for((i = 0;i<${#ServiceList[*]};i=i+1))
    do

     echo "stop:" $ServicePath/${ServiceList[i]}
     svcname=`echo ${ServiceList[i]} | awk '{print $1}'`
     killall $svcname > /dev/null

    done
}

RestartAll()
{
    StopAll
    StartAll
}


InstallService()
{
    svcname=`basename $0`
    chmod +x $svcname
    cp $svcname /etc/init.d
    ln /etc/init.d/$svcname /etc/rc3.d/S03$svcname
    ln /etc/init.d/$svcname /etc/rc0.d/K03$svcname
    chkconfig --add $svcname
    chkconfig $svcname on
    chkconfig --list | grep $svcname
}

UninstallService()
{
    svcname=`basename $0`
    chkconfig --del $svcname
    rm -f /etc/init.d/$svcname
    rm -f /etc/rc3.d/S03$svcname
    rm -f /etc/rc3.d/K03$svcname
}



case "$1" in
    start)
    StartAll
    ;;
    stop)
    StopAll
    ;;
    restart)
    RestartAll
    ;;
    install)
    InstallService
    ;;
    uninstall)
    UninstallService
    ;;
    *)
           echo "Usage: service $EXEC {install|start|stop|restart|uninst}"
       exit 1
esac
 
exit $? 

posted on 2012-04-12 09:33 战魂小筑 阅读(2043) 评论(0)  编辑 收藏 引用 所属分类: 脚本技术网络 服务器技术操作系统

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理