gpt4 book ai didi

f# - Fake.Deploy 运行自定义 Windows 服务锁定部署文件,从而更新

转载 作者:行者123 更新时间:2023-12-01 10:45:01 25 4
gpt4 key购买 nike

我想使用 FAKE 部署一些 Windows 服务。使用 FAKE 构建脚本部署包后,我使用部署后构建脚本 (*.fsx) 安装服务。

这一切都很好,只是一旦服务启动,文件就会被锁定。这禁止任何进一步的(更新)部署。

是否有可能在 FAKE.Deploy 尝试覆盖文件之前停止服务?

最佳答案

只是不要从 FAKE 解压缩的目录安装您的服务。这样做:

  1. 检查目标目录是否存在。如果不是就创建它
  2. 检查是否安装了服务,如果是则卸载
  3. 清理目标目录(确保所有内容都已删除)
  4. 复制新版本文件
  5. 在目标目录中安装新版本的服务

我项目中的部署脚本:

#r @"c:\Project\FAKE.Deploy\bin\FAKE\tools\FakeLib.dll"

open Fake
open System
open System.IO

let targetDirectory = @"c:\Project\Service"
let runScript file =
if File.Exists file then
let result, messages =
ExecProcessRedirected
(fun info ->
info.FileName <- file
info.WorkingDirectory <- targetDirectory)
(TimeSpan.FromMinutes 10.0)
for msg in messages do
(if msg.IsError then traceError else traceImportant) msg.Message

if not result then
failwithf "MyProc.exe returned with a non-zero exit code"
else
traceImportant <| sprintf "File %s is not found" file

// *** Define Targets ***

Target "EnsureDirectory" (fun () ->
trace <| sprintf " --- Ensure that directory '%s' is exist --- " targetDirectory
CreateDir targetDirectory
)

Target "UninstallService" (fun () ->
trace " --- Uninstall service --- "
targetDirectory @@ "uninstall.bat"
|> runScript
)

Target "CleanDirectory" (fun () ->
trace " --- Clean target directory --- "
CleanDir targetDirectory
)

Target "CopyFiles" (fun () ->
trace " --- Copy new files --- "
XCopy (__SOURCE_DIRECTORY__ @@ "content") targetDirectory
)

Target "InstallService" (fun () ->
trace " --- Install service --- "
targetDirectory @@ "install.bat"
|> runScript
)

Target "Deploy" DoNothing

// *** Define Dependencies ***
"EnsureDirectory"
==> "UninstallService"
==> "CleanDirectory"
==> "CopyFiles"
==> "InstallService"
==> "Deploy"

// *** Start Build ***
RunParameterTargetOrDefault "target" "Deploy"

关于f# - Fake.Deploy 运行自定义 Windows 服务锁定部署文件,从而更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27446800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com