.net core 使用带.NET内核的systemd套接字

.net core 使用带.NET内核的systemd套接字,.net-core,systemd,.net Core,Systemd,我已经在我的Ubuntu服务器上安装了一个.NET核心应用程序,无论是手动运行还是将其设置为systemd服务,它都运行良好。但是,由于应用程序是通过nginx web服务器运行的,并且我只希望在用户访问应用程序时启动应用程序,因此我尝试使用systemd套接字对其进行设置,以便只有当套接字收到nginx的通知时,才启动相应的服务。在这种情况下,应用程序不工作,并在发生错误时给出错误。有没有办法在Linux中为.NET核心应用程序设置基于套接字的活动?我想强调的是,当同一个服务没有被套接字激活时

我已经在我的Ubuntu服务器上安装了一个.NET核心应用程序,无论是手动运行还是将其设置为systemd服务,它都运行良好。但是,由于应用程序是通过nginx web服务器运行的,并且我只希望在用户访问应用程序时启动应用程序,因此我尝试使用systemd套接字对其进行设置,以便只有当套接字收到nginx的通知时,才启动相应的服务。在这种情况下,应用程序不工作,并在发生错误时给出错误。有没有办法在Linux中为.NET核心应用程序设置基于套接字的活动?我想强调的是,当同一个服务没有被套接字激活时,它可以正常工作。下面是我收到的错误和systemd单位

Microsoft.AspNetCore.DataProtection.Repositories.EphemeralXmlRepository[50]
Using an in-memory repository. Keys will not be persisted to storage.
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[59]
Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits.
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
No XML encryptor configured. Key {1c6b8e72-67bd-4653-b656-76f9dd136ee3} may be persisted to storage in unencrypted form.


相关的谷歌搜索会在IIS中出现这个错误,但这显然与这种情况无关。谢谢


所以我的问题有点不正确。该应用程序不支持套接字激活,因此无法正常工作。相反,我提出的解决方案使用套接字代理来实现这一点,systemd socket proxyd是要使用的应用程序。这是我制作的三个systemd装置

ercot-proxy.socket
[Unit]
Description=ERCOT trade uploader proxy socket

[Socket]
ListenStream=/run/ercot-proxy.sock
SocketUser=www-data
SocketGroup=www-data

[Install]
WantedBy=sockets.target



Microsoft.AspNetCore.DataProtection
位是警告,而不是错误(他们说他们不能在Linux上进行加密,即使是对
root
,这也是意料之中的)。您看到的实际错误是什么?构建主机时是否使用
.UseSystemd()
?Hmmm.不知道这些是警告。检查了ercot.socket和ercot.service的journalctl日志,这些是唯一的异常消息。唯一的另一个错误是web浏览器返回504网关超时。可能表示套接字与服务通信不正常?或者使用nginx?以下是相关的nginx错误日志。2021/05/12 18:31:22[错误]16327#16327:*8475上游在从上游读取响应头时超时(110:连接超时),客户端:199.185.131.171,服务器:kramericaindustries.hopto.org,请求:“GET/private/ercot HTTP/1.1”,上游:,主机:“kramericaindustries.hopto.org”,参考者:“
ercot.socket
[Socket]
ListenStream=/run/ercot.sock
# Our service won't need permissions for the socket, since it
# inherits the file descriptor by socket activation
# only the nginx daemon will need access to the socket
SocketUser=www-data
SocketGroup=www-data
# Optionally restrict the socket permissions even more.
# SocketMode=600

[Install]
WantedBy=sockets.target
ercot-proxy.socket
[Unit]
Description=ERCOT trade uploader proxy socket

[Socket]
ListenStream=/run/ercot-proxy.sock
SocketUser=www-data
SocketGroup=www-data

[Install]
WantedBy=sockets.target
ercot-proxy.service
[Unit]
Description=ERCOT trade uploader proxy service

BindsTo=ercot-proxy.socket
After=ercot-proxy.socket

Wants=ercot.service

[Service]
ExecStart=/lib/systemd/systemd-socket-proxyd 127.0.0.1:42222
ercot.service
[Unit]
Description=ERCOT trade uploader daemon
BindsTo=ercot-proxy.service

[Service]
WorkingDirectory=/srv/netcore/ercot
ExecStart=/srv/netcore/ercot/DashboardWebServer