Friends, I solved this demand with another method. Follows: Run Mono App on startup in Ubuntu with "startup applications"
Thank you very much for attention!
Question
I need run a c# Windows Forms application (Mono app) on Ubuntu startup, then I trying use Upstart. I run this application fine manually, but when I use the Upstart script, as follow:
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
in Indsys.exe.log the error message appears:
A Unhanled Exception : System.TypeInitializationException: An exception was throw
Parameter name: Display
...
When I use the script as How do I add my mono Program to the startup? , so, in Indsys.exe.log the error messages is:
run-detectors: unable to find an interpreter for /usr/lib/IndsysAndon/IndsysAndon.exe
I don't know rights, but i think that my need is very simple. It's really necessary to use Upstart? I also tried unsuccessfully by rc.local, inserting:
/usr/bin/mono /usr/lib/IndsysAndon/IndsysAndon.exe
Somebody help me, please. Thanks,
Solution 3
Friends, I solved this demand with another method. Follows: Run Mono App on startup in Ubuntu with "startup applications"
Thank you very much for attention!
OTHER TIPS
I think WinForms applications on mono need a valid Xserver running and a valid DISPLAY environment variable. It should be run from a X session or redirect the output to a valid one (it can be on another machine).
To verify, try running your app from a console prepending "DISPLAY='' ".
I get the same error trying to launch keepass (a winforms app) with an empty DISPLAY variable.
$ 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
Maybe you could setup a dummy X server, this question may help you: What dummy X server should I use with openoffice on debian?
Can you try making a script to call your application, e.g.
#!/bin/sh
exec /usr/bin/mono PREFIX/lib/APPLICATION/app.exe "$@"
Then invoking that script from upstart? It's a long time since I've done this, but I seem to remember doing something like that...
This may also be of help: Application Deployment