首页 文章

使用mono-service在Linux上包装Windows服务

提问于
浏览
13

嗨,我正在尝试使用mono-service2从visual studio运行一个股票Windows服务项目 . 我正在使用mono 2.0和编译器在debian上运行它 .

gmcs *.cs -pkg:dotnet

我尝试从这开始(我尝试使用-d设置为dir与app和-n,-m设置)

mono-service2 -l:service.lock --debug Program.exe

唯一的代码更改是添加用于测试的writelines

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]

谢谢你的帮助

Answer

我错过了LD____LIBRARY____PATH env变量,因此我将其添加到csh中进行测试

#!/bin/csh
setenv LD_LIBRARY_PATH .:/usr/local/lib
mono-service2 -l:service.lock --debug Program.exe

2 回答

  • 9

    你的LD_LIBRARY_PATH指向哪里?那里是 libMonoPosixHelper.so 吗?

  • 0

    确保安装了libmono0 .

相关问题