前言
Net core 項目部門在Windows有很多種方式,大致有以下幾種,
- dotnet 命令,
- iis(windowshosts),
- 一些開源的應(yīng)用容器(docker )
- 基于一些exe 程序,微軟官網(wǎng)上案例
- Nssm 搭建windows服務(wù)
其中優(yōu)劣對比在這不進行累述。我今天是把它搭建到windows服務(wù)上的,這種方式對于我們現(xiàn)有dotnet來說相對美觀(一個黑框框,一個看不到),電腦重啟可以自動重啟。
1.實現(xiàn)
1.1.下載nssm
官網(wǎng)http://www.nssm.cc/,下載地址http://www.nssm.cc/download
1.2.搭建windows 服務(wù)
找到文件夾下建立的Install.bat 點擊運行彈出操作窗體。
Install.bat內(nèi)容:
1
2
3
4
|
%~d0 cd %~dp0 nssm install NPSWebCoreService PAUSE |
Path:選擇系統(tǒng)運行bat----C:\Nps\CoreWeb\1run.bat
ps:因為我們系統(tǒng)中要特殊處理所以直接執(zhí)行了bat。此內(nèi)容正常是填寫C:\Program Files\dotnet\dotnet.exe. 因為要執(zhí)行dotnet命令,我這些操作實在bat中執(zhí)行的。
Startup directory:bat 所在目錄不用改變;
ps:發(fā)布項目文件夾的地址。
Arguments:為空;
ps:項目運行dll:
Service name:我寫在install.bat 批處理里面了,不要改變,因為代碼中重啟服務(wù)我這是寫死的。。
ps:創(chuàng)建線管名稱即可,即windows 服務(wù)名稱。
然后點擊Install service按鈕就完成了部署。
注:紅色字體為是一般處理方式,非紅色是我們系統(tǒng)中處理的方式
1.2.3 啟動服務(wù)
讓后輸入網(wǎng)站就可以訪問了
3. Nssm
3.1.輸入nssm 了解其命令行
3.2.官網(wǎng)http://www.nssm.cc/usage
4. 針對與咱們系統(tǒng)的問題的處理方案
4.1. 日志問題,nssm 中path 文件運行bat 不要運行dotnet.exe. Log4net 配置問題。
4.2. Office 轉(zhuǎn)換pdf 問題,windows servers 2008 服務(wù)器缺少com組件缺少窗口,我在程序中增加了相關(guān)代碼,如果沒有權(quán)限請手動創(chuàng)建(服務(wù)器2008 r2 ,2016都能創(chuàng)建)
System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Office Excel 不能訪問文件“D:\Benz\Daimler\Benz.Win\LSHBizPlanFigure.xls”。 可能的原因有:
? 文件名稱或路徑不存在。
? 文件正被其他程序使用。
? 您正要保存的工作簿與當前打開的工作簿同名。
此問題的出現(xiàn) 我十分不解。
解決方案 也十分疑惑
This solution is ...
?Windows 2008 Server x64
Please make this folder.C:\Windows\SysWOW64\config\systemprofile\Desktop
?Windows 2008 Server x86
Please make this folder.
C:\Windows\System32\config\systemprofile\Desktop
...instead of dcomcnfg.exe.
This operation took away office automation problems in my system.
A Desktop folder seems to be necessary in the systemprofile folder to open file by Excel.
It disappears from Windows2008, Windows2003 had the folder,
and I think it cause this error.
即在C:\Windows\System32\config\systemprofile和C:\Windows\SysWOW64\config\systemprofile目錄下創(chuàng)建名為Desktop目錄即可解決問題
該方法確實解決了我的問題
4.3.數(shù)據(jù)庫備份重啟服務(wù)問題,改為重啟windows服務(wù),所以請用上面的install.bat運行不要,改變Service name。
重啟服務(wù)代碼:
1
2
3
4
5
6
7
8
9
10
11
12
|
try { ServiceController service = new ServiceController( "NPSWebCoreService" ); if (service.Status == ServiceControllerStatus.Running) { service.Stop(); service.WaitForStatus(ServiceControllerStatus.Stopped); } service.Start(); service.WaitForStatus(ServiceControllerStatus.Running); } catch (Exception){} |
4.4.netcoreweb要基于mysql 服務(wù)問題,擔(dān)心再啟服務(wù)器的時候,mysql和windows 服務(wù)啟動順序的問題,我在啟動bat 中怎么了判斷mysql服務(wù)是否啟動的判斷。
bat 內(nèi)容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
@echo off SETLOCAL enabledelayedexpansion rem 關(guān)閉自動輸出 :begin for /f "skip=3 tokens=4" %%i in ( 'sc query MySQL' ) do set "zt=%%i" & goto :next :next if /i "%zt%" == "RUNNING" ( echo 已經(jīng)發(fā)現(xiàn)該服務(wù)在運行。 ) else ( net start MySQL80 echo 已經(jīng)發(fā)現(xiàn)該服務(wù)在運行1。 ) rem 接收輸入 rem 輸出得到的輸入信息 echo 啟動NPSWebCore dotnet ./NPSWebCore.dll @echo 啟動結(jié)束 exit |
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對服務(wù)器之家的支持。
原文鏈接:https://www.cnblogs.com/kmonkeywyl/p/11506028.html