├── .gitattributes
├── .gitignore
├── README.md
└── redis-topshelf
├── .nuget
└── packages.config
├── redis-topshelf.sln
└── redis-topshelf
├── App.config
├── Constants.cs
├── Program.cs
├── Properties
└── AssemblyInfo.cs
├── RedisService.cs
├── install.bat
├── log4net.config
├── obj
└── Debug
│ └── DesignTimeResolveAssemblyReferencesInput.cache
├── packages.config
├── redis-topshelf.csproj
└── uninstall.bat
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows image file caches
2 | Thumbs.db
3 | ehthumbs.db
4 |
5 | # Folder config file
6 | Desktop.ini
7 |
8 | # Recycle Bin used on file shares
9 | $RECYCLE.BIN/
10 |
11 | # Windows Installer files
12 | *.cab
13 | *.msi
14 | *.msm
15 | *.msp
16 |
17 | # =========================
18 | # Operating System Files
19 | # =========================
20 |
21 | # OSX
22 | # =========================
23 |
24 | .DS_Store
25 | .AppleDouble
26 | .LSOverride
27 |
28 | # Icon must ends with two \r.
29 | Icon
30 |
31 | # Thumbnails
32 | ._*
33 |
34 | # Files that might appear on external disk
35 | .Spotlight-V100
36 | .Trashes
37 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | redis-topshelf
2 | ==============
3 | redis-topshelf is a simple windows service installer package via using top-shelf(http://topshelf-project.com/) to wrap the redis console window as a windows service.
4 |
5 | How to install redis windows service by redis-topshelf ?
6 |
7 | 1.Edit the config file redis-topshelf.exe.config.
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | The config key description as below:
18 | redis.service.name: the windows sevice name.
19 | redis.service.displayname: the windows service display name.
20 | redis.service.description: the windows service desription.
21 | redis.server: the redis server console file name.
22 | redis.conf: the redis server config file name.
23 | redis.cli: the redis client file name.
24 | redis.path:the redis root directory.
25 |
26 | One more important thing is to assign the key "redis.path"...
27 |
28 | 2.Running the bat file install.bat to install the windows service.
29 | Uninstalling the windows service using the file uninstall.bat.
30 |
--------------------------------------------------------------------------------
/redis-topshelf/.nuget/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/redis-topshelf/redis-topshelf.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "redis-topshelf", "redis-topshelf\redis-topshelf.csproj", "{2B7C3855-9784-48B0-823D-C6A301E6E4E1}"
5 | EndProject
6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{2BEA73CA-280B-49A8-922A-27AFB3E5B663}"
7 | ProjectSection(SolutionItems) = preProject
8 | .nuget\packages.config = .nuget\packages.config
9 | EndProjectSection
10 | EndProject
11 | Global
12 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
13 | Debug|Any CPU = Debug|Any CPU
14 | Release|Any CPU = Release|Any CPU
15 | EndGlobalSection
16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
17 | {2B7C3855-9784-48B0-823D-C6A301E6E4E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18 | {2B7C3855-9784-48B0-823D-C6A301E6E4E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
19 | {2B7C3855-9784-48B0-823D-C6A301E6E4E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
20 | {2B7C3855-9784-48B0-823D-C6A301E6E4E1}.Release|Any CPU.Build.0 = Release|Any CPU
21 | EndGlobalSection
22 | GlobalSection(SolutionProperties) = preSolution
23 | HideSolutionNode = FALSE
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/redis-topshelf/redis-topshelf/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/redis-topshelf/redis-topshelf/Constants.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace redis_topshelf
7 | {
8 | public class Constants
9 | {
10 | public static readonly string REDIS_SERVICE_NAME = "redis.service.name";
11 | public static readonly string REDIS_SERVICE_DISPALYNAME = "redis.service.displayname";
12 | public static readonly string REDIS_SERVICE_DESCRIPTION = "redis.service.description";
13 | public static readonly string REDIS_SERVER = "redis.server";
14 | public static readonly string REDIS_CONF = "redis.conf";
15 | public static readonly string REDIS_CLI = "redis.cli";
16 | public static readonly string REDIS_PAHT = "redis.path";
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/redis-topshelf/redis-topshelf/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Configuration;
6 | using Topshelf;
7 | using Topshelf.Logging;
8 |
9 | namespace redis_topshelf
10 | {
11 | class Program
12 | {
13 | static string _ServiceName = ConfigurationManager.AppSettings[Constants.REDIS_SERVICE_NAME];
14 | static string _ServiceDisplayName = ConfigurationManager.AppSettings[Constants.REDIS_SERVICE_DISPALYNAME];
15 | static string _ServiceDescription = ConfigurationManager.AppSettings[Constants.REDIS_SERVICE_DESCRIPTION];
16 | static int Main(string[] args)
17 | {
18 | return (int)HostFactory.Run(x =>
19 | {
20 | x.UseLog4Net("log4net.config");
21 |
22 | x.RunAsLocalSystem();
23 | x.SetServiceName(_ServiceName);
24 | x.SetDisplayName(_ServiceDisplayName);
25 | x.SetDescription(_ServiceDescription);
26 |
27 | x.Service();
28 |
29 | x.EnableServiceRecovery(r => { r.RestartService(1); });
30 | });
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/redis-topshelf/redis-topshelf/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("redis-topshelf")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("redis-topshelf")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("dbf5e511-4b78-403a-b57b-762ab30c1027")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/redis-topshelf/redis-topshelf/RedisService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading;
6 | using System.Configuration;
7 | using System.IO;
8 | using System.Diagnostics;
9 | using Topshelf;
10 | using Topshelf.Logging;
11 |
12 | namespace redis_topshelf
13 | {
14 | public class RedisService : ServiceControl
15 | {
16 | private readonly LogWriter _log = HostLogger.Get();
17 | private string _redisPath = ConfigurationManager.AppSettings[Constants.REDIS_PAHT];
18 | private string _redisServer, _redisConf, _redisCli;
19 | private int _port;
20 | private Process _redisServerConsole;
21 | bool VerifyArgumnets()
22 | {
23 | if (!Directory.Exists(_redisPath))
24 | {
25 | _log.ErrorFormat("Redis directory not found->{0}", _redisPath);
26 | return false;
27 | }
28 | _redisServer = Path.Combine(_redisPath, ConfigurationManager.AppSettings[Constants.REDIS_SERVER]);
29 | _redisConf = Path.Combine(_redisPath, ConfigurationManager.AppSettings[Constants.REDIS_CONF]);
30 | _redisCli = Path.Combine(_redisPath, ConfigurationManager.AppSettings[Constants.REDIS_CLI]);
31 |
32 | _port = FindPort(_redisConf);
33 |
34 | return true;
35 | }
36 | public bool Start(HostControl hostControl)
37 | {
38 | if (!VerifyArgumnets()) return false;
39 |
40 | _log.Info("RedisService Starting...");
41 |
42 | try
43 | {
44 | ProcessStartInfo cfg = new ProcessStartInfo(_redisServer);
45 | cfg.UseShellExecute = false;
46 | cfg.Arguments = Path.GetFileName(_redisConf);
47 | cfg.WorkingDirectory = _redisPath;
48 | using (_redisServerConsole = new Process { StartInfo = cfg })
49 | {
50 | _redisServerConsole.Start();
51 | }
52 | }
53 | catch (Exception ex)
54 | {
55 | _log.ErrorFormat("Starting redis console server occured exception:{0}", ex);
56 | return false;
57 | }
58 |
59 | _log.Info("RedisService Started");
60 | return true;
61 | }
62 |
63 | public bool Stop(HostControl hostControl)
64 | {
65 | if (_redisServerConsole != null)
66 | {
67 | try
68 | {
69 | //using reids command "shutdown" to close the server.
70 | ProcessStartInfo cfg = new ProcessStartInfo(_redisCli);
71 | cfg.UseShellExecute = false;
72 | cfg.Arguments = string.Format(" -p {0} shutdown", _port);
73 | cfg.WorkingDirectory = _redisPath;
74 | using (var redisClient = new Process { StartInfo = cfg })
75 | {
76 | redisClient.Start();
77 | }
78 | }
79 | catch (Exception ex)
80 | {
81 | _log.ErrorFormat("Using command -shutdown to close server occured exception:{0}", ex);
82 | return false;
83 | }
84 |
85 | }
86 |
87 | Thread.Sleep(500);
88 |
89 | _log.Info("RedisService Stopped");
90 | return true;
91 | }
92 |
93 | private int FindPort(string conf)
94 | {
95 | using (var reader = new StreamReader(conf))
96 | {
97 | string line;
98 | while ((line = reader.ReadLine()) != null)
99 | if (line.IndexOf("port") == 0)
100 | return int.Parse(line.Substring(5, line.Length - 5));
101 | }
102 | return 6379;
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/redis-topshelf/redis-topshelf/install.bat:
--------------------------------------------------------------------------------
1 | redis-topshelf.exe install
2 | redis-topshelf.exe start
3 | pause
--------------------------------------------------------------------------------
/redis-topshelf/redis-topshelf/log4net.config:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/redis-topshelf/redis-topshelf/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/icsharp/redis-topshelf/ea483b1e7d63836ab34dc7b0308125037e13c95c/redis-topshelf/redis-topshelf/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------
/redis-topshelf/redis-topshelf/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/redis-topshelf/redis-topshelf/redis-topshelf.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {2B7C3855-9784-48B0-823D-C6A301E6E4E1}
8 | Exe
9 | Properties
10 | redis_topshelf
11 | redis-topshelf
12 | v3.5
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 | false
25 |
26 |
27 | AnyCPU
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 | false
35 |
36 |
37 |
38 | ..\packages\log4net.2.0.3\lib\net35-full\log4net.dll
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | ..\packages\Topshelf.3.1.3\lib\net35\Topshelf.dll
49 |
50 |
51 | ..\packages\Topshelf.Log4Net.3.1.3\lib\net35\Topshelf.Log4Net.dll
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | PreserveNewest
64 |
65 |
66 | PreserveNewest
67 |
68 |
69 |
70 | PreserveNewest
71 |
72 |
73 |
74 |
75 | False
76 | .NET Framework 3.5 SP1 Client Profile
77 | false
78 |
79 |
80 | False
81 | .NET Framework 3.5 SP1
82 | true
83 |
84 |
85 |
86 |
93 |
--------------------------------------------------------------------------------
/redis-topshelf/redis-topshelf/uninstall.bat:
--------------------------------------------------------------------------------
1 | redis-topshelf.exe stop
2 | redis-topshelf.exe uninstall
3 | pause
--------------------------------------------------------------------------------