公司接了一个第三方的系统,基于linux写的几个程序,一共有9个部件,第三方没有给脚本,每次启动或停止都得一个一个手工去停止或修改.......,这里稍微鄙视下。

没办法,求人还不如自己动手写,

需求简单:就是将这9个部件同时管理,可以启动与停止,可以查看当前是否运行。

脚本如下

#!/bin/bash
. /etc/init.d/functions devsNum=`ps -eo comm,pid|awk '/sdk_devs/'|wc -l`
gatewayNum=`ps -eo comm,pid|awk '/sdk_gateway/'|wc -l`
live_serverNum=`ps -eo comm,pid|awk '/sdk_live/'|wc -l`
nvr_Num=`ps -eo comm,pid|awk '/sdk_nvr/'|wc -l`
oss_Num=`ps -eo comm,pid|awk '/sdk_oss/'|wc -l`
portalNum=`ps -eo comm,pid|awk '/portal_ds6/'|wc -l`
rec_serverNum=`ps -eo comm,pid|awk '/sdk_rec/'|wc -l`
xhome_ssNum=`ps -eo comm,pid|awk '/xhome_ss/'|wc -l` #echo $devsNum $gatewayNum $live_serverNum $nvr_Num $oss_Num $portalNum $rec_serverNum $xhome_ssNu status()
{
output='printf "%-11s is Running and PID is %6s\n"'
[ $devsNum -eq ] && printf "%-11s is Running and PID is %6s\n" "dev" "`ps -eo comm,pid|awk '/sdk_devs/{print $2}'`" || echo "dev is not Run"
[ $gatewayNum -eq ] && printf "%-11s is Running and PID is %6s\n" "gateway" "`ps -eo comm,pid|awk '/sdk_gateway/{print $2}'`" || echo "gateway is not Run"
[ $live_serverNum -eq ] && printf "%-11s is Running and PID is %6s\n" "live_server" "`ps -eo comm,pid|awk '/sdk_live/{print $2}'`" || echo "live_server is not Run"
[ $nvr_Num -eq ] && printf "%-11s is Running and PID is %6s\n" "nvr" "`ps -eo comm,pid|awk '/sdk_nvr/{print $2}'`" || echo "Nvr is not Run"
[ $oss_Num -eq ] && printf "%-11s is Running and PID is %6s\n" "oss" "`ps -eo comm,pid|awk '/sdk_oss/{print $2}'`" || echo "oss is not Run"
[ $portalNum -eq ] && printf "%-11s is Running and PID is %6s\n" "portal" "`ps -eo comm,pid|awk '/portal_ds6$?/{print $2}'`" || echo "portal is not Run"
[ $rec_serverNum -eq ] && printf "%-11s is Running and PID is %6s\n" "rec_server" "`ps -eo comm,pid|awk '/sdk_rec/{print $2}'`" || echo "rec_server is not Run"
[ $xhome_ssNum -eq ] && printf "%-11s is Running and PID is %6s\n" "ss" "`ps -eo comm,pid|awk '/xhome_ss/{print $2}'`" || echo "ss is not Run"
[ `ps -e|awk '/report/'|wc -l` -eq ] && printf "%-11s is Running and PID is %6s\n" "report" "`ps -e|awk '/report/{printf("%s ",$1)}'`" || echo "report is not Run"
} start()
{
#start devs
if [ $devsNum -eq ];then
echo "dev Server is already Running"
else
cd devs
chmod +x sdk_devs_351
./sdk_devs_351 --Ice.Config=xhome_webdev.conf -s -d >& /dev/null &
[ $? -eq ] && action "Starting dev Sucessfull" /bin/true || action "Starting Failed" /bin/false
cd ..
fi #start gateway
if [ $gatewayNum -eq ];then
echo "gateway Server is already Running"
else
cd gateway
chmod +x sdk_gateway_ice351
./sdk_gateway_ice351 -s -d -alarmvideo >& /dev/null &
[ $? -eq ] && action "Starting gateway Sucessfull" /bin/true || action "Starting Failed" /bin/false
cd ..
fi #Start live_server
if [ $live_serverNum -eq ];then
echo "live_Server is already Running "
else
cd live_server
chmod +x sdk_live_server_ice351
./sdk_live_server_ice351 -s -d >& /dev/null &
[ $? -eq ] && action "Starting live_server Sucessfull" /bin/true || action "Starting Failed" /bin/false
cd ..
fi #Start nvr Server
if [ $nvr_Num -eq ];then
echo "nvr_Server is already Running "
else
cd nvr
chmod +x sdk_nvr_write
./sdk_nvr_write -s -d >& /dev/null &
[ $? -eq ] && action "Starting nvr_server Sucessfull" /bin/true || action "Starting Failed" /bin/false
cd ..
fi #start oss server
if [ $oss_Num -eq ];then
echo "oss_Server is already Running "
else
cd oss_server/
chmod +x sdk_oss_server_ice351
./sdk_oss_server_ice351 --Ice.Config=oss_server.conf -s -d >& /dev/null &
[ $? -eq ] && action "Starting oss_server Sucessfull" /bin/true || action "Starting Failed" /bin/false
cd ..
fi #start portal
if [ $portalNum -eq ];then
echo "portal_Server is already Running "
else
cd portal/
chmod +x portal_ds60_ice351
./portal_ds60_ice351 -s -d& -s -d >& /dev/null &
[ $? -eq ] && action "Starting portal Sucessfull" /bin/true || action "Starting Failed" /bin/false
cd ..
fi #start rec_server
if [ $rec_serverNum -eq ];then
echo "rec_Server is already Running "
else
cd rec_server/
chmod +x sdk_rec_server_ice351
./sdk_rec_server_ice351 any 112.74.75.20 >& /dev/null &
[ $? -eq ] && action "Starting rec_server Sucessfull" /bin/true || action "Starting Failed" /bin/false
cd ..
fi #start ss_server
if [ $xhome_ssNum -eq ];then
echo "ss_server is already Running "
else
cd ss
chmod +x xhome_ss
./xhome_ss -s -d >& /dev/null &
[ $? -eq ] && action "Starting ss_server Sucessfull" /bin/true || action "Starting Failed" /bin/false
cd ..
fi #start report
./report } stop()
{
#stop dev
killall - sdk_devs_351 >& /dev/null
[ $? -eq ] && action "stop dev" /bin/true || action "stop dev" /bin/false #stop gateway
killall - sdk_gateway_ice351 &> /dev/null
[ $? -eq ] && action "stop gateway" /bin/true || action "stop gateway" /bin/false #stop live_server
killall - sdk_live_server_ice351 &> /dev/null
[ $? -eq ] && action "stop live_server" /bin/true || action "stop live_server" /bin/false #stop nvr
killall sdk_nvr_write &> /dev/null
[ $? -eq ] && action "stop nvr" /bin/true || action "stop nvr" /bin/false
#stop oss
killall - sdk_oss_server_ice351 >& /dev/null
[ $? -eq ] && action "stop oss" /bin/true || action "stop oss" /bin/false
#stop portal
killall portal_ds6$?_ice351 >& /dev/null
[ $? -eq ] && action "stop portal" /bin/true || action "stop portal" /bin/false
#stop rec_server
killall - sdk_rec_server_ice351 &> /dev/null
[ $? -eq ] && action "stop rec_server" /bin/true || action "stop rec_server" /bin/false
#stop ss
killall - xhome_ss &> /dev/null
[ $? -eq ] && action "stop ss" /bin/true || action "stop ss" /bin/false
#stop report
killall - node_report &> /dev/null
[ $? -eq ] && action "stop report" /bin/true || action "stop ss" /bin/false } case $ in
start)
start
;;
stop)
stop
;;
status)
status
;;
*)
echo "Usage $0 {start|stop|status}"
exit
esac

