Centos – Running mono-based application on Centos Start

centoscentos6monoservicestartup

I am very new to Linux and I am currently switching my server from Windows to Centos 6.3.
I have written a small UDP server. UDP server was written in C# and now I adopted it to work with Linux using Mono. It is working fine, when I run it this way:

/opt/mono/bin/mono /root/MySoft/UDPServer.exe "$@"

How do I run it automatically–when computer stats? (in windows terms: windows-service)

I tried creating a launcher file and putting it to /etc/init.d but it did not work

Best Answer

My goto solution for things like this is to install and use supervisord.

Supervisord is a python process supervisor that is very simple to install from your distro's package repo, and simple to configure. You just add a simple config file for your executable and supervisor takes care of starting it up, capturing output, and (optionally) re-starting it if the process fails.

An example config would look like this:

[program:udp_server]
user = <username>
command = /opt/mono/bin/mono /root/MySoft/UDPServer.exe "$@"
stdout_logfile = /var/log/udp_server-stdout.log
stdout_logfile_maxbytes = 10MB
stdout_logfile_backups = 5
stderr_logfile = /var/log/udp_server-stderr.log
stderr_logfile_maxbytes = 10MB
stderr_logfile_backups = 5
Related Topic