在服务启动期间,我尝试安装网络驱动器。 我遵循了这些教程,但是找不到正确的解决方案。
创建了文件共享:Quickstart: Create and manage Azure Files share with Windows virtual machines
将SetupEntryPoint
添加到ServiceManifest
Run script at service startup
我添加了日志记录,也可以找到错误(ConsoleRedirection
部分):
<SetupEntryPoint>
<ExeHost>
<Program>InitNetworkDrives.bat</Program>
<WorkingFolder>CodePackage</WorkingFolder>
<ConsoleRedirection FileRetentionCount="10"/>
</ExeHost>
</SetupEntryPoint>
InitNetworkDrives.bat正常工作
PowerShell -NoProfile -ExecutionPolicy Bypass -Command %cd%\MountNetworkDrive.ps1
它调用PowerShell
脚本,该脚本负责安装新的网络驱动器:
$password = ConvertTo-SecureString "PASSSSWOOOOOOOOOOOORD" -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ("Azure\fileshare", $password)
New-PSDrive -Name W -PSProvider FileSystem -Root \\fileshare\something-Credential $Cred -Persist -Scope Global
如果我在本地调用.bat或.ps1脚本,则驱动器将正确安装。但是,在ServiceFabric
部署期间,用户权限存在问题,并且无法创建已安装的驱动器。我非常确定问题是由用户权限引起的。默认情况下,ServiceFabric
使用NetworkService
用户,但是我尝试使用LocalSystem
,LocalService
,LocalUser
来实现。
Run a service as a local user account or local system account
我开始认为最好的方法是在VM上使用Git存储库,而不是安装的网络驱动器。
我已经尝试过@Compo的修复程序,但是该驱动器仍然不存在。 在New-PSDrive调用之前,我还添加了驱动器检查,并有更详细的日志。
$Networkpath = "B:"
$pathExists = Test-Path -Path $Networkpath
echo "Mount started"
If (-not ($pathExists)) {
$password = ConvertTo-SecureString "PAWWWWSRORD" -AsPlainText -Force
echo "password : $password"
$Cred = New-Object System.Management.Automation.PSCredential ("Azure\fileshare", $password)
echo "Cred : $Cred"
New-PSDrive -Name B -PSProvider FileSystem -Root \\fileshare\algorithmconfigs -Credential $Cred -Persist -Scope Global
echo "New-PSDrive done"
}
else {
echo "Path already existed"
Return #end the function if path was already there
}
脚本运行没有任何问题,日志告诉我一切正常,但是资源管理器中没有驱动器。
Mount started
password : System.Security.SecureString
Cred : System.Management.Automation.PSCredential
Name Used (GB) Free (GB) Provider Root CurrentLocation
---- --------- --------- -------- ---- ---------------
B 0.00 1.00 FileSystem \\stalgorithmconfigs.file.core.w...
New-PSDrive done