forked from xkjyeah/openvpnserv2
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathService.cs
More file actions
49 lines (43 loc) · 1.54 KB
/
Service.cs
File metadata and controls
49 lines (43 loc) · 1.54 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.IO;
using System.Diagnostics;
using System.ServiceProcess;
using System.Threading;
namespace OpenVpn
{
public class OpenVpnService : ServiceBase
{
public static string DefaultServiceName = "OpenVpnService";
private OpenVPNServiceRunner _serviceRunner;
private EventLog _eventLog;
public OpenVpnService()
{
this.ServiceName = DefaultServiceName;
this.CanStop = true;
this.CanPauseAndContinue = false;
// N.B. if OpenVPN always dies when suspending, then this is unnecessary
// However if there is some kind of stuck state where OpenVPN.exe hangs
// after resuming, then this will help
this.CanHandlePowerEvent = false;
this.AutoLog = true;
_eventLog = new EventLog();
// this assumes that OpenVPNService event source has been created, since it requires elevated privileges
_eventLog.Source = this.ServiceName;
_eventLog.Log = "Application";
_serviceRunner = new OpenVPNServiceRunner(_eventLog); // Decoupled service logic
}
protected override void OnStart(string[] args)
{
_serviceRunner.Start(args);
}
protected override void OnStop()
{
RequestAdditionalTime(3000);
_serviceRunner.Stop();
}
}
}