/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: - 50 50 # description: start or stop mono service by pathname # config: /etc/sysconfig/netconsole # # Copyright 2015 Qtong, Inc. # # Based in part on a shell script by # evlon <[email protected]> 2015-11-02 MONOPATH=/opt/mono/bin SHNAME=$0 SERVICENAME=$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>&2 RETVAL=2 } start () { if [ ! -d $DAEMONPATH ]; then echo $"目錄不存在 $DAEMONPATH" 1>&2 exit 3 fi if [ ! -d "$BASEPATH/$SERVICENAME" ]; then echo $"目錄不存在 $BASEPATH/$SERVICENAME" 1>&2 exit 4 fi if [ "$EXEFILE" == "" ]; then echo $"找不到可執行文件!目錄: $BASEPATH/$SERVICENAME/" 1>&2 exit 5 fi mono-service -d:$BASEPATH/${SERVICENAME} -l:$DAEMONPATH/${SERVICENAME}d $EXEFILE sleep 3 if [ ! -f $DAEMONPATH/${SERVICENAME}d ]; then echo "PID:"`cat $DAEMONPATH/${SERVICENAME}d` "Started" 1>&2 fi } stop () { if [ ! -d $BASEPATH/$SERVICENAME ]; then echo $"目錄不存在 $BASEPATH/$SERVICENAME" 1>&2 exit 3 fi if [ ! -f $DAEMONPATH/${SERVICENAME}d ]; then echo $"服務沒有運行 $BASEPATH/$SERVICENAME" 1>&2 exit 5 fi PID=`cat $DAEMONPATH/${SERVICENAME}d` kill `cat $DAEMONPATH/${SERVICENAME}d` echo "PID: $PID Stoped" 1>&2 } restart () { stop start } case "$2" in stop) stop ;; start) start;; restart|reload|force-reload) restart ;; *) usage ;; esac exit $RETVAL