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

发布于 2024-09-15 02:53:53 字数 347 浏览 9 评论 0原文

有人知道服务器要与 xinetd 一起工作需要进行哪些更改吗?

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

请参阅本文底部以供参考: Lumisoft 邮件服务器论坛帖子

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

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

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

See the bottom of this post for reference:
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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

韶华倾负 2024-09-22 02:53:54

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

以下程序在我的机器上的 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;
}

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

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.

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

#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.)

数理化全能战士 2024-09-22 02:53:54

inetd 服务对于需要接收数据并与用户进行某种程度交互的一次性应用程序来说确实非常有用。它通过 tcp/udp 工作,通过套接字将数据从 (x)inetd 传输到 std{in,out,err}。 inetd 应用程序还可以与 tcpwrappers 很好地配合,通过系统策略文件和 ACL 增强安全性。

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

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

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

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

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

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

至于 xinetd,每个配置都有自己的类似 C 的语法,并且根据发行版可以存在于 /etc/xinetd.conf 或 <代码>/etc/xinetd.d/myapp.conf。建议阅读手册页: https://linux.die.net/ man/5/xinetd.conf

一个示例配置 in-cpio.conf 看起来像这样:

service ftp 
{ 
  socket_type        = stream 
  wait               = no 
  user               = nobody
  server             = /usr/bin/cpio
  server_args        = -idv
  instances          = 1 
  nice               = 10
  only_from          = 127.0.0.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.

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.

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.

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.

A good example for an inetd would be:

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

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

As for xinetd this has its own c like syntax for each config and depending on the distro could live in /etc/xinetd.conf or /etc/xinetd.d/myapp.conf. Would suggest one to read up on the manpage: https://linux.die.net/man/5/xinetd.conf

An example config say in-cpio.conf would look something like:

service ftp 
{ 
  socket_type        = stream 
  wait               = no 
  user               = nobody
  server             = /usr/bin/cpio
  server_args        = -idv
  instances          = 1 
  nice               = 10
  only_from          = 127.0.0.1
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文