Control the start and stop of the mono service in Linux

Source: Internet
Author: User

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
#
# Run Mono. Service on monosd to start and stop the. net Service.
# For example, when the directory structure is as follows, 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
# Evlon <evlion@qq.com> 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 $ "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 ;;
Esac

Exit $ RETVAL

You may also like the following Mono and Jexus articles:

Deploy Mono 4 and Jexus 5.6 On CentOS 7

Deploying. NET, Mono and DNX in Ubuntu 15.04 and CentOS 7

Configure ASP. NET (Apache + Mono) in Linux (Ubuntu/openSUSE/CentOS)

Configure the Linux (Apache) + Mono to run asp.net

How to upgrade Mono

Idea about running ASP. NET 4 website in Mono 3.0

Install Mono and Jexus on Ubuntu to build the. NET Runtime Environment

Ubuntu 14.04 configure Mono + Jexus to run ASP. NET

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.