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 # The following directory structure is required to stop:
/Opt/basepath/s1/sample1.exe # Service 1. The file name is not limited to s2/sampleservice2.exe # Service 2. The file name is not limited to daemon. d/# Empty directory, put the process identifier 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 <[email protected]> 2015-11-02MONOPATH =/opt/mono/binSHNAME = $0 SERVIC ENAME = $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