public void InstallTheService() { try { IDictionary state = new Hashtable(); using (AssemblyInstaller installer = new AssemblyInstaller(InstallersAssembly, Args)) { installer.UseNewContext = true; try { installer.Install(state); installer.Commit(state); InternalTrace("Installed the service"); } catch (Exception installException) { try { installer.Rollback(state); InternalTrace("Rolledback the service installation because:" + installException.ToString()); } catch { } throw; } } } catch (Exception exception) { InternalTrace("Failed to install the service " + exception.ToString()); } }
public static void Uninstall(string[] args) { try { using (var installer = new AssemblyInstaller(typeof(InstallationManager).Assembly, args)) { IDictionary state = new Hashtable(); // Install the service installer.UseNewContext = true; try { installer.Uninstall(state); } catch (Exception ex) { Console.WriteLine(ex.ToString()); try { installer.Rollback(state); } catch (Exception exception) { Console.WriteLine(exception.ToString()); } } } } catch (Exception exception) { Console.WriteLine("Failed to install service. Error: " + exception.Message); } }
public void InstallService(string user, string pass) { using (AssemblyInstaller installer = new AssemblyInstaller(Path.Combine(Utils.GetApplicationPath(), Utils.GetExecutableName()), null)) { installer.UseNewContext = true; Hashtable savedState = new Hashtable(); UserPassCombination c = new UserPassCombination(); c.User = user; c.Pass = pass; _userPassCombination = c; installer.BeforeInstall += new InstallEventHandler(installer_BeforeInstall); //Rollback has to be called by user code. According msdn-doc for AssemblyInstaller.Install() is probably wrong. try { installer.Install(savedState); installer.Commit(savedState); } catch (Exception ex) { installer.Rollback(savedState); throw new InstallException(String.Format("Install failed: {0}", ex.Message), ex); } installer.BeforeInstall -= installer_BeforeInstall; } }
private void TryRollback(AssemblyInstaller installer, IDictionary state) { try { installer.Rollback(state); } catch (Exception ex ) { _log.Write(LogLevel.Warning, "An error occured during rollback. {0}", ex); } }
static void Install(bool undo, string[] args) { try { Console.WriteLine(undo ? "uninstalling" : "installing"); using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { if (undo) { inst.Uninstall(state); } else { inst.Install(state); inst.Commit(state); try { ServiceController service = new ServiceController("DpFamService"); TimeSpan timeout = TimeSpan.FromMilliseconds(1000); service.Start(); service.WaitForStatus(ServiceControllerStatus.Running, timeout); } catch { Console.WriteLine("Could not start the server\n"); } } } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } }
public static bool Install() { Tracker.StartServer(); bool result = true; InstallContext context = null; try { using (var inst = new AssemblyInstaller(typeof (ServerLifecycleManager).Assembly, null)) { context = inst.Context; LogMessage("Installing service " + AppSettings.ServiceName, inst.Context); IDictionary state = new Hashtable(); inst.UseNewContext = true; try { inst.Install(state); inst.Commit(state); Tracker.TrackEvent(TrackerEventGroup.Installations, TrackerEventName.Installed); } catch (Exception err) { Tracker.TrackException("WindowsServiceManager", "Install", err); try { inst.Rollback(state); } catch (Exception innerErr) { throw new AggregateException(new List<Exception> {err, innerErr}); } throw; } } } catch (Exception ex) { result = false; WriteExceptions(ex, context); } finally { Tracker.Stop(); } return result; }
// References http://stackoverflow.com/questions/1195478/how-to-make-a-net-windows-service-start-right-after-the-installation/1195621#1195621 public static void Install() { using (AssemblyInstaller installer = new AssemblyInstaller(typeof(OpenVpnService).Assembly, null)) { installer.UseNewContext = true; var state = new System.Collections.Hashtable(); try { installer.Install(state); installer.Commit(state); } catch { installer.Rollback(state); throw; } } }
static void Install(bool undo, string[] args) { try { Logger.Log(undo ? "Uninstalling ..." : "Installing ... "); using (var inst = new AssemblyInstaller(typeof(Program).Assembly, args)) { var state = new Hashtable(); inst.UseNewContext = true; try { if (undo) { inst.Uninstall(state); } else { inst.Install(state); inst.Commit(state); StartService(); } } catch (Exception ex) { try { Logger.Log(ex); inst.Rollback(state); } catch { } throw; } inst.Dispose(); } Logger.Log("... finished"); } catch (Exception ex) { Logger.Log(ex); } }
public static bool Install(bool undo, string[] args) { try { Console.WriteLine(undo ? "Uninstalling..." : "Installing..."); using (AssemblyInstaller inst = new AssemblyInstaller(typeof(WakeService).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { if (undo) { inst.Uninstall(state); } else { inst.Install(state); inst.Commit(state); } } catch { try { inst.Rollback(state); } catch { } throw; } } return true; } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } return false; }
public void OnAction(Hashtable parameters) { ArrayList temp = new ArrayList(); temp.Add("/LogToConsole=false"); StringBuilder tempString = new StringBuilder(); foreach (DictionaryEntry entry in parameters) { if (tempString.Length > 0) tempString.Append(" "); tempString.Append(entry.Key); tempString.Append("="); tempString.Append(entry.Value); } temp.Add("commandline=" + tempString.ToString()); string[] commandLine = (string[])temp.ToArray(typeof(string)); System.Configuration.Install.AssemblyInstaller asmInstaller = new AssemblyInstaller(Assembly.GetExecutingAssembly(), commandLine); Hashtable rollback = new Hashtable(); if (GameServerService.GetDOLService() != null) { Console.WriteLine("DOL service is already installed!"); return; } Console.WriteLine("Installing Road as system service..."); try { asmInstaller.Install(rollback); asmInstaller.Commit(rollback); } catch (Exception e) { asmInstaller.Rollback(rollback); Console.WriteLine("Error installing as system service"); Console.WriteLine(e.Message); return; } Console.WriteLine("Finished!"); }
public static bool Install(bool undo, string[] args) { try { using(var inst = new AssemblyInstaller(typeof(Program).Assembly, args)) { inst.AfterInstall += OnAfterInstall; IDictionary state = new Hashtable(); inst.UseNewContext = true; try { if(undo) inst.Uninstall(state); else { inst.Install(state); inst.Commit(state); } } catch { try { inst.Rollback(state); } catch { return false; } throw; } } } catch(Exception ex) { Console.WriteLine(ex); return false; } return true; }
/// <summary> /// Actually installs/uninstalls this service. /// </summary> /// <param name="undo"></param> /// <param name="args"></param> private static void Install(bool undo, string[] args) { try { using (AssemblyInstaller installer = new AssemblyInstaller( Assembly.GetEntryAssembly(), args)) { IDictionary savedState = new Hashtable(); installer.UseNewContext = true; try { if (undo) { installer.Uninstall(savedState); } else { installer.Install(savedState); installer.Commit(savedState); } } catch { try { installer.Rollback(savedState); } catch { } throw; } } } catch (Exception exception) { Console.Error.WriteLine(exception.Message); } }
static void Install(bool undo, string[] args) { try { Console.WriteLine(undo ? "uninstalling" : "installing"); using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { if (undo) { inst.Uninstall(state); } else { inst.Install(state); inst.Commit(state); } } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); throw; } }
private static void InstallService(bool undo, string[] args) { using (AssemblyInstaller inst = new AssemblyInstaller(Assembly.GetExecutingAssembly(), args)) { var state = new Hashtable(); inst.UseNewContext = true; try { if (undo) { inst.Uninstall(state); } else { inst.Install(state); inst.Commit(state); } } catch { try { inst.Rollback(state); } catch { } throw; } } }
public static void Install(bool undo, string openvpn) { try { using (AssemblyInstaller inst = new AssemblyInstaller(typeof(OpenVPNServiceRunner).Assembly, new String[0])) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { if (undo) { inst.Uninstall(state); } else { inst.Install(state); inst.Commit(state); SetParameters(openvpn); } } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } }
/// <summary> /// Installation standalone du service. /// </summary> /// <param name="undo"></param> /// <param name="args"></param> public static void Install(bool undo, string[] args) { // Source: https://groups.google.com/forum/?hl=en&fromgroups=#!topic/microsoft.public.dotnet.languages.csharp/TUXp6lRxy6Q var logger = LogManager.GetLogger("MemcachedServiceInstaller"); try { logger.Info(undo ? "uninstalling" : "installing"); using (AssemblyInstaller inst = new AssemblyInstaller(typeof(MemcachedServiceInstaller).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { if (undo) { inst.Uninstall(state); } else { inst.Install(state); inst.Commit(state); } } catch (Exception ex) { logger.Error(ex.ToString()); try { inst.Rollback(state); } catch (Exception ex2) { logger.Error(ex2.ToString()); } throw; } } } catch (Exception ex) { logger.Fatal(ex.ToString()); throw; } }
static void Install(bool undo, string[] args) { using (AssemblyInstaller asminstall = new AssemblyInstaller(typeof(XenService).Assembly, args)) { System.Collections.IDictionary state = new System.Collections.Hashtable(); asminstall.UseNewContext = true; try { if (undo) { asminstall.Uninstall(state); } else { asminstall.Install(state); asminstall.Commit(state); } } catch { try { asminstall.Rollback(state); } catch { } } } }
/// <summary> /// Uninstalls this service /// </summary> void UninstallThis() { try { using (var i = new AssemblyInstaller(ProgramType.Assembly, null) { UseNewContext = true }) { IDictionary s = new Hashtable(); try { i.Uninstall(s); } catch { try { i.Rollback(s); } catch { } throw; } } Console.WriteLine(Messages.Done); } catch (Exception x) { Console.Error.WriteLine(x.Message); ReturnValue = 1; } }
/// <summary> /// Installs the service /// </summary> void Install() { Console.Write(InfoString); try { using (var i = new AssemblyInstaller(ProgramType.Assembly, null) { UseNewContext = true }) { var s = new Hashtable(); try { i.Install(s); i.Commit(s); } catch { try { i.Rollback(s); } catch { } throw; } } Console.WriteLine(Messages.Done); } catch (Exception x) { Console.Error.WriteLine(x.Message); ReturnValue = 1; } }
/// <summary> /// Handle installation and uninstallation. /// </summary> /// <param name="uninstall">Whether we're uninstalling. False if installing, true if uninstalling</param> /// <param name="args">Any service installation arguments.</param> public void Install(bool uninstall, string[] args) { try { using (AssemblyInstaller installer = new AssemblyInstaller(typeof(Program).Assembly, args)) { IDictionary state = new Hashtable(); installer.UseNewContext = true; try { // Attempt to install or uninstall. if (uninstall) installer.Uninstall(state); else { installer.Install(state); installer.Commit(state); } } catch { // If an error is encountered, attempt to roll back. try { installer.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } }
private void Register(bool undo) { Log.Debug("Registering Poweshell Plugin"); var core = Common.ApiPath + @"\Plugins\PowerShell\OSAE.PowerShellProcessor.dll"; using (var install = new AssemblyInstaller(core, null)) { IDictionary state = new Hashtable(); install.UseNewContext = true; try { if (undo) install.Uninstall(state); else { install.Install(state); install.Commit(state); } } catch { install.Rollback(state); } } if (PluginRegistered()) Log.Debug("Powershell Plugin successfully registered"); else Log.Debug("Powershell Plugin failed to register"); }
private void Install(bool uninstall) { try { _log.Info(uninstall ? "Uninstalling" : "Installing"); using (var inst = new AssemblyInstaller(typeof (Program).Assembly, null)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { if (uninstall) { inst.Uninstall(state); } else { inst.Install(state); inst.Commit(state); } } catch { try { inst.Rollback(state); } catch (Exception ex) { _log.Error("Error Rolling back"); _log.Error(ex.Message); } throw; } } } catch (Exception ex) { _log.Error(ex.Message); } }
private void DoInstall(bool add, string[] args) { try { this.CbLog(add ? "Installing application..." : "Uninstalling application..."); this.CbLog("This must be run as an Administrator!"); using (AssemblyInstaller inst = new AssemblyInstaller( this.ProgramToInstall.Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { if (add) { inst.Install(state); inst.Commit(state); } else { inst.Uninstall(state); } this.CbLog("Installation successful!"); } catch { this.CbLog("Installation error:"); try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { this.CbLog(ex); } }
static void Main(string[] args) { bool isConsole = false; try { // Get DateTime.ToString() to use a format ot ToString("o") instead of ToString("G"). CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone(); culture.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd"; culture.DateTimeFormat.LongTimePattern = "THH:mm:ss.fffffffzzz"; Thread.CurrentThread.CurrentCulture = culture; m_serverStorageType = (AppState.GetConfigSetting(m_storageTypeKey) != null) ? StorageTypesConverter.GetStorageType(AppState.GetConfigSetting(m_storageTypeKey)) : StorageTypes.Unknown; m_serverStorageConnStr = AppState.GetConfigSetting(m_connStrKey); bool monitorCalls = true; if (m_serverStorageType == StorageTypes.Unknown || m_serverStorageConnStr.IsNullOrBlank()) { throw new ApplicationException("The SIP Application Service cannot start with no persistence settings specified."); } SIPAllInOneDaemon daemon = null; if (args != null && args.Length == 1 && args[0] == "-i") { try { using (AssemblyInstaller inst = new AssemblyInstaller(typeof(MainConsole).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { //if (undo) //{ // inst.Uninstall(state); //} //else //{ inst.Install(state); inst.Commit(state); //} } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } else if (args != null && args.Length == 1 && args[0] == "-u") { try { using (AssemblyInstaller inst = new AssemblyInstaller(typeof(MainConsole).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { inst.Uninstall(state); } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } else if (args != null && args.Length == 1 && args[0].StartsWith("-c") || System.Environment.UserInteractive == true) { isConsole = true; Console.WriteLine("SIP App Server starting"); logger.Debug("SIP App Server Console starting..."); string sipSocket = null; string callManagerSvcAddress = null; if (args != null && args.Length > 0) { foreach (string arg in args) { if (arg.StartsWith("-sip:")) { sipSocket = arg.Substring(5); } else if (arg.StartsWith("-cms:")) { callManagerSvcAddress = arg.Substring(5); } else if (arg.StartsWith("-hangupcalls:")) { monitorCalls = Convert.ToBoolean(arg.Substring(13)); } } } if (sipSocket.IsNullOrBlank() || callManagerSvcAddress.IsNullOrBlank()) { daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr); } else { daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr, SIPEndPoint.ParseSIPEndPoint(sipSocket), callManagerSvcAddress, monitorCalls); } Thread daemonThread = new Thread(new ThreadStart(daemon.Start)); daemonThread.Start(); Console.CancelKeyPress += delegate (object sender, ConsoleCancelEventArgs e) { e.Cancel = true; Console.WriteLine("Ctrl-C, clean up and exit..."); daemon.Stop(); m_proxyUp.Set(); }; m_proxyUp.WaitOne(); } else { logger.Debug("SIP App Server Windows Service Starting..."); System.ServiceProcess.ServiceBase[] ServicesToRun; daemon = new SIPAllInOneDaemon(m_serverStorageType, m_serverStorageConnStr); ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service(daemon) }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } } catch (Exception excp) { Console.WriteLine("Exception SIP App Server Main. " + excp.Message); if (isConsole) { Console.WriteLine("press any key to exit..."); Console.ReadLine(); } } }
public static void Install() { if (Installed) return; IDictionary saveState = new Hashtable(); using (AssemblyInstaller installer = new AssemblyInstaller(Assembly.GetExecutingAssembly(), new string[0])) { installer.UseNewContext = true; try { installer.Install(saveState); installer.Commit(saveState); } catch { try { installer.Rollback(saveState); } catch { } throw; } } }
static void Main(string[] args) { try { Console.WriteLine("WebRTC Video Service Console:"); //Windows service has system32 as default working folder, we change the working dir to install dir for file access System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory); logger.Debug("Setting current directory to " + System.AppDomain.CurrentDomain.BaseDirectory); var daemon = new WebRTCDaemon(); if (args != null && args.Length == 1 && args[0] == "-i") { try { using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { inst.Install(state); inst.Commit(state); } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } else if (args != null && args.Length == 1 && args[0] == "-u") { try { using (AssemblyInstaller inst = new AssemblyInstaller(typeof(Program).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { inst.Uninstall(state); } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } else if ((args != null && args.Length == 1 && args[0].StartsWith("-c")) || System.Environment.UserInteractive == true) { Thread daemonThread = new Thread(daemon.Start); daemonThread.Start(); Console.WriteLine("Daemon successfully started."); var mre = new ManualResetEvent(false); mre.WaitOne(); } else { System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] { new WebRTCService(daemon) }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } } catch (Exception excp) { Console.WriteLine("Exception Main. " + excp); } }
private static void Install(bool undo, string[] args) { using (var inst = new AssemblyInstaller(typeof(Collectd).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { if (undo) { inst.Uninstall(state); } else { inst.Install(state); inst.Commit(state); } } catch (Exception) { try { inst.Rollback(state); } catch { } throw; } } }
private void Install(bool install) { try { _installLog.Info(install ? "Installing" : "Uninstalling"); using (var inst = new AssemblyInstaller(typeof (Program).Assembly, null)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { EnsureEveryoneHasPermissionsToWriteToLogFiles(); if (install) { inst.Install(state); inst.Commit(state); } else { inst.Uninstall(state); } } catch { try { inst.Rollback(state); } catch (Exception ex) { _installLog.Error("Error Rolling back"); _installLog.Error(ex.Message); } throw; } } } catch (Exception ex) { ReportError(ex); } }
static void Main(string[] args) { var cancelled = false; var config = args.Where((s) => s.Contains("--config-path=")).SingleOrDefault(); if (!String.IsNullOrEmpty(config)) { var configFileName = config.Split('=')[1]; if (!String.IsNullOrEmpty(configFileName)) { _currentConfigPath = Path.Combine(Directory.GetCurrentDirectory(), configFileName); if (!File.Exists(_currentConfigPath)) throw new FileNotFoundException(String.Format("File {0} is not found in current directory", configFileName)); } } ServiceRunner runner = new ServiceRunner(args, LoadTaskHandlerDescriptors()); if (!runner.Options.IsValid) { Console.WriteLine(String.Format(runner.GetHelp(), System.IO.Path.GetFileName(Environment.GetCommandLineArgs()[0]))); return; } if (runner.Options.RunConsole) // console mode { Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) => { e.Cancel = true; cancelled = true; Logger.Instance.Info("Exiting..."); runner.Dispose(); return; }; runner.Start(); WatchServiceAssemblies(Directory.GetCurrentDirectory(), (fname) => { // Reload the task handlers, not ready yet if (runner.Options.Mode != MSA.Zmq.JsonRpc.ServiceMode.Router) { if (Environment.UserInteractive) { PrintMessage("Reloading task handlers...", true); } runner.Reload(LoadTaskHandlerDescriptors()); } }); if (runner.Options.Mode != ServiceMode.None) while (!cancelled) { } } else { var serviceAction = runner.Options.ServiceAction; if (serviceAction == ServiceAction.Install) { // install the service with arguments AssemblyInstaller installer = new AssemblyInstaller(typeof(Program).Assembly, args); IDictionary state = new Hashtable(); try { installer.UseNewContext = true; if (runner.Options.Mode == ServiceMode.Router || runner.Options.Mode == ServiceMode.MultiWorker || runner.Options.Mode == ServiceMode.Worker || runner.Options.Mode == ServiceMode.Publisher) { // remove the --install-service arg var newArgs = args.Where(s => !s.StartsWith("--install-service")).ToArray(); installer.Installers.Add(new ZMQServiceInstaller(runner.Options.ServiceName, newArgs)); } if (serviceAction == ServiceAction.Install) { installer.Install(state); installer.Commit(state); } } catch (Exception ex) { Logger.Instance.Error(ex); installer.Rollback(state); throw; } finally { installer.Dispose(); } } else if (serviceAction == ServiceAction.Help) { Console.WriteLine(String.Format(runner.GetHelp(), System.IO.Path.GetFileName(Environment.GetCommandLineArgs()[0]))); } else // run the service { ServiceBase.Run(new ZMQService(runner)); } } }
/// <summary> /// Uninstalls a service. /// </summary> /// <param name="assembly">The assembly to install. as a service</param> /// <param name="args">The command line to use when creating a new System.Configuration.Install.InstallContext object for the assembly's installation.</param> /// <returns><c>true</c> if the service was uninstalled; otherwise, <c>false</c>.</returns> public static bool UninstallService(Assembly assembly, string[] args) { using (AssemblyInstaller installer = new AssemblyInstaller(assembly, args)) { IDictionary state = new Hashtable(); installer.UseNewContext = true; try { installer.Uninstall(state); } catch { try { installer.Rollback(state); } catch (Exception ex) { Logger.Error(ex, "Unable to rollback uninstallation."); } return false; } } return true; }