介绍
最近公司有部分服务需要部署在windows上,考虑到windows有时候会重启,做了一个开机启动,避免我每次都需要手动的去操作服务器开启。
Nginx开机启动
1.下载开机启动文件
WinSW-x64.exe文件,放在nginx.exe目录下。
2.配置启动命令
创建xml格式文件在nginx程序目录,xml名称要与WinSW-x64.exe程序名称一致,名称可以自定义。
- logpath 日志的地址
- executable 开机执行启动的命令
- stopexecutable 停止服务的命令
<service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<logpath>F:\ChangSha\nginx-1.20.0</logpath>
<logmode>roll</logmode>
<depend></depend>
<executable>F:\ChangSha\nginx-1.20.0\nginx.exe</executable>
<stopexecutable>F:\ChangSha\nginx-1.20.0\nginx.exe -s stop</stopexecutable>
</service>
3.启动服务
以上步骤完成以后,双击 WinSW-x64.exe 启动服务,可在service里查看到有一个nginx的服务。
jar开启启动
1.下载开机启动文件
同nginx
2.配置启动命令
创建xml格式文件在jar程序目录,xml名称要与WinSW-x64.exe程序名称一致,名称可以自定义。
<service>
<!--服务ID:启动、关闭、删除服务时,都是通过ID来操作的-->
<id>cardservice</id>
<!-- Display name of the service -->
<name>cardservice</name>
<description>reader card</description>
<!-- 启动程序命令,如果你没有配置环境变量要把路径也写出来 -->
<executable>java</executable>
<arguments>-jar cardservice.jar -Xms512M -Xmx512M</arguments>
<stopexecutable>taskkill /f /im javaw.exe /T</stopexecutable>
<!--
OPTION: onfailure
Defines a sequence of actions, which should be performed if the managed executable fails.
Supported actions: restart, reboot, none
-->
<onfailure action="restart" delay="10 sec"/>
<onfailure action="restart" delay="20 sec"/>
<!--
OPTION: resetfailure
Time, after which the Windows service resets the failure status.
Default value: 1 day
-->
<resetfailure>1 hour</resetfailure>
<!--
OPTION: priority
Desired process priority.
Possible values: Normal, Idle, High, RealTime, BelowNormal, AboveNormal
Default value: Normal
-->
<priority>Normal</priority>
<!--
OPTION: stoptimeout
Time to wait for the service to gracefully shutdown the executable before we forcibly kill it
Default value: 15 seconds
-->
<stoptimeout>15 sec</stoptimeout>
<!--
OPTION: stopparentprocessfirst
If set, WinSW will terminate the parent process before stopping the children.
Default value: false
-->
<stopparentprocessfirst>false</stopparentprocessfirst>
<!--
OPTION: startmode
Defines start mode of the service.
Supported modes: Automatic, Manual, Boot, System (latter ones are supported for driver services only)
Default mode: Automatic
-->
<startmode>Automatic</startmode>
<waithint>15 sec</waithint>
<sleeptime>1 sec</sleeptime>
<log mode="roll-by-size">
<sizeThreshold>10240</sizeThreshold>
<keepFiles>8</keepFiles>
</log>
</service>
启动服务
双击 WinSW-x64.exe 启动服务,可以在任务详情里查看到javaw.exe程序,就代表启动成功了。