运行如下:

[root@iZ94nv1rj5tZ xhome]# ./dianShiServer.sh status
dev is Running and PID is
gateway is not Run
live_server is Running and PID is
nvr is Running and PID is
oss is Running and PID is
portal is Running and PID is
rec_server is Running and PID is
ss is Running and PID is
report is Running and PID is
[root@iZ94nv1rj5tZ xhome]# ./dianShiServer.sh start
dev Server is already Running
Starting gateway Sucessfull [ OK ]
live_Server is already Running
nvr_Server is already Running
oss_Server is already Running
portal_Server is already Running
rec_Server is already Running
ss_server is already Running
node_report: no process killed
start report sucessfull

在实际使用时,发现不能单独对一个部件进行操作,

只要在case中嵌套if判断,就可实现。这里就不写更新了

linux 程序启动与停止管理脚本的更多相关文章

  1. Linux 解决数量庞大wildfly容器启动与停止的脚本

    一.问题 因公司业务的发展,后台架构的变更,导致测试环境(Linux)部署与管理困难成倍增长,duang的一下,增加N倍.进入正题说问题: 问题1.  测试环境包含普通用户环境.开发者用户环境,原来只 ...

  2. 在Linux下启动Java服务的脚本

    #!/bin/sh #该脚本为Linux下启动java程序的通用脚本.即可以作为开机自启动service脚本被调用, #也可以作为启动java程序的独立脚本来使用. # #Author: tudaxi ...

  3. Linux下启动和停止Java应用程序的Shell脚本

    转自:http://blog.csdn.net/jadyer/article/details/7960802 资料参考来源自兔大侠,并略作修改:http://www.tudaxia.com/archi ...

  4. [转] Linux中启动和停止jar包的运行

    脚本一: startTest.sh内容如下:#!/bin/shjava -jar Test.jar &       #注意:必须有&让其后台执行,否则没有pid生成echo $! &g ...

  5. Linux中启动和停止jar包的运行

    脚本一: startTest.sh内容如下: #!/bin/sh java -jar Test.jar &       #注意:必须有&让其后台执行,否则没有pid生成 echo $! ...

  6. linux防火墙启动、停止、查看

    停止防火墙 service iptables stop 启动防火墙 service iptables start 查看防火墙配置 iptables -L -n 修改的内容只是暂时保存在内存中,如果重启 ...

  7. linux程序安装及包管理

    程序包的封装类型: RPM软件包:扩展名为“.rpm”,使用rpm命令安装. DEB软件包:扩展名为“.deb”,使用DPKG包管理器. 源代码软件安装:程序员开发完成的原始代码,一般制作成“.tar ...

  8. Linux下启动、停止xampp命令

    启动xampp: /opt/lampp/./lampp start 停止xampp: /opt/lampp/./lampp stop 卸载xampp: rm -rf /opt/lampp

  9. linux下启动、停止tomcat,杀死tomcat进程

    1.打开终端 cd /java/tomcat 2.执行 bin/startup.sh #启动tomcat bin/shutdown.sh #停止tomcat tail -f logs/catalina ...

