Windows Azure Environment.GetEnvironmentVariable("RoleRoot") read access denied error - azure

I have an xml file that I ma tryin to read from
string xmlTemplatePath = Path.Combine(Environment.GetEnvironmentVariable("RoleRoot") + #"\", #"approot\myxml.xml");
Using XDocument doc = XDocument.Load(xmlTemplatePath), however I get an access denied exception both on the cloud and development environment. Any ideas why a read is denied?

I know, old thread... but the answer could be useful to someone nevertheless.
It appears that an azure worker process runs under a custom user (shows up as a GUID in taskmgr). This user account appears to be quite restricted and has no read-access to the filesystem (even inside the approot directory).
My solution was to create a startup script for the azure role (see msdn article) which uses icacls to add permissions to access the files. In this case, I created a file called startup\Install.cmd in my project, containing the following:
#echo off
if "%EMULATED%"=="true" goto :EOF
echo Allowing access to files
cd directory_where_files_exist
icacls *.* /grant Everyone:F
In my ServiceDefinition.csdef file, I instruct the Azure deployment system to run this startup script during deployment by putting this inside the role definition (e.g. <WorkerRole>):
<Startup>
<Task executionContext="elevated" commandLine="startup\Install.cmd">
<Environment>
<Variable name="EMULATED">
<RoleInstanceValue xpath="/RoleEnvironment/Deployment/#emulated" />
</Variable>
</Environment>
</Task>
</Startup>
The variable "EMULATED" is set when the emulator is running - note that in the startup/Install.cmd file above, I skip doing the permission change if running in the emulator.

Looks fine to me. I even grabbed your code and dropped it into a worker role, calling it from OnStart(), after creating myxml.xml in my project root, just to make sure I wasn't missing something obvious.
Check myxml.xml properties: "Build Action" should be "Content" and "Copy to Output Directory" should be "Copy always" or "Copy if newer". If that doesn't fix it, check permissions on that file.

Related

Failed to delete a file in Azure File Share, Error: The specified resource is read-only and cannot be modified at this time

While trying to delete a file in the Azure Storage File Share. I continuously get following error:
Failed to delete file
'cs-firstName-lastname-domain-com-10033fff99999999/mslearn-my-app-folder-word-and-word-wd/.git/objects/pack/pack-someguid.idx'.
Error: The specified resource is read-only and cannot be modified at
this time
Tried to check if there are any current open handles but I see none.
https://learn.microsoft.com/en-us/rest/api/storageservices/list-handles
<?xml version="1.0" encoding="utf-8"?>
<EnumerationResults>
<Entries />
<NextMarker />
</EnumerationResults>
Also, I tried to connect to this Azure file share from Windows by running powershell cmdlet New-PSDrive, but there too and using Remove-Item, getting below error
Remove-Item : Cannot remove item
Z:\mslearn-my-app-folder-word-and-word-wd/.git/objects/pack/pack-someguid.idx: **You
do not have sufficient access rights to perform this operation**.
Any help, about how to change the property from read-only/ how can I delete/ or anything which I am missing.
Thanks,
As mentioned in the link shared by #BhargaviAnnadevara-MSFT, https://social.msdn.microsoft.com/Forums/en-US/6fde433a-aef0-49e9-8568-2aaf5a9b673a/unable-to-delete-a-file-from-azure-file-storage?forum=windowsazuredata The read-only attribute can be removed only once mounted, I did following.
Mounted the File Share using the script provided in the Azure portal
Once mounted, doing a ls command will show the file attributes
In powershell or CMD change the file attribute. I found it hard to do it via powershell so instead used ATTRIB cmd. attrib pack-someguid.idx -R
Update : Easier Solution
https://learn.microsoft.com/en-us/azure/storage/files/storage-how-to-use-files-windows#mount-the-azure-file-share-with-file-explorer

Azure Cloud Service Virtual Directory Issue

I am trying to add virtual directory in WebRole1 of my could service using following directive in csdf file...
<Site name="Web">
<VirtualDirectory name="aspnet_client" physicalDirectory="..\..\..\crazureresource\aspnet_client" />
<VirtualDirectory name="Downloads" physicalDirectory="..\..\..\crazureresource\Downloads" />
<Bindings>
<Binding name="Endpoint1" endpointName="Endpoint1" />
</Bindings>
</Site>
The development machine directory structure is...
..\CR1\CR1\ProjectFiles
..\CR1\crazureresource\aspnet_client
..\CR1\crazureresource\Downloads
The azure webrole1 directory structure is...
siteroot\0\website-deployed-files
siteroot\crazureresource\aspnet_client
siteroot\crazureresource\Downloads
The package gets published successfully; instance is also updated but WebRole's status is either 'Busy' or 'Restarting'. The website is not deployed on the webrole. If I shorten the path of virtual directory to
> ..\..\..\aspnet_clients and ..\..\..\Downloads
It works (the deployment); but the contents are modified on azure cloud service. In place of these physical folders a new folder by the name of 1 and 2 are created. Inside these two replacement folders, config files are placed by system - the original files are replaced. While at the same time in IIS, a valid link shows for virtual directory.
I am not able to access the resources from virtual directory due to this!
For Azure this is the valid directory structure
siteroot\0\website-deployed-files
siteroot\1\ ----name it as aspnet_client
siteroot\2\ ----name it as Downloads
and the contents will be availble like below urls
www.exapmple.com --- default (website-deployed-files)
www.exapmple.com/aspnet_client --contents of (aspnet_client)
www.exapmple.com/Downloads --contents of Downloads
you can update you local directroy structure to match.
for the path in csdef file
physicalDirectory="..\..\..\crazureresource\Downloads"
This is the path from /bin directory of Azure project to the Other projects Downloads.csproj directory.
Refer this for updating the Path properly in your csdef file
Hope this helps.

Microsoft Azure Startup Task Not Executing

I have a simple file in the root of my Web project (which is tied to a Web worker role). The file is named Startup.cmd. This file contains the following line: dir > directory.txt. It executes properly when I run it from the command line and outputs a list of the directory contents to file named directory.txt as you would expect. Similarly, the line ECHO Write this line to file > output.txt does not appear to work either.
Inside ServiceDefinition.csdef for my Azure Cloud Service project, I have the following lines:
<WebRole name="Website" vmsize="Small">
<Startup>
<Task commandLine="Startup.cmd" executionContext="elevated" taskType="simple"></Task>
</Startup>
....
</WebRole>
I believe it is finding the file, because I have tried changing the path and it will throw a build error that it cannot find it. The issue is that when I check my /bin/ directory after debugging to the Azure Debugging Environment, I see Startup.cmd (I have it set to Copy always) but I do not see directory.txt. I'm not sure of another way to confirm that it executed properly.
I found the following MSDN article useful: http://msdn.microsoft.com/en-us/library/hh180155.aspx.
As a result, I made some changes to my Startup.cmd file. I changed the command to:
ECHO The current version is %MyVersionNumber% >> "%TEMP%\StartupLog.txt" 2>&1
EXIT /B 0
However, this did not appear to put the output in my temporary directory for my system: C:\Users\username\AppData\Local\Temp. I'm going to presume this is because the Azure Compute Emulator uses a different temp directory I am unaware of.
I changed my Startup.cmd to:
ECHO The current version is %MyVersionNumber% >> "c:\temp\StartupLog.txt" 2>&1
EXIT /B 0
And updated my configuration to:
<WebRole name="Website" vmsize="Small">
<Startup>
<Task commandLine="Startup.cmd" executionContext="elevated" taskType="simple">
<Environment>
<Variable name="MyVersionNumber" value="1.0.0.0" />
<Variable name="ComputeEmulatorRunning">
<RoleInstanceValue xpath="/RoleEnvironment/Deployment/#emulated" />
</Variable>
</Environment>
</Task>
</Startup>
...
</WebRole>
And this did appear to write the file to C:\temp\ upon starting the debugger.

Trying to create my .cspkg Azure package file, but getting an error "Need to specify the physical directory for the virtual path..."

When I try to package my Azure web app (to create the .cspkg and .cscfg files), I get the following error in my ServiceDefinition.csdef file:
Need to specify the physical directory for the virtual path
'AzurePOCWebRole/' of role AzurePOCWebRole
Here's my .csdef file:
I'm assuming the error is referring to my <Site name="AzurePOCWebRole"> piece. I try adding physicalDirectory to <Site name="AzurePOCWebRole" physicalDirectory="../AzurePOCWebRole">:
And try to create the package again, but I get the same error and it reverts that change I just made back to <Site name="AzurePOCWebRole">:
QUESTION: What can I do to resolve this error and create my package?
I was editing the "automatically generated" version of ServiceDefinition.csdef, which wasn't apparent because it didn't indicate it wasn't the actual file, so whenever I rebuilt, it reverted this file back to the original ServiceDefinition.csdef's file, which I WASN'T editing.

Cruisecontrol.net with UCM Clearcase - How to?

I am trying to configure Cruisecontrol.net for UCM Clearcase for the first time. Following is the sourceControl tag in the ccnet.config file:
<sourcecontrol type="clearCase">
<branch>123_India_Release</branch>
<autoGetSource>true</autoGetSource>
<viewName>admin_123_CRUISE</viewName>
<viewPath>$(ViewDirectory)</viewPath>
<useLabel>false</useLabel>
<useBaseline>false</useBaseline>
<executable>cleartool.exe</executable>
</sourcecontrol>
I constantly receive the following error:
ThoughtWorks.CruiseControl.Core.CruiseControlException: Source control
operation failed: cleartool: Error: Not an object in a vob: "PATH TO
THE VIEW"
When I run cleartool from an arbitrary directory with the following parameters:
cleartool.exe lshist -r -nco -branch "123_India_Release" -since
05-Dec-2012.14:38:18 -fmt
I get the same error. But if I change the working directory to $(ViewDirectory) before running cleartool, it runs fine.
How should I make Cruisecontrol.net run cleartool.exe from the $(ViewDirectory)?
I have already tried adding <workingDirectory>$(ViewDirectory)</workingDirectory> tag before <executable>cleartool.exe</executable> but it did not work.
Any help would be appreciated.
EDIT 1:
As a workaround I have done the following:
<exec>
<executable>cleartool.exe</executable>
<baseDirectory>d:\Workspace\123_India_Release\VOB</baseDirectory>
<buildArgs>update -force</buildArgs>
<buildTimeoutSeconds>6000</buildTimeoutSeconds>
</exec>
I have added this to the tasks tag. I have configured an hourly trigger which does the following:
1) Update snapshot view
2) Build the VS 2010 solutions mentioned in the tasks tag.
The limitations are:
1) The trigger is hourly. I want it to be a commit based trigger.
2) This is a workaround
EDIT 2:
Further experimentation revealed that the ccnet.exe works fine. It does all that is needed. The issue is caused by the service ccservice.
I have stopped ccservice for now and started ccnet.exe. I plan to leave it running.
The View directory isn't enough: you must specify a vob.
See for instance:
"clearfsimport: Error: Not an object in a vob: "\"." (as an illustratio of that error message)
this thread (or this one): "You have to specify explicitly the VOB(s) to check for modification set"
The path should looks like:
<viewPath>Drive:\path\to\view\vobname</viewPath>
If your $(ViewDirectory) already references Drive:\path\to\view, then you could use:
<viewPath>$(ViewDirectory)\vobname</viewPath>

Resources