如何利用mono把.net windows service程序迁移到linux上
How to migrate a .NET Windows Service application to Linux using mono?
写在最前:之所以用要把windows程序迁移到Linux上,主要是由于一些成本问题,这个就不多解释了。
如何把之前用.net写的windows服务程序迁移到linux上运行。答案是有很多种的,今天我只提一下mono(我只实验了mono,呵呵)。
如何在Linux部署mono,并成功的运行.net程序,还请大家多多查询吧,我在这方面也只是搭建成功了,遇到的问题不足够多,就不误导大家了。
用mono来在Linux运行一个.net程序还是很容易的,但如何运行一个后台服务程序呢,今天也是费了九牛二虎之力,最后借鉴一下stackoverflow中的一个回答来诠释这个难题吧。
Under Linux, deamons are simple background processes. No special control methods (e.g start(), stop()) are used as in Windows. Build your service as a simple (console) application, and run it in the background. Use a tool like daemonize to run a program as a Unix daemon, and remember to specify mono as the program to be activated.
As noted by others, mono-service is a host to run services built with the ServiceProcess assembly. Services built for Windows can use this method to run unmodified under Linux. You can control the service by sending signals to the process (see man page).
我英文不是太好,只能大概理解其中的意思。里边的滋味大家可以自己细细品味。
大致意思就是说,第一种方式:在Linux下可以把windows服务改造成一个控制台程序来运行。第二种方式:用mono-service来运行windows的服务程序。前提是你这个程序是有.net写成的。
mono-service运行时参数又该如何配置呢?
命令格式:mono-service [options] program.exe
-d:DIRECTORYUse this option to specify the working directory for the service. The default is the current directory.
-l:LOCKFILESpecifies the file to use for locking, the default is a filename constructed in /tmp based on the name of the program that hosts the service.
-m:MESSAGEName to show in the syslog.
-n:NAMEUse this to specify the service to be launched (if the program contains more than one service). The default is to run the first defined service.
--debug:Use this option to prevent mono-service from redirecting stdin and stdout and prevent the program to be sent to the background. Equivalent to
--no-daemon:Use this option to prevent mono-service from redirecting stdin and stdout and prevent the program to be sent to the background. Equivalent to --debug.
例:mono-service -l:/var/run/Myservice-lock.pid MyService.exe (这个-l参数一定要加上)
控制服务(这几种操作的区别请参考windows的使用方式,这里我就不做过多解释了):
暂停: kill -USR1 `cat <lock file>`
继续: kill -USR2 `cat <lock file>`
停止: kill `cat <lock file>`
这里的不是单引号,是数字1左边的那个点号。(够坑)
注意:Use mono-service to run services that use the 1.0 assemblies and use mono-service2 to run services that use the 2.0 assemblies.
mono-service可以运行.net 1.0的程序集,mono-service2可以运行.net 2.0的程序集。
对上面删除的内容做一下纠正,之前用的2.0的程序做的测试,没有发现这个问题。
后来翻了一些资料发现:mono-service已经不再支持.net程序了,mono-service2支持的还是.net2.0的程序。特别说明mono-service支持的是4.5的程序了,至于它对4.0支持如何,自己实验一下吧,我就不一一实验了。下面我为这个说法提供一些佐证:

