[OBORONA-SPAM] [Mono-devel-list] Mono app x services

Vadim B. Guzev vguzev at yandex.ru
Tue Jun 8 14:08:57 EDT 2004


It seems to me that such tasks can be implemented only with the help of C++.

For example, you can start mono as a daemon and pass some parameters (.exe filename and so on) like this:
8<------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/param.h>
#include <iostream.h>
#include <stdlib.h>
#include <string.h>

int main( int argc, char** argv ) {
 const char* mcsharppath = getenv( "MCSHARPPATH" );
 if ( mcsharppath == NULL || strlen( mcsharppath ) == 0 ) {
  cout << "Error RMS1! MCSHARPPATH variable wasn't set!" << endl;
  return 1;
 }

 int len = strlen( mcsharppath ) + 16;
 char* path = new char [len];
 memset( path, 0, len );
 strncat( path, mcsharppath, strlen( mcsharppath ) );
 strncat( path, "/bin/resman.exe\0", 16 );

 FILE* ptr;
 char filename[1024];

 if ( (ptr = popen("which mono", "r")) != NULL ) {
  if ( fgets( filename, 1024, ptr ) == NULL ) {
   cout << "Error RMS2! No \"mono\" was found on this system!" << endl;
   cout << " You should probably make sure that Mono wass properly installed on your system!" << endl;
   cout << " Also, check you should check your $PATH environment variable and " << endl;
   cout << " make sure that \"mono\" interpreter is located in one of the specified directories." << endl;
   return 2;
  }
 }
 pclose( ptr );
 pid_t  pid;

 int i;

 for ( int i = 0; i < NOFILE; i++ )
  close( i );

 pid = fork();

 if ( pid < 0 )
  printf ( "Error RMS3! Fork returned error...\n" );
 else if ( pid > 0 )  {
  exit( 0 );
 }
 else {
  setsid();

  char* buf = new char [strlen( filename ) - 1];
  strncpy( buf, filename, strlen( filename ) - 1 );

  execl( buf, "mono",
            (const char*) path, argv [1],
            (char *)0 );
  perror( "Error RMS4! Execl failed in the rm_starter child...\n" );
  exit( 1 );
 }
}

8<------------------------------------------------------------------------------------------------------

I couldn't find any way how to implement such things in pure C#. Is it possible at all?


Best regards,
Vadim B. Guzev
http://u.pereslavl.ru/~vadim/MCSharp/ 
  ----- Original Message ----- 
  From: Pekus Cons. e Desenvolvimento 
  To: mono-devel-list at lists.ximian.com 
  Sent: Tuesday, June 08, 2004 9:45 PM
  Subject: [OBORONA-SPAM] [Mono-devel-list] Mono app x services


  Hi,

  Did anyone try to use a mono app like a linux service (i.e.: load the app like a daemon)? In affirmative case, could you please give an orientation?

  Regards,

  Baccarin.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20040608/c5fdf422/attachment.html 


More information about the Mono-devel-list mailing list