Linux:如何使用xinetd可以使用守护进程/服务?

时间:2021-10-18 23:55:17

Anybody knows what changes are necessary for a server to work with xinetd ?

有人知道服务器使用xinetd需要做哪些更改?

The server being a .NET mailserver that runs on Linux.

服务器是在Linux上运行的.NET邮件服务器。

See the bottom of this post for reference: Lumisoft Mailserver Forum Post

请参阅此文章的底部以供参考:Lumisoft Mailserver Forum Post

Note: xinetd, not mono-service. [x]inetd is an internet superserver.
A superserver starts a server service on demand.
(As opposed to the server service running continuously, which is what mono-service does)

注意:xinetd,而不是单一服务。 [x] inetd是一个互联网超级服务器。超级服务器按需启动服务器服务。 (与连续运行的服务器服务相反,这是单服务所做的)

2 个解决方案

#1


7  

An inetd service runs differently from a standalone server. inetd services read stdin and write to stdout, letting inetd handle the gory details of TCP/IP, rather than keeping track of their own sockets. If you want to make a server run under inetd, it'll have to do the same.

inetd服务的运行方式与独立服务器不同。 inetd服务读取stdin并写入stdout,让inetd处理TCP / IP的血腥细节,而不是跟踪自己的套接字。如果你想让服务器在inetd下运行,它必须做同样的事情。

The following program runs just fine under xinetd on my machine:

以下程序在我的机器上的xinetd下运行正常:

#include <iostream>
#include <string>

using namespace std;  // yeah, i'm lazy.

int main()
{
    string name;
    cout << "What's your name? " << flush;
    cin >> name;
    cout << "Hi, " << name << "!" << endl;
}