在这里还有一种方式:http://www.cnblogs.com/sjhrun2001/archive/2009/03/10/1408264.html
如何利用mono把.net windows service程序迁移到linux上的更多相关文章
- .NET开发Windows Service程序 - Topshelf
在实际项目开发过程中,会经常写一些类似定时检查,应用监控的应用.这类应用在windows平台通常都会写成window service程序. 在百度上搜索一下'c#开发windows service', ...
- C#Windows Service程序的创建安装与卸载
C#Windows Service程序的创建安装与卸载 一.开发环境 操作系统:Windows7x64 sp1 专业版 开发环境:Visual studio 2013 编程语言:C# .NET版本: ...
- .Net程序跑在Linux上
.Net越来越拥抱开源了,今天就试了如何让.Net程序跑在Linux上,果然再无人可以阻挡.Net的脚步了. Linux Disibutaion:Open Logic 7.2 1.Install .N ...
- C#中级-Windows Service程序安装注意事项
一.前言 这周除了改写一些识别算法外,继续我的Socket服务编写.服务器端的Socket服务是以Windows Service的形式运行的. 在我完成Windows Service编写后,启动服务时 ...
- C#中级-通过注册表读取Windows Service程序执行路径
一.前言 假设我们的C#解决方案中有多个程序应用,如:Web应用.控制台程序.WPF程序应用和Windows服务应用. 那么这些非Windows Service应用程序怎么在代码中找到W ...
- windows service程序的Environment.CurrentDirectory路径
当前工作目录Environment.CurrentDirectory,对于winform程序,其是在程序放置的目录里, 而windows service的Environment.CurrentDire ...
- svn从Windows服务器上迁移到Linux上
svn从Windows服务器迁移到Linux服务器 author:headsen chen 2017-10-16 16:50:32 个人原创,转载请注明.否则依法追究法律责任 ...
- windows python文件拷贝到linux上执行问题-换行符问题/r/n
之前在Windows下写好了一个Python脚本,运行没问题,今天在Linux下,脚本开头的注释行已经指明了解释器的路径,也用chmod给了执行权限,但就是不能直接运行脚本. 1 问题1: 报错:: ...
- 把我的漫画浏览器后台程序迁移到GAE上了
这两天看了一下Python和GAE相关资料,作为练手,把我以前写的Windows 8下看漫画的程序的后台解析算法迁移到了GAE上了. 之前由于没有后台服务器,很多东西在本地实现起来不是很方便,现在拿G ...
随机推荐
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(74)-微信公众平台开发-自定义菜单
系列目录 引言 1.如果不借用Senparc.Weixin SDK自定义菜单,编码起来,工作量是非常之大 2.但是借助SDK似乎一切都是简单得不要不要的 3.自定义菜单无需要建立数据库表 4.自定义菜 ...
- [C#] C# 知识回顾 - 表达式树 Expression Trees
C# 知识回顾 - 表达式树 Expression Trees 目录 简介 Lambda 表达式创建表达式树 API 创建表达式树 解析表达式树 表达式树的永久性 编译表达式树 执行表达式树 修改表达 ...
- 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...
- Kotlin与Android SDK 集成(KAD 05)
作者:Antonio Leiva 时间:Dec 19, 2016 原文链接:https://antonioleiva.com/kotlin-integrations-android-sdk/ 使用Ko ...
- 关于Genymotion下载比较慢的解决办法
Genymotion号称Android模拟器中运行最快的,但是服务器在国外,Android镜像下载起来那个速度就不想说了. Add new device后下载速度太慢了,容易失败 先登录,然后add, ...
- 数据库备份并分离日志表(按月)sh 脚本
#!/bin/sh year=`date +%Y` month=`date +%m` day=`date +%d` hour=`date +%H` dir="/data/dbbackup/f ...
- Apache2.4:AH01630 client denied by server configuration
问题说明:Apache服务总共有4个,是为了防止单点故障和负载均衡,负载均衡控制由局方的F5提供. 访问的内容在NAS存储上,现象是直接访问每个apache的服务内容都是没有问题,但是从负载地址过来的 ...
- jetBrain系列软件
请尽量支持正版软件!https://www.jetbrains.com/ 本文仅供参考 以下提供一种方法可以无限期体验JetBrain2016系列软件. 1.下载JetbrainsCrack-2.5. ...
- 创建maven项目(cmd 命令)
2016五月 22 原 创建maven项目(cmd 命令) 分类:maven (994) (0) 1.普通方式创建 1)进入cmd窗口执行 mvn archetype:generate 2) 光标停止 ...
- linux系统下基于mono部署asp.net,使用ef6与mysql出现的问题【索引】
git clone github.com/mono的源码,日期:2014-06-19,百度网盘链接:http://pan.baidu.com/s/1kTG9EUb 关于asp.net利用mono部署到 ...