随机推荐

  1. 『Golang』Martini框架入门

    本文介绍golang中的优秀web开发框架martini! 序 Martini框架是使用Go语言作为开发语言的一个强力的快速构建模块化web应用与服务的开发框架.Martini是一个专门用来处理Web ...

  2. volatile关键字的介绍和使用

    关键字volatile的主要作用是使变量在过个线程中可见 1.假设volatile不存在我们将会面对的问题 public class PrintString implements Runnable { ...

  3. easui Pagination Layout

    分页显示方式有几种 layout: ['first', 'prev', 'next', 'last'] layout: ['list', 'sep', 'first', 'prev', 'sep', ...

  4. android 自定义照相机Camera黑屏 (转至 http://blog.csdn.net/chuchu521/article/details/8089058)

    对于一些手机,像HTC,当自定义Camera时,调用Camera.Parameters的 parameters.setPreviewSize(width, height)方法时,如果width和hei ...

  5. Fastqc 能够识别的碱基编码格式

    Fastqc 能够自动识别序列的碱基编码格式,我查看一下源代码,发现是碱基编码格式一共分为 1)sanger/illumina 1.9 2) illumina 1.3 3) illumina 1.5 ...

  6. 【Java面试题】10 abstract的method是否可同时是static,是否可同时是native,是否可同时是synchronized?

    1.abstract是抽象的,指的是方法只有声明而没有实现,他的实现要放入声明该类的子类中实现. 2.static是静态的,是一种属于类而不属于对象的方法或者属性 3.synchronized 是同步 ...

  7. PHP中替换换行符方法总结

    <?php header("content-type:text/html;charset=utf-8"); $str = "aaaa bbbb cccc dddd& ...

  8. Jquery实现上下移动和排序代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  9. apk 反编译工具的使用

    在学习android 开发的时候,我们经常回尝试使用到别人的apk,希望能了解别人怎么编写的代码,于是想要一个能实现其反编译的软件,将软件反编译出来,查看其代码. 工具/原料 反编译软件dex2jar ...

  10. libui-node体验笔记

    简介 libui-node是基于libui库的node封装.libui库是一个简便的将本地原生的GUI封装的C语言库,并支持各平台(Mac,Linux,windows).官网提供了第三方封装文档,开发 ...