简体   繁体   English

Windows Task Scheduler运行X天后将停止任务

[英]Windows Task Scheduler stops tasks when it's been running for X days

I am creating a scheduled task from command line: 我正在从命令行创建计划任务:

schtasks /Create /SC ONSTART /TN "Zookeeper server" /TR D:\Zookeeper\zookeeper-3.4.6\bin\zkServer.cmd /RU System /V1 /f

The issue is that the "Stop task if running for X days" options is always checked. 问题是始终选中“如果运行X天则停止任务”选项。 I tried unchecking it, but it always comes back on right away. 我尝试取消选中它,但它总是立即恢复。 Since it's a server, I want it to be able to run for more than 3 days. 由于它是服务器,因此我希望它能够运行3天以上。

I saw a solution where you had to export the xml of the task, change the value manually (ExecutionTimeLimit), delete the task and create it from the xml template, but that doesn't work either. 我看到了一个解决方案,其中您必须导出任务的xml,手动更改值(ExecutionTimeLimit),删除任务并从xml模板创建它,但这也不起作用。

I also thought that it was a mandatory option for a ONSTART trigger, so I tried to replace it with a one time only trigger, the same thing happens. 我还认为这是ONSTART触发器的强制性选项,因此我尝试将其替换为一次性触发器,发生同样的事情。

Is there a way to make sure my app is run on startup (without a user logged in)? 有没有办法确保我的应用在启动时运行(没有用户登录)? Still allowing the user to stop and start it as he pleases. 仍然允许用户根据需要停止和启动它。

I know about services, but I heard it was kind of hard to make a service from an app with java. 我了解服务,但听说使用Java从应用程序提供服务有点困难。

EDIT : I would prefer to fix that issue, but if that's not possible, a way to install Zookeeper Server as a service. 编辑 :我更愿意解决该问题,但是,如果那不可能,一种将Zookeeper Server作为服务安装的方法。 I tried with nssm 2.23, but there is no way to install a service silently (it must be done without user interface). 我尝试使用nssm 2.23,但是没有办法静默安装服务(必须在没有用户界面的情况下完成)。

Why don't you run that command as a service rather than in the task scheduler? 为什么不将命令作为服务而不是在任务计划程序中运行? Task scheduler, as the name implies is to schedule tasks, not running them forever. 顾名思义,任务计划程序用于计划任务,而不是永远运行它们。

You can run the command as a service when the server starts and give the user the control if they want to stop it. 您可以在服务器启动时将命令作为服务运行,并向用户提供控制权(如果他们想停止它)。 There's more information about how to make it a service in this other question: Run batch file as a Windows service 在另一个问题中,有更多有关如何使其成为服务的信息: 作为Windows服务运行批处理文件

I found a nice Windows service wrapper that allows me to install and manage a service all in command line. 我找到了一个不错的Windows服务包装程序,该程序包装程序允许我在命令行中全部安装和管理服务。 It works great with the Zookeeper server from what I tested today. 从我今天测试的结果来看,它与Zookeeper服务器配合使用效果很好。

https://github.com/kohsuke/winsw/ https://github.com/kohsuke/winsw/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM