gocron+winsw搭配使服务于后台运行,轻松搞定定时任务管理
gocron是一款go语言写的任务管理系统,可以用于Linux、Mac OS、Windows上,安装好golang环境就可以用命令的形式运行,以Windows系统为例:
执行命令:cmd>cd gocron目录>gocron.exe web
而使用过程中发现通过命令提示符的形式运行不太友好,于是想把服务改成后台服务模式,找遍各大网站都没有很好的解决方案,于是咨询了gocron的开发者,他推荐使用winsw进行服务的安装。但是winsw使用教程和经验案例网上也很少,于是自己摸索,根据开发者提供的配置模板,各种折腾后,最终使用以下配置完美搞定后台服务。
根据winsw的使用规则。程序和配置文件名称要一致,于是
重命名winsw程序为:gocron-service.exe
配置文件为:gocron-service.xml
配置如下:
<configuration> <!-- ID of the service. It should be unique accross the Windows system--> <id>gocron-service</id> <!-- Display name of the service --> <name>gocron-service(powered by WinSW)</name> <!-- Service description --> <description>This service is a service cratead from a minimal configuration</description> <!-- Path to the executable, which should be started --> <executable>D:\gocron\gocron.exe " web"</executable> </configuration>
通过命令进行安装:cmd>cd winsw目录(推荐跟gocron为同一个目录)>gocron-service.exe install
服务卸载命令为:gocron-service.exe uninstall
