Control the start and stop of the mono service in Linux.
When the services in windows are deployed to Linux, we generally use Mono. service to start and stop. It is not easy to use because there are many parameters. So there is a Shell script.
Usage: moa s1 start # start
Moa s1 stop # stop
The following directory structure is required:
/Opt/basepath/
S1/
Sample1.exe # Service 1 with unlimited file names
S2/
Sampleservice2.exe # Service 2 with unlimited file names
Daemon. d/# Empty directory, place process ID
Moa # Shell script
#! /Bin/bash # Mono is executed by monosd. service starts and stops. net service, according to the directory name. # For example, when the directory structure is as follows, monosd s1 start/stop #/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 <evlion@qq.com> 2015-11-02MONOPATH =/opt/mono/binSHNAME = $0 SERVICENAM E = $1 # BASEPATH =/opt/$ {SHNAME ### */} # BASEPATH =$ {SHNAME %/*} BASEPATH =$ (cd 'dirname $0 '; pwd) DAEMONPATH = $ BASEPATH/daemon. dPATH = $ MONOPATH: $ PATHRETVAL = 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 $ "the directory does not exist $ DAEMONPATH" 1> & 2 exit 3 fi if [! -D "$ BASEPATH/$ SERVICENAME"]; then echo $ "the directory does not exist $ BASEPATH/$ SERVICENAME" 1> & 2 exit 4 fi if ["$ EXEFILE" = ""]; then echo $ "the executable file cannot be found! Directory: $ 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 $ "the directory does not exist $ BASEPATH/$ SERVICENAME" 1> & 2 exit 3 fi if [! -F $ DAEMONPATH/$ {SERVICENAME} d]; then echo $ "the service is not running $ 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; esacexit $ RETVAL