控制Linux下mono服务的启动停止
來源:互聯網 2016-08-27 13:36:13 評論
当Window下的服务部署到linux的时候,我们一般用Mono.service 来启动停止。参数比较多,不太好用。于是有个这个Shell脚本。
用法:moa s1 start #启动
moa s1 stop # 停止
要求有如下的目录结构:
/opt/basepath/
s1/
sample1.exe #服务1,文件名称不限
s2/
sampleservice2.exe #服务2 ,文件名称不限
daemon.d/ #空目录,放置进程标识
moa #Shell脚本
#!/bin/bash
#
# monosd 执行Mono.Service 启动停止 .net 服务,根据目录名.
# 例如:目录结构如下时候, monosd s1 start/stop
#/opt/basedir/#/opt/basedir/s1
#/opt/basedir/s1/xxxxx.exe
#
#
# chkconfig:-5050# description: start or stop mono service by pathname
# config:/etc/sysconfig/netconsole
#
# Copyright2015Qtong, Inc.
#
# Basedinpart on a shell script by
# evlon2015-11-02MONOPATH=/opt/mono/bin
SHNAME=$0SERVICENAME=$1#BASEPATH=/opt/${SHNAME##*/}
#BASEPATH=${SHNAME%/*}
BASEPATH=$(cd `dirname $0`; pwd)
DAEMONPATH=$BASEPATH/daemon.d
PATH=$MONOPATH:$PATH
RETVAL=0
EXEFILE=`find $BASEPATH/$SERVICENAME/ -name *.exe`
EXEFILE=${EXEFILE##*/}
usage ()
{echo$"Usage: $0 servicePathName {start|stop}"1>&2RETVAL=2}
start ()
{if[ ! -d $DAEMONPATH ];thenecho$"目录不存在 $DAEMONPATH"1>&2exit3fiif[ ! -d"$BASEPATH/$SERVICENAME"];thenecho$"目录不存在 $BASEPATH/$SERVICENAME"1>&2exit4fiif["$EXEFILE"==""];thenecho$"找不到可执行文件!目录: $BASEPATH/$SERVICENAME/"1>&2exit5fimono-service -d:$BASEPATH/${SERVICENAME} -l:$DAEMONPATH/${SERVICENAME}d $EXEFILEsleep3if[ ! -f $DAEMONPATH/${SERVICENAME}d ];thenecho"PID:"`cat$DAEMONPATH/${SERVICENAME}d`"Started"1>&2fi}
stop ()
{if[ ! -d $BASEPATH/$SERVICENAME ];thenecho$"目录不存在 $BASEPATH/$SERVICENAME"1>&2exit3fiif[ ! -f $DAEMONPATH/${SERVICENAME}d ];thenecho$"服务没有运行 $BASEPATH/$SERVICENAME"1>&2exit5fiPID=`cat$DAEMONPATH/${SERVICENAME}d`kill`cat$DAEMONPATH/${SERVICENAME}d`echo"PID: $PID Stoped"1>&2}
restart ()
{
stop
start
}case"$2"instop) stop ;;
start) start;;
restart|reload|force-reload) restart ;;*) usage ;;esacexit $RETVAL
当Window下的服务部署到linux的时候,我们一般用Mono.service 来启动停止。参数比较多,不太好用。于是有个这个Shell脚本。
用法:moa s1 start #启动
moa s1 stop # 停止
要求有如下的目录结构:
/opt/basepath/
s1/
sample1.exe #服务1,文件名称不限
s2/
sampleservice2.exe #服务2 ,文件名称不限
daemon.d/ #空目录,放置进程标识
moa #Shell脚本
#!/bin/bash
#
# monosd 执行Mono.Service 启动停止 .net 服务,根据目录名.
# 例如:目录结构如下时候, monosd s1 start/stop
#/opt/basedir/#/opt/basedir/s1
#/opt/basedir/s1/xxxxx.exe
#
#
# chkconfig:-5050# description: start or stop mono service by pathname
# config:/etc/sysconfig/netconsole
#
# Copyright2015Qtong, Inc.
#
# Basedinpart on a shell script by
# evlon2015-11-02MONOPATH=/opt/mono/bin
SHNAME=$0SERVICENAME=$1#BASEPATH=/opt/${SHNAME##*/}
#BASEPATH=${SHNAME%/*}
BASEPATH=$(cd `dirname $0`; pwd)
DAEMONPATH=$BASEPATH/daemon.d
PATH=$MONOPATH:$PATH
RETVAL=0
EXEFILE=`find $BASEPATH/$SERVICENAME/ -name *.exe`
EXEFILE=${EXEFILE##*/}
usage ()
{echo$"Usage: $0 servicePathName {start|stop}"1>&2RETVAL=2}
start ()
{if[ ! -d $DAEMONPATH ];thenecho$"目录不存在 $DAEMONPATH"1>&2exit3fiif[ ! -d"$BASEPATH/$SERVICENAME"];thenecho$"目录不存在 $BASEPATH/$SERVICENAME"1>&2exit4fiif["$EXEFILE"==""];thenecho$"找不到可执行文件!目录: $BASEPATH/$SERVICENAME/"1>&2exit5fimono-service -d:$BASEPATH/${SERVICENAME} -l:$DAEMONPATH/${SERVICENAME}d $EXEFILEsleep3if[ ! -f $DAEMONPATH/${SERVICENAME}d ];thenecho"PID:"`cat$DAEMONPATH/${SERVICENAME}d`"Started"1>&2fi}
stop ()
{if[ ! -d $BASEPATH/$SERVICENAME ];thenecho$"目录不存在 $BASEPATH/$SERVICENAME"1>&2exit3fiif[ ! -f $DAEMONPATH/${SERVICENAME}d ];thenecho$"服务没有运行 $BASEPATH/$SERVICENAME"1>&2exit5fiPID=`cat$DAEMONPATH/${SERVICENAME}d`kill`cat$DAEMONPATH/${SERVICENAME}d`echo"PID: $PID Stoped"1>&2}
restart ()
{
stop
start
}case"$2"instop) stop ;;
start) start;;
restart|reload|force-reload) restart ;;*) usage ;;esacexit $RETVAL