Working with a WorkerRole, I have two startup tasks that are defined. In the first one, firewall rules, cygwin download and install and calling powershell scripts is executed from a .cmd file.
The problem I am seeing, is that "sometimes", it is not executed. I can run a deployment, and it will work, then another it will not. The logs are not providing any help.
I have tried ensuring file encoding is correct, but there does not seem to be any consistency to the problem.
The .cmd file is as follows:
netsh advfirewall firewall add rule name="SSH" dir=in action=allow service=any enable=yes profile=any localport=22 protocol=tcp
IF EXIST C:\alreadySetup\NUL GOTO ALREADYSETUP
mkdir c:\alreadySetup
mkdir e:\approot\uploads
set remoteuser=user
set remotepassword=password
net user %remoteuser% %remotepassword% /add
net localgroup Administrators %remoteuser% /add
.\Startup\ntrights.exe +r SeServiceLogonRight -u "%remoteuser%"
.\Startup\ntrights.exe +r SeServiceLogonRight -u "Administrators"
netsh advfirewall firewall add rule name="SSH" dir=in action=allow service=any enable=yes profile=any localport=22 protocol=tcp
powershell -executionpolicy unrestricted -file .\Startup\DownloadBlob.ps1
c:\cygwin\bin\dos2unix.exe e:\approot\Startup\startSSHd.sh
schtasks /CREATE /TN "StartSSHd" /SC ONCE /SD 01/01/2020 /ST 00:00:00 /RL HIGHEST /RU %remoteuser% /RP %remotepassword% /TR "c:\cygwin\bin\bash --login /cygdrive/e/approot/startup/startSSHd.sh" /F
icacls d:\windows\system32\tasks\StartSSHd /grant:r Administrators:(RX)
schtasks /RUN /TN "StartSSHd"
schtasks /CREATE /TN "CopyAndCleanupSFTPFiles" /SC MINUTE /SD 01/01/2000 /ST 00:00:00 /RL HIGHEST /RU %remoteuser% /RP %remotepassword% /TR "e:\approot\Startup\CopyAndCleanupSFTPFiles.cmd" /F
schtasks /RUN /TN "CopyAndCleanupSFTPFiles"
:ALREADYSETUP
Of note, is that when it doesn't run, the alreadySetup folder is not even created, which is the first part of the script.