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上的更多相关文章

  1. .NET开发Windows Service程序 - Topshelf

    在实际项目开发过程中,会经常写一些类似定时检查,应用监控的应用.这类应用在windows平台通常都会写成window service程序. 在百度上搜索一下'c#开发windows service', ...

  2. C#Windows Service程序的创建安装与卸载

    C#Windows Service程序的创建安装与卸载 一.开发环境 操作系统:Windows7x64 sp1 专业版 开发环境:Visual studio 2013 编程语言:C# .NET版本: ...

  3. .Net程序跑在Linux上

    .Net越来越拥抱开源了,今天就试了如何让.Net程序跑在Linux上,果然再无人可以阻挡.Net的脚步了. Linux Disibutaion:Open Logic 7.2 1.Install .N ...

  4. C#中级-Windows Service程序安装注意事项

    一.前言 这周除了改写一些识别算法外,继续我的Socket服务编写.服务器端的Socket服务是以Windows Service的形式运行的. 在我完成Windows Service编写后,启动服务时 ...

  5. C#中级-通过注册表读取Windows Service程序执行路径

    一.前言        假设我们的C#解决方案中有多个程序应用,如:Web应用.控制台程序.WPF程序应用和Windows服务应用. 那么这些非Windows Service应用程序怎么在代码中找到W ...

  6. windows service程序的Environment.CurrentDirectory路径

    当前工作目录Environment.CurrentDirectory,对于winform程序,其是在程序放置的目录里, 而windows service的Environment.CurrentDire ...

  7. svn从Windows服务器上迁移到Linux上

    svn从Windows服务器迁移到Linux服务器    author:headsen chen   2017-10-16  16:50:32  个人原创,转载请注明.否则依法追究法律责任       ...

  8. windows python文件拷贝到linux上执行问题-换行符问题/r/n

    之前在Windows下写好了一个Python脚本,运行没问题,今天在Linux下,脚本开头的注释行已经指明了解释器的路径,也用chmod给了执行权限,但就是不能直接运行脚本. 1 问题1: 报错:: ...

  9. 把我的漫画浏览器后台程序迁移到GAE上了

    这两天看了一下Python和GAE相关资料,作为练手,把我以前写的Windows 8下看漫画的程序的后台解析算法迁移到了GAE上了. 之前由于没有后台服务器,很多东西在本地实现起来不是很方便,现在拿G ...

随机推荐

  1. npm 私有模块的管理使用

    你可以使用 NPM 命令行工具来管理你在 NPM 仓库的私有模块代码,这使得在项目中使用公共模块变的更加方便. 开始前的工作 你需要一个 2.7.0 以上版本的 npm ,并且需要有一个可以登陆 np ...

  2. 学点HTTP知识

    不学无术 又一次感觉到不学无术,被人一问Http知识尽然一点也没答上来,丢人丢到家了啊.平时也看许多的技术文章,为什么到了关键时刻就答不上来呢? 确实发现一个问题,光看是没有用的,需要实践.看别人说的 ...

  3. DDD初学指南

    去年就打算总结一下,结果新换的工作特别忙,就迟迟没有认真动手.主要内容是很多初学DDD甚至于学习很长时间的同学没有弄明白DDD是什么,适合什么情况.这世界上没有银弹,抛开了适合的场景孤立的去研究DDD ...

  4. ASP.NET MVC5+EF6+EasyUI 后台管理系统(75)-微信公众平台开发-用户管理

    系列目录 前言 本节主要是关注者(即用户)和用户组的管理,微信公众号提供了用户和用户组的管理,我们可以在微信公众号官方里面进行操作,添加备注和标签,以及移动用户组别,同时,微信公众号也提供了相应的接口 ...

  5. Mac OS、Ubuntu 安装及使用 Consul

    Consul 概念(摘录): Consul 是 HashiCorp 公司推出的开源工具,用于实现分布式系统的服务发现与配置.与其他分布式服务注册与发现的方案,比如 Airbnb 的 SmartStac ...

  6. 【从零开始学BPM,Day3】自定义表单开发

    [课程主题] 主题:5天,一起从零开始学习BPM [课程形式] 1.为期5天的短任务学习 2.每天观看一个视频,视频学习时间自由安排. [第三天课程] 1.课程概要 Step 1 软件下载:H3 BP ...

  7. linux字符串url编码与解码

    编码的两种方式 echo '手机' | tr -d '\n' | xxd -plain | sed 's/\(..\)/%\1/g' echo '手机' |tr -d '\n' |od -An -tx ...

  8. 微软收购Xamarin,你怎么看?

    今天的最大新闻就是微软收购热门初创企业Xamarin,从网上的反馈大部分都是积极的,也有担心微软在把Xamarin移动开发技术整合进VS的同时,还很有可能废掉MONO的GUI客户端能力只保留.net ...

  9. 工大助手(C#与python交互)

    工大助手(爬虫--C#与python交互) 基本内容 工大助手(桌面版) 实现登陆.查成绩.计算加权平均分等功能 团队人员 13070046 孙宇辰 13070003 张帆 13070004 崔巍 1 ...

  10. 小丁带你走进git的世界二-工作区暂存区分支

    小丁带你走进git的世界二-工作区暂存区分支 一.Git基本工作流程 1.初始化一个仓库 git  init git  clone git仓库分为两种情况: 第一种是在现有项目或目录下导入所有文件到 ...