-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Watchog to try to recover from outages
- Loading branch information
Showing
6 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Ditto | ||
.Net Core application to mirror messages between IRC and Discord. | ||
|
||
## Projects | ||
|
||
* Ditto - the main application | ||
* IrcDotNet - Slightly customized version of [IrcDotNet](https://github.com/IrcDotNet/IrcDotNet). | ||
* Watchog - Starts Ditto and watches to make sure it's online, restarting it if necessary. This is needed because on some systems, Ditto dies so hard its error handling doesn't kick in, whenever there's a Discord outage for any length. | ||
|
||
## Usage | ||
1. Create the json settings files. Instructions coming eventually. | ||
2. Run startup.sh | ||
3. Run shutdown.sh to shutdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
|
||
namespace Watchog | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
try | ||
{ | ||
if (args.Length < 2) | ||
{ | ||
Console.WriteLine("Usage: Watchog <filename> [args]"); | ||
return; | ||
} | ||
|
||
Console.WriteLine($"[{DateTime.Now.ToString()}] Watchog started."); | ||
|
||
var p = new Process(); | ||
|
||
Console.CancelKeyPress += delegate | ||
{ | ||
Console.WriteLine($"[{DateTime.Now.ToString()}] Received Control+C. Closing program."); | ||
p.Close(); | ||
if (!p.HasExited) | ||
{ | ||
Console.WriteLine($"[{DateTime.Now.ToString()}] Program not running. Waiting for up to 10 seconds."); | ||
p.WaitForExit(10 * 1000); | ||
if (!p.HasExited) | ||
{ | ||
p.Kill(); | ||
Console.WriteLine($"[{DateTime.Now.ToString()}] Killed program."); | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"[{DateTime.Now.ToString()}] Program exited on its own. Program not killed."); | ||
} | ||
} | ||
Console.WriteLine($"[{DateTime.Now.ToString()}] Watchog exiting."); | ||
}; | ||
|
||
if (File.Exists(args[0])) | ||
{ | ||
while (true) | ||
{ | ||
p = new Process(); | ||
p.StartInfo.FileName = args[0]; | ||
p.StartInfo.Arguments = args[1]; | ||
p.WaitForExit(); | ||
p.Dispose(); | ||
p = null; | ||
|
||
// Program exited, and Watchog should restart | ||
Console.WriteLine($"[{DateTime.Now.ToString()}] Program exited. Restarting..."); | ||
} | ||
} | ||
else | ||
{ | ||
throw new FileNotFoundException("Can't find the file on disk", args[0]); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine($"[{DateTime.Now.ToString()}] Watchog encountered an exception: {ex.ToString()}"); | ||
throw; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<OutputPath>..\Ditto\bin\Debug\netcoreapp2.0\</OutputPath> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<OutputPath>..\Ditto\bin\Release\netcoreapp2.0\</OutputPath> | ||
</PropertyGroup> | ||
|
||
</Project> |