Ejemplo n.º 1
0
        public bool DownloadLogAndLoss(WeightVersionModel weight, string destinationFolder)
        {
            try
            {
                if (string.IsNullOrEmpty(weight.LogPath) || string.IsNullOrEmpty(weight.LossFunctionPath))
                {
                    return(false);
                }
                var pk = new PrivateKeyFile(ApplicationConstant.PrivateKeyFilePath);
                //var folder = DateTime.Now.ToString(ApplicationConstant.DatetimeFormat);
                var destination   = new DirectoryInfo(destinationFolder);
                var logPath       = $"{ServerDetectConstant.ApiPath}/{weight.LogPath}";
                var lossPath      = $"{ServerDetectConstant.ApiPath}/{weight.LossFunctionPath}";
                var detectSertver = CommonService.GetUrlDetectServer();
                using (var client = new ScpClient(detectSertver, 22, ServerTrainConstant.Username, pk))
                {
                    client.Connect();

                    client.Download(logPath, destination);
                    client.Download(lossPath, destination);

                    client.Disconnect();
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public void ApplyWeight(string weightPath)
        {
            var pk            = new PrivateKeyFile(ApplicationConstant.PrivateKeyFilePath);
            var weightDir     = ServerDetectConstant.WeightPath;
            var apiDir        = ServerDetectConstant.ApiPath;
            var filename      = Path.GetFileName(weightPath);
            var detectSertver = CommonService.GetUrlDetectServer();

            using (var client = new SshClient(detectSertver, ServerTrainConstant.Username, pk))
            {
                client.Connect();

                var command = client.CreateCommand($@"cp {apiDir}/{weightPath} {weightDir}");
                command.Execute();

                var stopServerCommand = client.CreateCommand($@"pkill -f runserver");
                stopServerCommand.Execute();

                var renameCommand = client.CreateCommand($@"mv {weightDir}/{filename} {weightDir}/latest.weights");
                renameCommand.Execute();

                var restartCommand = client.CreateCommand($@"screen -dm bash -c 'cd {apiDir}; source $HOME/.profile; GOOGLE_APPLICATION_CREDENTIALS=solveequation-firebase.json poetry run python manage.py runserver 0.0.0.0:8080'");
                restartCommand.Execute();
                client.Disconnect();
            }
        }