Example #1
0
        /// <summary>
        /// Used for automating adding HTTP load balancers to Apache2. We open the Apache2 file, modify it, close it. YOU WILL NEED TO RELOAD APACHE2 ELSEWHERE
        /// </summary>
        public void UpdateApacheFile(bool reload = false)
        {
            //Ensure that Apache2 mode is enabled
            if (!type_config.apache_mode_enabled)
            {
                return;
            }

            //Update each file
            foreach (var s in type_config.apache_files)
            {
                _UpdateSingleApacheFile(s);
            }

            //Ensure we have the command to reload
            if (reload && Program.config.apache_reload_command == null)
            {
                throw new Exception("Can't reload Apache2, as there is no command set for it.");
            }

            //Reload
            if (reload)
            {
                ManagerTools.ExecuteShellCommand(Program.config.apache_reload_command);
            }
        }
        private static void _UpdatePackages(OperationProgressClient progressSender)
        {
            progressSender.SendStatus(0x00, $"Updating {Program.config.packages.Count} packages...");
            bool applied = true;

            for (int step = 0; applied; step++)
            {
                applied = false;
                foreach (var p in Program.config.packages)
                {
                    //Only apply if within index
                    if (step < p.Value.update_commands.Length)
                    {
                        //Apply
                        applied = true;
                        progressSender.SendStatus(0x00, $"[{step}-{p.Key}] Updating package...");
                        int code = ManagerTools.ExecuteShellCommand(p.Value.update_commands[step], out string result);
                        progressSender.SendStatus(0x03, result + "\n" + result);
                        progressSender.SendStatus(0x00, $"[{step}-{p.Key}] Package update finished with exit code {code}.");
                    }
                }
            }
            progressSender.SendStatus(0x00, $"Finished updating {Program.config.packages.Count} packages.");
        }