使用 mono-service 在 Linux 上包装 Windows 服务
您好,我正在尝试使用 mono-service2 从 Visual Studio 运行库存 Windows 服务项目。 我在 debian 上使用 mono 2.0 运行它并进行编译。
gmcs *.cs -pkg:dotnet
我尝试从此开始(我尝试将 -d 设置为应用程序的目录,并设置 -n,-m)
mono-service2 -l:service.lock --debug Program.exe
唯一的代码更改是添加用于测试
Service1.cs
using System;
using System.ServiceProcess;
namespace spikes
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
Console.WriteLine("starting...");
}
protected override void OnStop()
{
Console.WriteLine("stopping....");
}
}
}
的 写入行结果是这个错误
Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for Mono.Unix.Native.Syscall ---> System.DllNotFoundException: libMonoPosixHelper.so
at (wrapper managed-to-native) Mono.Unix.Native.Syscall:_L_ctermid ()
at Mono.Unix.Native.Syscall..cctor () [0x00000]
--- End of inner exception stack trace ---
at MonoServiceRunner.Main (System.String[] args) [0x00000]
感谢您的帮助
答案
我缺少 LD____LIBRARY____PATH env 变量,所以我将其添加到 csh 中进行测试
#!/bin/csh
setenv LD_LIBRARY_PATH .:/usr/local/lib
mono-service2 -l:service.lock --debug Program.exe
Hi I'm trying to use mono-service2 to run a stock Windows Service Project from visual studio. I'm running this on debian with mono 2.0 and compiling with.
gmcs *.cs -pkg:dotnet
I try and start with this (I've tried with -d set to the dir with the app and -n,-m set)
mono-service2 -l:service.lock --debug Program.exe
The only code change is to add writelines for testing
Service1.cs
using System;
using System.ServiceProcess;
namespace spikes
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
Console.WriteLine("starting...");
}
protected override void OnStop()
{
Console.WriteLine("stopping....");
}
}
}
The resulting is this error
Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for Mono.Unix.Native.Syscall ---> System.DllNotFoundException: libMonoPosixHelper.so
at (wrapper managed-to-native) Mono.Unix.Native.Syscall:_L_ctermid ()
at Mono.Unix.Native.Syscall..cctor () [0x00000]
--- End of inner exception stack trace ---
at MonoServiceRunner.Main (System.String[] args) [0x00000]
Thanks for your help
Answer
I was missing the LD____LIBRARY____PATH env variable, so I added it in a csh for a test
#!/bin/csh
setenv LD_LIBRARY_PATH .:/usr/local/lib
mono-service2 -l:service.lock --debug Program.exe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的 LD_LIBRARY_PATH 指向哪里? 里面有 libMonoPosixHelper.so 吗?
Where is your LD_LIBRARY_PATH pointing to? Is
libMonoPosixHelper.so
in there?确保您已安装libmono0。
Make sure you have libmono0 installed.