private static void StopService(string serviceName) { try { if (!Services.IsInstalled(serviceName)) { ColorizeConsole.PrintlnError($"\n> Service {serviceName} not installed!\n"); return; } if (!Services.IsRunning(serviceName)) { ColorizeConsole.PrintlnWarning($"\n> Service {serviceName} not running!\n"); return; } var proc = new Process { StartInfo = { FileName = "net.exe", Arguments = "stop " + serviceName, WindowStyle = ProcessWindowStyle.Hidden, RedirectStandardInput = true, RedirectStandardOutput = false, UseShellExecute = false, CreateNoWindow = true, Verb = "runas" } }; proc.Start(); Task.Delay(TimeSpan.FromSeconds(3)); } catch (FormatException) {} }
private void OnExecute(IConsole console) { ColorizeConsole.PrintlnInfo($"\n> Reloading services ..."); ReloadService(References.ServiceNameHttp); ReloadService(References.ServiceNameSmtp); ColorizeConsole.PrintlnInfo($"\n> Services reloaded.\n"); }
private void OnExecute(IConsole console) { ColorizeConsole.PrintlnInfo($"\n> Stopping services ..."); StopService(References.ServiceNameHttp); StopService(References.ServiceNameSmtp); ColorizeConsole.PrintlnSuccess($"\n> Services stopped.\n"); }
private void OnExecute(IConsole console) { var dirPath = Environment.CurrentDirectory; var dirName = Path.GetFileName(dirPath); var defaultExtension = Config.Get("App", "VhostExtension"); var givenDomain = dirName.ToLower() + defaultExtension; if (Domain != null) { givenDomain = Domain; } // TODO: fix domain tld validator if (!Utilities.IsValidDomainName(givenDomain)) { ColorizeConsole.PrintlnError($"\n> Please specify a valid domain name!\n"); return; } var vhostFile = VirtualHost.ApacheVhostDir + @"\" + givenDomain + ".conf"; if (File.Exists(vhostFile)) { ColorizeConsole.PrintlnError($"\n> VirtualHost already exists!\n"); return; } ColorizeConsole.PrintlnInfo($"\n> Creating virtualhost ..."); VirtualHost.CreateCert(givenDomain); VirtualHost.CreateVhost(givenDomain, dirPath.Replace("\\", "/")); if (DnsHostfile.IsNotExists(givenDomain)) { DnsHostfile.AddRecord(givenDomain); } // TODO: services restart command still not working // ColorizeConsole.PrintlnInfo($"\n> Reloading services ..."); // Services.Reload(References.ServiceNameHttp); // Task.Delay(TimeSpan.FromSeconds(5)); ColorizeConsole.PrintlnSuccess($"\n> Virtualhost has been created, please restart Varlet services in VarletUi!"); ColorizeConsole.PrintlnWarning($"> Your site will be available at: http://{givenDomain} and https://{givenDomain}\n"); }
private void OnExecute(IConsole console) { var dirPath = Environment.CurrentDirectory; var dirName = Path.GetFileName(dirPath); var defaultExtension = Config.Get("App", "VhostExtension"); var givenDomain = dirName.ToLower() + defaultExtension; if (Domain != null) { givenDomain = Domain; } // TODO: fix domain tld validator if (!Utilities.IsValidDomainName(givenDomain)) { ColorizeConsole.PrintlnError($"\n> Please specify a valid domain name!\n"); return; } var vhostFile = VirtualHost.ApacheVhostDir + @"\" + givenDomain + ".conf"; if (!File.Exists(vhostFile)) { ColorizeConsole.PrintlnWarning($"\n> VirtualHost doesn't exists!\n"); return; } ColorizeConsole.PrintlnInfo($"\n> Removing virtualhost ..."); File.Delete(vhostFile); if (!DnsHostfile.IsNotExists(givenDomain)) { DnsHostfile.DeleteRecord(givenDomain); } // ColorizeConsole.PrintlnInfo($"\n> Reloading services ..."); // Services.Reload(References.ServiceNameHttp); // Task.Delay(TimeSpan.FromSeconds(5)); ColorizeConsole.PrintlnSuccess($"\n> Your site has been removed, please restart Varlet services in VarletUi!\n"); }