码迷,mamicode.com
首页 > Windows程序 > 详细

如何利用mono把.net windows service程序迁移到linux上

时间:2014-11-05 21:14:25      阅读:323      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   os   使用   for   sp   

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:/root/service-lock MyService.exe

控制服务(这几种操作的区别请参考windows的使用方式,这里我就不做过多解释了):

暂停: kill -USR1 ‘cat <lock file>‘

继续: kill -USR2 ‘cat <lock file>‘

停止: kill ‘cat <lock file>‘

 

注意: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的程序集。

 

在这里还有一种方式:http://www.cnblogs.com/sjhrun2001/archive/2009/03/10/1408264.html

 

如何利用mono把.net windows service程序迁移到linux上

标签:style   blog   http   io   ar   os   使用   for   sp   

原文地址:http://www.cnblogs.com/eric-z/p/4077125.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!