Automatically starting C# Mono application on Ubuntu server
Me too was having this problem. I am now able to run my mono c# app on start up with the help of: http://www.stuffaboutcode.com/2012/06/raspberry-pi-run-program-at-start-up.html
In the "start" section of file (as specified in the above link), do the following: 1. change directory to the folder of your c# app: cd /home/pi/myApp 2. in the next line, add full path of "mono" AND full path of your c# app. For example: /usr/bin/mono /home/pi/myApp/myApp.exe
in the "stop" section, I am not sure how to stop the exact "myApp.exe"; but i stopped the "mono" by giving command:
killall mono
(in effect, the myApp.exe... but if you are running more than one c# apps..please test it.)
Notes
- make sure your c# app don't asks for user input...otherwise it will hang
- Don't forget to run sudo update-rc.d NameOfYourScript defaults :)
- test the script by running "start" and "stop" commands (as specified in the above given link) before you restart your machine.
- ALL comment lines in the script is a must. Otherwise you won't be able add it to start up list.
All the best! :)
Related videos on Youtube
Kieran Crown
Updated on September 18, 2022Comments
-
Kieran Crown over 1 year
I have a TCP server written in C# which I will run on my server. I've tested the application running on the server and client side and it all works great! I'm using mono on my Linux server to run the Server.exe application. I've been experimenting with both Upstart and Shell scripts to get the Server.exe application to run in the background at start up. None of these have worked.
Here is the Shell Script I tried:
#!/bin/sh
/usr/bin/mono Server.exe "$@" &
I then edited the rc.local file found in the /etc directory and added this line:
/usr/local/bin/ClipCloud/start.sh &
Am I missing something here as I can't seem to get it working. It seems to start and then terminate the process straight away. When I start the Server.exe application from terminal by just typing
mono /usr/local/bin/ClipCloud/Server.exe
it works fine and will continue to run until I close the terminal window or type "exit"
I will be happy to share anything I can to help.
-
krisFR about 10 yearsWhat about
nohup /full/path/to/mono /full/path/to/server.exe &
? From now i cannot understand why you use "$@" in your script and not from the terminal -
Kieran Crown about 10 yearsI did try this with no luck... Any other ideas?
-
knocte about 10 yearsin the same way you try to run manually
mono /usr/local/bin/ClipCloud/Server.exe
and it works, have you tried running your shell script manually too? -
Kieran Crown about 10 yearsYes I've tried running the script manually and nothing seems to happen. I still can't connect from my clients.
-