Beispiel #1
0
        protected override void OnLockAcquired()
        {
            OperationManager.SafeExecute(() => {
                // Create Sentinel file for DWAS to check
                // DWAS will check for presence of this file incase a an app setting based recycle needs to be performed in middle of deployment
                // If this is present, DWAS will postpone the recycle so that deployment goes through first
                if (!String.IsNullOrEmpty(siteRoot))
                {
                    FileSystemHelpers.CreateDirectory(Path.Combine(siteRoot, @"ShutdownSentinel"));
                    string sentinelPath = Path.Combine(siteRoot, @"ShutdownSentinel\Sentinel.txt");

                    if (!FileSystemHelpers.FileExists(sentinelPath))
                    {
                        var file = FileSystemHelpers.CreateFile(sentinelPath);
                        file.Close();
                    }

                    // DWAS checks if write time of this file is in the future then only postpones the recycle
                    FileInfoBase sentinelFileInfo     = FileSystemHelpers.FileInfoFromFileName(sentinelPath);
                    sentinelFileInfo.LastWriteTimeUtc = DateTime.UtcNow.AddMinutes(20);
                }
            });

            IRepositoryFactory repositoryFactory = RepositoryFactory;

            if (repositoryFactory != null)
            {
                IRepository repository = repositoryFactory.GetRepository();
                if (repository != null)
                {
                    // Clear any left over repository-related lock since we have the actual lock
                    repository.ClearLock();
                }
            }
        }
Beispiel #2
0
 public DeploymentLockFile(string path, ITraceFactory traceFactory)
     : base(path, traceFactory)
 {
     OperationManager.SafeExecute(() => {
         if (Environment.IsAzureEnvironment() && OSDetector.IsOnWindows())
         {
             siteRoot = PathUtilityFactory.Instance.ResolveLocalSitePath();
         }
     });
 }
Beispiel #3
0
        protected override void OnLockRelease()
        {
            base.OnLockRelease();

            OperationManager.SafeExecute(() => {
                // Delete the Sentinel file to signal DWAS that deployment is complete
                if (!String.IsNullOrEmpty(siteRoot))
                {
                    string sentinelPath = Path.Combine(siteRoot, @"ShutdownSentinel\Sentinel.txt");

                    if (FileSystemHelpers.FileExists(sentinelPath))
                    {
                        FileSystemHelpers.DeleteFile(sentinelPath);
                    }
                }
            });
        }
Beispiel #4
0
        protected override void OnLockRelease()
        {
            base.OnLockRelease();

            if (ScmHostingConfigurations.FunctionsSyncTriggersDelayBackground && shutdownDelayed)
            {
                ShutdownDelaySemaphore.GetInstance().Release(_traceFactory.GetTracer());
            }
            else
            {
                OperationManager.SafeExecute(() => {
                    // Delete the Sentinel file to signal DWAS that deployment is complete
                    if (!String.IsNullOrEmpty(siteRoot))
                    {
                        string sentinelPath = Path.Combine(siteRoot, @"ShutdownSentinel\Sentinel.txt");

                        if (FileSystemHelpers.FileExists(sentinelPath))
                        {
                            FileSystemHelpers.DeleteFile(sentinelPath);
                        }
                    }
                });
            }
        }
Beispiel #5
0
        public bool Acquire(ITracer tracer)
        {
            lock (_lock)
            {
                try
                {
                    // No timeout makes this call instant. No waiting for acquistion
                    bool acquired = _shutdownSemaphore.Wait(millisecondsTimeout: 0);

                    if (!acquired)
                    {
                        tracer.Trace("Could not acquire shutdown semaphore", new Dictionary <string, string>
                        {
                            { "SemaphoreCount", _shutdownSemaphore.CurrentCount.ToString() }
                        });

                        return(false);
                    }

                    //tracer.Trace("Acquired shutdown semaphore", new Dictionary<string, string>
                    //{
                    //    { "SemaphoreCount", _shutdownSemaphore.CurrentCount.ToString() }
                    //});

                    OperationManager.SafeExecute(() => {
                        if (Environment.IsAzureEnvironment() && OSDetector.IsOnWindows())
                        {
                            string siteRoot = PathUtilityFactory.Instance.ResolveLocalSitePath();

                            // Create Sentinel file for DWAS to check
                            // DWAS will check for presence of this file incase a an app setting based recycle needs to be performed in middle of deployment
                            // If this is present, DWAS will postpone the recycle so that deployment goes through first
                            if (!string.IsNullOrEmpty(siteRoot))
                            {
                                FileSystemHelpers.CreateDirectory(Path.Combine(siteRoot, @"ShutdownSentinel"));
                                string sentinelPath = Path.Combine(siteRoot, @"ShutdownSentinel\Sentinel.txt");

                                if (!FileSystemHelpers.FileExists(sentinelPath))
                                {
                                    //tracer.Trace("Creating shutdown sentinel file", new Dictionary<string, string>
                                    //{
                                    //    { "SemaphoreCount", _shutdownSemaphore.CurrentCount.ToString() }
                                    //});
                                    var file = FileSystemHelpers.CreateFile(sentinelPath);
                                    file.Close();
                                }

                                tracer.Trace("Updating shutdown sentinel last write time", new Dictionary <string, string>
                                {
                                    { "SemaphoreCount", _shutdownSemaphore.CurrentCount.ToString() }
                                });
                                // DWAS checks if write time of this file is in the future then only postpones the recycle
                                FileInfoBase sentinelFileInfo     = FileSystemHelpers.FileInfoFromFileName(sentinelPath);
                                sentinelFileInfo.LastWriteTimeUtc = DateTime.UtcNow.AddMinutes(20);
                            }
                        }
                    });
                }
                catch (Exception ex)
                {
                    tracer.TraceError(ex);
                    return(false);
                }

                return(true);
            }
        }