[英]Can't start topshelf service locally: The service did not respond in a timely fashion
I am having difficulties to start my service using the following setup.我无法使用以下设置启动我的服务。
static void Main(string[] args)
{
var builder = new ContainerBuilder();
builder.RegisterModule<FixAcceptorModule>();
var container = builder.Build();
var rc = HostFactory.Run(c =>
{
c.UseAutofacContainer(container);
c.Service<IServiceManager>(svc =>
{
svc.ConstructUsingAutofacContainer();
svc.WhenStarted(sm => sm.Start()).BeforeStartingService(a => a.RequestAdditionalTime(TimeSpan.FromSeconds(30)));
svc.WhenStopped(sm => sm.Stop());
});
c.SetDescription("");
c.SetDisplayName("FIX Acceptor Service");
c.SetServiceName("FixAcceptorSvc");
c.RunAsLocalService();
c.StartManually();
});
}
This is the output of the start action myservice.exe start
:这是启动动作myservice.exe start
的 output :
Topshelf.Hosts.StartHost Error: 0 : The service failed to start., System.InvalidOperationException: Cannot start service FixAcceptorSvc on computer '.'. ---> System.ComponentModel.Win32Exception: The service did not respond to the start or control request in a timely fashion
--- End of inner exception stack trace ---
at System.ServiceProcess.ServiceController.Start(String[] args)
at System.ServiceProcess.ServiceController.Start()
at Topshelf.Runtime.Windows.WindowsHostEnvironment.StartService(String serviceName, TimeSpan startTimeOut)
at Topshelf.Hosts.StartHost.Run()
Although the exception points to a timeout I don't think this is related to a timing issue, as this exception get's thrown immediately.尽管异常指向超时,但我认为这与时间问题无关,因为此异常会立即抛出。 I guess it's more like a permission or configuration issue.我想这更像是权限或配置问题。
Things to note:注意事项:
Windows 10 Pro - 1909
我的开发人员机器是加入域并运行Windows 10 Pro - 1909
myservice.exe install --localservice
(and c.RunAsLocalSystem()
in HostFactory
) => same result myservice.exe install --localservice
(和c.RunAsLocalSystem()
在HostFactory
)=>相同的结果myservice.exe install --localsystem
(and c.RunAsLocalSystem()
in HostFactory
) => same result myservice.exe install --localsystem
(和 HostFactory 中的HostFactory
c.RunAsLocalSystem()
)=>相同的结果myservice.exe install -username myaduser -password myadpassword
did not help (double checked group policies and that my user is allowed to logon as a service)也使用myservice.exe install -username myaduser -password myadpassword
没有帮助(仔细检查组策略并且我的用户被允许作为服务登录)So what am I doing wrong here?那么我在这里做错了什么?
The mentioned exception is totally misleading.提到的例外完全是误导性的。 I found the culprit.我找到了罪魁祸首。 To get more details I've added the following action:要获取更多详细信息,我添加了以下操作:
c.OnException(ex =>
{
File.AppendAllText(@"C:\Temp\Service.txt", ex.ToString());
});
Now this finally got me on the track.现在这终于让我走上了正轨。 As the exception shows there is something wrong with my service, which is looking in the wrong folder ( C:\Windows\System32
) for the FIX dictionary... Problem solved!由于异常显示我的服务有问题,它正在查找错误的文件夹( C:\Windows\System32
),用于 FIX 字典......问题已解决!
Topshelf.ServiceBuilderException: An exception occurred creating the service: IServiceManager ---> Autofac.Core.DependencyResolutionException: An exception was thrown while activating StrukiApp.FixAcceptor.Infrastructure.ServiceManager -> StrukiApp.FixAcceptor.Acceptor. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(QuickFix.IApplication, QuickFix.IMessageStoreFactory, QuickFix.SessionSettings, QuickFix.ILogFactory)' on type 'Acceptor'. ---> QuickFix.ConfigError: Configuration failed: Could not find file 'C:\WINDOWS\system32\FIX44.xml'. ---> System.IO.FileNotFoundException: Could not find file 'C:\WINDOWS\system32\FIX44.xml'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at QuickFix.SessionFactory.createDataDictionary(SessionID sessionID, Dictionary settings, String settingsKey, String beginString)
at QuickFix.SessionFactory.ProcessFixDataDictionary(SessionID sessionID, Dictionary settings, DataDictionaryProvider provider)
at QuickFix.SessionFactory.Create(SessionID sessionID, Dictionary settings)
at QuickFix.ThreadedSocketAcceptor.CreateSession(SessionID sessionID, Dictionary dict)
at QuickFix.ThreadedSocketAcceptor.CreateSessions(SessionSettings settings, SessionFactory sessionFactory)
at QuickFix.ThreadedSocketAcceptor..ctor(SessionFactory sessionFactory, SessionSettings settings)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.