springboot jar包做成系统服务(windows版本)v2

在使用了winsw之后,遇到了几个问题:

  • 在windows xp和windows server 2008或windows server 2012安装的时候,有时候报错,使用了WinSW.NET4.exe解决了这个问题
  • 开始一段时间没问题,后来查看日志发现不断地重启服务,但是后台程序已经运行了,一直在提示端口占用
2021-04-21 23:17:28,595 INFO - Starting jre\bin\java -Xms256m -Xmx512m -jar monitor-web.jar
2021-04-21 23:17:28,674 INFO - Started process 10024
2021-04-21 23:17:28,677 DEBUG - Forwarding logs of the process System.Diagnostics.Process (java) to WinSW.RollingSizeTimeLogAppender
2021-04-21 23:17:47,231 DEBUG - Starting WinSW in service mode
2021-04-21 23:17:47,310 INFO - Starting jre\bin\java -Xms256m -Xmx512m -jar monitor-web.jar
2021-04-21 23:17:47,386 INFO - Started process 5268
2021-04-21 23:17:47,389 DEBUG - Forwarding logs of the process System.Diagnostics.Process (java) to WinSW.RollingSizeTimeLogAppender
2021-04-21 23:18:05,787 DEBUG - Starting WinSW in service mode
2021-04-21 23:18:05,866 INFO - Starting jre\bin\java -Xms256m -Xmx512m -jar monitor-web.jar
2021-04-21 23:18:05,945 INFO - Started process 6680
2021-04-21 23:18:05,949 DEBUG - Forwarding logs of the process System.Diagnostics.Process (java) to WinSW.RollingSizeTimeLogAppender
2021-04-21 23:18:24,621 DEBUG - Starting WinSW in service mode
2021-04-21 23:18:24,700 INFO - Starting jre\bin\java -Xms256m -Xmx512m -jar monitor-web.jar
2021-04-21 23:18:24,779 INFO - Started process 3640

使用的配置:


    cloudMonitor
    cloudMonitor
    云监控服务
    
    
    jre\bin\java
    -Xms256m -Xmx512m -jar monitor-web.jar
    
    Automatic
    
    %BASE%\log
    
    
        10240
        yyyyMMdd
        00:00:00
    
    
    true
    
    

    没办法,最后看到别的项目用到了nssm这个东西,网上看了下资料得知,这个也是做服务的一种。活不多说开始搞:
1.在inno setup的脚本里修改配置

[Run]
Filename: "{app}\nssm.exe"; Description: "安装服务";Parameters:"install cloudMonitor {app}\jre\bin\java -Xms256m -Xmx512m -jar {app}\monitor-web.jar";Flags: runhidden skipifdoesntexist
Filename: "{app}\nssm.exe"; Description: "描述服务";Parameters:"set cloudMonitor Description 云监控服务";Flags: runhidden skipifdoesntexist
Filename: "{app}\nssm.exe"; Description: "设置工作空间";Parameters:"set cloudMonitor AppDirectory {app}";Flags: runhidden skipifdoesntexist
Filename: "{app}\nssm.exe"; Description: "设置启动方式";Parameters:"set cloudMonitor Start SERVICE_DELAYED_AUTO_START";Flags: runhidden skipifdoesntexist
Filename: "{app}\nssm.exe"; Description: "启动服务";Parameters:"start cloudMonitor";Flags: runhidden skipifdoesntexist

[UninstallRun]
Filename: "{app}\nssm.exe";Parameters:"stop cloudMonitor";Flags: runhidden skipifdoesntexist
Filename: "{app}\nssm.exe";Parameters:"remove cloudMonitor confirm";Flags: runhidden skipifdoesntexist

2.安装卸载测试没啥问题,但是生成的日志文件还残留
增加脚本

[Code]
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
    if CurUninstallStep = usDone then
      if MsgBox('您是否要删除用户配置和日志信息?', mbConfirmation, MB_YESNO) = IDYES then
      //删除 {app} 文件夹及其中所有文件
      DelTree(ExpandConstant('{app}'), True, True, True);
end;

[UninstallDelete]
Type: files; Name: "{app}\logs\monitor\*.log";
Type: files; Name: "{app}\tmp\monitor\*.json";
Type: dirifempty; Name: "{app}\logs";
Type: dirifempty; Name: "{app}\tmp";

安装成功后:


服务信息

卸载提示:


卸载提示

你可能感兴趣的:(springboot jar包做成系统服务(windows版本)v2)