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

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

目的:使用mono将ASPNET编写的Window服务移植到Linux下运行

使用的软件:mono20, Linux Red hat

步骤:

1、在Window下编写一个Remoting服务端作为Window服务。包括

  RemoteServerexe(服务运行文件)

RemoteServerexeconfig(配置文件)

将这两个文件放到Linux系统的一个目录下,本例放在/home/RemoteTest/RemoteServer下

2、 编写Linux服务脚本sjhServer,将脚本放在 /etc/rcd/initd目录下

3、 建立符号链接。建立相应运行级别的脚本符号链接,本例中是2、3、4、5级,使用命令 :

cd /etc/rcd/rc2d (相应地建立第3级的链接,cd到rc3d目录下)

ln –s /etc/rcd/initd/sjhServer S97sjhServer

4、 启动服务。使用命令:

service sjhService start

5、 本例中有一个客户端程序RemoteClientexe用做侦听。运行RemoteClientexe,返回运行结果说明服务已经在运行,如果客户端出现目标机器积极拒绝说明服务没有启动

6、停止服务,使用命令:

service sjhService stop

到此ASPNET的服务移植到Linux就算完成,和其它Linux的系统服务一样,操作方法都一样。

存在的几个疑点:

一、第3点建立符号链接时,只建立了S的链接,没有建立K的链接。还有启动和停止服务的顺序的定义有什么规则,是否对其它服务有顺序上的依赖。

二、服务的暂停不起作用,Remoting这个服务是否没有这个概念。其它类型服务有待测试。

另外一种方式:

如何在Linux部署mono,并成功的运行net程序,还请大家多多查询吧,我在这方面也只是搭建成功了,遇到的问题不足够多,就不误导大家了。

用mono来在Linux运行一个net程序还是很容易的,但如何运行一个后台服务程序呢,今天也是费了九牛二虎之力,最后借鉴一下stackoverflow中的一个回答来诠释这个难题吧。

Under Linux, deamons are simple background processes No special control methods (eg 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 daemonizeto 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] programexe

-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 MyServiceexe

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

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

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

停止: kill 'cat <lock file>'

注意:Use mono-service to run services that use the 10 assemblies and use mono-service2 to run services that use the 20 assemblies

mono-service可以运行net 10的程序集,mono-service2可以运行net 20的程序集。

还可以运行的……

明白啥意思吧?

你现在已经无法离开微软而生活了,准备黑屏net

是微软的产品,只能使用在微软出品的操作系统上。

不过

novell

有微软的授权。但很可惜,除非你的

net

网站是针对

mono

编写而不是针对

net

编写的话,他做了一个叫

mono

的软件库,在

linux

上面支持

net

DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
网站模板库 » 如何利用mono把.net windows service程序迁移到linux上

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情