-
Notifications
You must be signed in to change notification settings - Fork 6
/
SolrService.cs
59 lines (53 loc) · 2.18 KB
/
SolrService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Configuration;
using System.Diagnostics;
using System.ServiceProcess;
using Guardian.Configuration;
using System.IO;
namespace SolrWindowsService
{
internal class SolrService
{
static Process process = new Process();
public void Start()
{
Log("service starting");
try
{
process.StartInfo.FileName = ConfigurationHelper.GetConfigValue("JavaExecutable");
var port = ConfigurationHelper.GetConfigValueOrDefault("Port", 8983);
var workingDirectory = ConfigurationHelper.GetConfigValue("WorkingDirectory");
var jarFile = string.Format(@"{0}\start.jar", workingDirectory);
if (!File.Exists(jarFile))
throw new ConfigurationErrorsException("Couldn't find the start.jar file at " + jarFile);
var solrHome = ConfigurationHelper.GetConfigValueOrDefault("Solr.Home", "solr");
var commandLineArgs = ConfigurationHelper.GetConfigValueOrDefault("CommandLineArgs", "");
process.StartInfo.WorkingDirectory = workingDirectory;
process.StartInfo.Arguments = string.Format(@"-Dsolr.solr.home={0} -Djetty.port={3} {1} -jar {2}", solrHome, commandLineArgs, jarFile, port);
process.StartInfo.UseShellExecute = ConfigurationHelper.GetConfigValueOrDefault("ShowConsole", false);
var result = process.Start();
Log("result of batch start: " + result);
//process.WaitForExit();
}
catch (Exception ex)
{
Log("An error occurred: " + ex.Message);
throw;
}
}
protected void Log(string message)
{
const string source = "SolrService";
const string log = "Application";
if (!EventLog.SourceExists(source))
EventLog.CreateEventSource(source, log);
//EventLog.WriteEntry(message);
}
public void Stop()
{
//Log("stopping service");
process.Kill();
process.Dispose();
}
}
}