使用Upstart在启动时运行Mono应用程序

时间:2013-10-03 15:49:59

标签: c# winforms ubuntu mono upstart

我需要在Ubuntu启动时运行一个c#Windows窗体应用程序(Mono应用程序),然后我尝试使用Upstart。我手动运行此应用程序,但是当我使用Upstart脚本时,如下所示:

description "Indsys Andon"

start on runlevel [2345]
stop on runlevel [016]

setuid nobody
setgid nogroup
respawn
console log

script
     /usr/bin/mono /usr/lib/IndsysAndon/IndsysAndon.exe "$@"
end script
在Indsys.exe.log中

出现错误消息:

A Unhanled Exception : System.TypeInitializationException: An exception was throw
Parameter name: Display
...

当我将脚本用作How do I add my mono Program to the startup?时,在Indsys.exe.log中,错误消息是:

run-detectors: unable to find an interpreter for /usr/lib/IndsysAndon/IndsysAndon.exe

我不知道权利,但我认为我的需要很简单。使用Upstart真的有必要吗?我也尝试过rc.local但未成功,插入:

 /usr/bin/mono /usr/lib/IndsysAndon/IndsysAndon.exe

请有人帮助我。谢谢,

3 个答案:

答案 0 :(得分:1)

我认为单声道上的WinForms应用程序需要运行有效的Xserver和有效的DISPLAY环境变量。它应该从X会话运行或将输出重定向到有效的(它可以在另一台机器上)。

要验证,请尝试在控制台上运行您的应用,前面是“DISPLAY =''”。

尝试使用空的DISPLAY变量启动keepass(winforms应用程序)时出现同样的错误。

$ DISPLAY= /usr/bin/mono /usr/share/keepass/KeePass.exe

Unhandled Exception:
System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.XplatUI ---> System.ArgumentNullException: Could not open display (X-Server required. Check you DISPLAY environment variable)
Parameter name: Display
  at System.Windows.Forms.XplatUIX11.SetDisplay (IntPtr display_handle) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUIX11..ctor () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUIX11.GetInstance () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUI..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Windows.Forms.Application.EnableVisualStyles () [0x00000] in <filename unknown>:0 
  at KeePass.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.XplatUI ---> System.ArgumentNullException: Could not open display (X-Server required. Check you DISPLAY environment variable)
Parameter name: Display
  at System.Windows.Forms.XplatUIX11.SetDisplay (IntPtr display_handle) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUIX11..ctor () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUIX11.GetInstance () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUI..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Windows.Forms.Application.EnableVisualStyles () [0x00000] in <filename unknown>:0 
  at KeePass.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0

也许您可以设置虚拟X服务器,这个问题可以帮助您:What dummy X server should I use with openoffice on debian?

答案 1 :(得分:0)

您可以尝试制作一个脚本来调用您的应用程序,例如

  #!/bin/sh
  exec /usr/bin/mono PREFIX/lib/APPLICATION/app.exe "$@"

然后从upstart调用该脚本?我做完这个已经有很长一段时间了,但我似乎记得做过那样的事......

这可能也有帮助:Application Deployment

答案 2 :(得分:0)

朋友们,我用另一种方法解决了这个问题。具体情况如下: Run Mono App on startup in Ubuntu with "startup applications"

非常感谢您的关注!