开发者

Windows service porting to linux

开发者 https://www.devze.com 2022-12-28 04:34 出处:网络
I am porting an application which runs as a background service in windows at startup, we are porting the application to linux(SUSE Enterprise server), I\'am completely new to linux. Can somebody help

I am porting an application which runs as a background service in windows at startup, we are porting the application to linux(SUSE Enterprise server), I'am completely new to linux. Can somebody help me on how to proceed with this. Like

  1. Should I build the linux executable
  2. After builiding the binary开发者_开发知识库, what changes should I make to linux startup files to run this executable
  3. How my service can register call back function to modify or change or send commands to my service while it is running


  1. Yes, you should build a Linux binary. You may want to rephrase your question since I doubt this is the answer you want :-)
  2. You should generally create what is known as an "init" file, which lives in /etc/init.d. Novell has a guide online which you can use to author the file. Note that while the init file is common, the exact method of letting the operating system use it varies depending on the distribution.
  3. This is going to be a marked change for you. If you are doing simple actions such as re-loading a configuration file, you can use the signals functionality, especially the SIGHUP/HUP signal which is generally used for this purpose. If you require extended communication with your daemon, you can use a UNIX domain socket (think of it as a named pipe) or a network socket.

Another task you are going to need to accomplish is to daemonize your application. Generally this is done by first fork()ing your process, then redirecting the stdin/stdout pipes in the child. There are more details which can be answered by reading this document


See how-to-migrate-a-net-windows-service-application-to-linux-using-mono.

Under Linux, deamons are simple background processes. No special control methods (e.g start(), stop()) are used as in Windows. Build your service as a simple (console) application, and run it in the background. You can use a tool like daemonize to run a program as a Unix daemon.

0

精彩评论

暂无评论...
验证码 换一张
取 消