Note i'm not at all worried about sockets -- xinetd arranges things so that the service can read standard input and write to standard output. You just write your app like you'd be running it on the console, for the most part. The socket details are specified in the config file for the service. (Note, you might be able to get/set details about the socket using stdin/stdout, which may be the actual socket -- i'm not sure -- but you really should leave that stuff up to inetd.)

注意我并不担心套接字--xinetd会安排一些事情,以便服务可以读取标准输入并写入标准输出。您只需编写您的应用程序就像在控制台上运行它一样。套接字详细信息在服务的配置文件中指定。 (注意,您可能能够使用stdin / stdout来获取/设置有关套接字的详细信息,这可能是实际的套接字 - 我不确定 - 但是您真的应该将这些内容留给inetd。)

#2


1  

An inetd services are really great for one off apps that need to take in data and act with some degree of interaction with the user. IT works over tcp/udp by piping the data viva a socket from (x)inetd to std{in,out,err}. inetd apps also works well with tcpwrappers to inhance security though system policy files and ACL.

对于需要接收数据并与用户进行某种程度的交互的应用程序,inetd服务非常适合。 IT通过将数据viva从(x)inetd传递给std {in,out,err}来管理tcp / udp。 inetd应用程序也适用于tcpwrappers,以通过系统策略文件和ACL增强安全性。

So yes you would write your app like its a console app since in reality it is a console app. Just think of inetd as a transparent reverse proxy from the network to your app's inputs.

所以是的,你会把你的应用程序写成一个控制台应用程序,因为实际上它是一个控制台应用程序只需将inetd视为从网络到应用程序输入的透明反向代理。

A Word of advice, write your code to handle the process signals correctly and if you need to interact with another process on the system use unix sockets/fifo for that.

建议,编写代码以正确处理过程信号,如果需要与系统上的另一个进程交互,请使用unix套接字/ fifo。

Also, don't try to write an app that streams a lot of data all at once or needs a lot of connections. Scalability is an issue as inetd becomes a bottle neck, this is why Apache and Sendmail dropped support for inetd and sit as mono apps instead. HTTP fits this role better and a fastcgi (or insert favorite framework) script with nginx works best for that use case.

此外,不要尝试编写一个可以同时传输大量数据或需要大量连接的应用程序。可扩展性是一个问题,因为inetd成为瓶颈,这就是为什么Apache和Sendmail放弃了对inetd的支持并将其作为单声道应用程序。 HTTP更适合这个角色,使用nginx的fastcgi(或插入喜欢的框架)脚本最适合该用例。

A good example for an inetd would be:

inetd的一个很好的例子是:

lock = Mutex.new

trap :HUP  { #log the connection and cleanup }
trap :USR1 { lock.synchronize do #stuff; end }
trap :TERM { #clean up }
trap :KILL { #clean up and die with error codes }

puts "App name - version"

loop do
  ('%s> ' % Console.prompt).display
  input = gets.chomp
  command, *params = input.split /\s/
  case command
    when /\Ahelp\z/i
      puts App.help_text
    when /\Ado\z/i
      Action.perform *params
    when /\Aquit\z/i
      exit
    else
      puts 'Invalid command'
  end
end
exit

Edit your /etc/services to include your app like this: myapp port#/proto

编辑您的/ etc / services以包含您的应用程序,如下所示:myapp port#/ proto

and add your app to /etc/inetd.conf (or xinetd.d) like this: myapp stream tcp6 nowait myappuser /path/to/myapp myapp -arg_flags

并将您的应用程序添加到/etc/inetd.conf(或xinetd.d),如下所示:myapp stream tcp6 nowait myappuser / path / to / myapp myapp -arg_flags

#1


7  

An inetd service runs differently from a standalone server. inetd services read stdin and write to stdout, letting inetd handle the gory details of TCP/IP, rather than keeping track of their own sockets. If you want to make a server run under inetd, it'll have to do the same.

inetd服务的运行方式与独立服务器不同。 inetd服务读取stdin并写入stdout,让inetd处理TCP / IP的血腥细节,而不是跟踪自己的套接字。如果你想让服务器在inetd下运行,它必须做同样的事情。

The following program runs just fine under xinetd on my machine:

以下程序在我的机器上的xinetd下运行正常:

#include <iostream>
#include <string>

using namespace std;  // yeah, i'm lazy.

int main()
{
    string name;
    cout << "What's your name? " << flush;
    cin >> name;
    cout << "Hi, " << name << "!" << endl;
}

Note i'm not at all worried about sockets -- xinetd arranges things so that the service can read standard input and write to standard output. You just write your app like you'd be running it on the console, for the most part. The socket details are specified in the config file for the service. (Note, you might be able to get/set details about the socket using stdin/stdout, which may be the actual socket -- i'm not sure -- but you really should leave that stuff up to inetd.)

注意我并不担心套接字--xinetd会安排一些事情,以便服务可以读取标准输入并写入标准输出。您只需编写您的应用程序就像在控制台上运行它一样。套接字详细信息在服务的配置文件中指定。 (注意,您可能能够使用stdin / stdout来获取/设置有关套接字的详细信息,这可能是实际的套接字 - 我不确定 - 但是您真的应该将这些内容留给inetd。)

#2


1  

An inetd services are really great for one off apps that need to take in data and act with some degree of interaction with the user. IT works over tcp/udp by piping the data viva a socket from (x)inetd to std{in,out,err}. inetd apps also works well with tcpwrappers to inhance security though system policy files and ACL.

对于需要接收数据并与用户进行某种程度的交互的应用程序,inetd服务非常适合。 IT通过将数据viva从(x)inetd传递给std {in,out,err}来管理tcp / udp。 inetd应用程序也适用于tcpwrappers,以通过系统策略文件和ACL增强安全性。

So yes you would write your app like its a console app since in reality it is a console app. Just think of inetd as a transparent reverse proxy from the network to your app's inputs.

所以是的,你会把你的应用程序写成一个控制台应用程序,因为实际上它是一个控制台应用程序只需将inetd视为从网络到应用程序输入的透明反向代理。

A Word of advice, write your code to handle the process signals correctly and if you need to interact with another process on the system use unix sockets/fifo for that.

建议,编写代码以正确处理过程信号,如果需要与系统上的另一个进程交互,请使用unix套接字/ fifo。

Also, don't try to write an app that streams a lot of data all at once or needs a lot of connections. Scalability is an issue as inetd becomes a bottle neck, this is why Apache and Sendmail dropped support for inetd and sit as mono apps instead. HTTP fits this role better and a fastcgi (or insert favorite framework) script with nginx works best for that use case.

此外,不要尝试编写一个可以同时传输大量数据或需要大量连接的应用程序。可扩展性是一个问题,因为inetd成为瓶颈,这就是为什么Apache和Sendmail放弃了对inetd的支持并将其作为单声道应用程序。 HTTP更适合这个角色,使用nginx的fastcgi(或插入喜欢的框架)脚本最适合该用例。

A good example for an inetd would be:

inetd的一个很好的例子是:

lock = Mutex.new

trap :HUP  { #log the connection and cleanup }
trap :USR1 { lock.synchronize do #stuff; end }
trap :TERM { #clean up }
trap :KILL { #clean up and die with error codes }

puts "App name - version"

loop do
  ('%s> ' % Console.prompt).display
  input = gets.chomp
  command, *params = input.split /\s/
  case command
    when /\Ahelp\z/i
      puts App.help_text
    when /\Ado\z/i
      Action.perform *params
    when /\Aquit\z/i
      exit
    else
      puts 'Invalid command'
  end
end
exit

Edit your /etc/services to include your app like this: myapp port#/proto

编辑您的/ etc / services以包含您的应用程序,如下所示:myapp port#/ proto

and add your app to /etc/inetd.conf (or xinetd.d) like this: myapp stream tcp6 nowait myappuser /path/to/myapp myapp -arg_flags

并将您的应用程序添加到/etc/inetd.conf(或xinetd.d),如下所示:myapp stream tcp6 nowait myappuser / path / to / myapp myapp -arg_flags