[Mono-devel-list] Mono app x services

Vadim B. Guzev vguzev at yandex.ru
Tue Jun 8 15:54:14 EDT 2004


> Comments: nohup makes it not be killed when the console session terminates
> and "2>&1" redirects stderr to stdin what makes it completely silent (all
> output goes to the log file).
Thanks a lot! I've been looking for such command a few weeks ago and
couldn't find it. I had to use these ugly C++ daemons related things...
I've got another one question: how can I disable the output (stdin and
stderr) of the program? Should I redirect it to ">/dev/null" or how?
Is the "nohup" and "/dev/null" exist on all *nix systems?


Best regards,
Vadim B. Guzev
http://u.pereslavl.ru/~vadim/MCSharp/

>
> If needed a more sofisticated construction could follow this Java Daemon
> solution
>
> http://www.geocities.com/primacprim/helloworld2001/rpm.html
>
> Best regards,
>
> Rafael "Monoman" Teixeira
> Mono Hacker since 16 Jul 2001 - http://www.go-mono.org/
> MonoBrasil Founding Member - Membro Fundador do MonoBrasil
> http://monobrasil.softwarelivre.org
> English Blog: http://monoblog.blogspot.com/
> Brazilian Portuguese Blog: http://monoblog.weblogger.terra.com.br/
>
>
> >From: "Vadim B. Guzev" <vguzev at yandex.ru>
> >
> >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.
>
> _________________________________________________________________
> MSN Messenger: instale grАtis e converse com seus amigos.
> http://messenger.msn.com.br
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>




More information about the Mono-devel-list mailing list