Optimization & bugfixing

This commit is contained in:
2016-03-22 17:14:11 +01:00
parent 8a61a544c3
commit 29b0f80e22
32 changed files with 1791 additions and 144 deletions
+7 -1
View File
@@ -3,10 +3,16 @@ all:
server: server:
xbuild Ntp.Analyzer.sln /property:Configuration=Server xbuild Ntp.Analyzer.sln /property:Configuration=Server
cp bin/ntpa/Debug/* bin/
cp bin/ntpav/Debug/* bin/
cp bin/ntpac/Debug/* bin/
rm -Rf bin/ntpa
rm -Rf bin/ntpav
rm -Rf bin/ntpac
release: release:
xbuild Ntp.Analyzer.sln /property:Configuration=Release xbuild Ntp.Analyzer.sln /property:Configuration=Release
rm -R bin
clean: clean:
xbuild Ntp.Analyzer.sln /t:clean xbuild Ntp.Analyzer.sln /t:clean
rm -Rf bin
+2 -5
View File
@@ -47,10 +47,8 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<UseVSHostingProcess>true</UseVSHostingProcess> <UseVSHostingProcess>true</UseVSHostingProcess>
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
<DocumentationFile>bin\$(TargetFrameworkVersion)\Debug\MySql.Data.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<BaseOutputPath>$(TargetFrameworkVersion)\</BaseOutputPath> <BaseOutputPath>$(TargetFrameworkVersion)\</BaseOutputPath>
<BaseIntermediateOutputPath>obj\$(TargetFrameworkVersion)\</BaseIntermediateOutputPath> <BaseIntermediateOutputPath>obj\$(TargetFrameworkVersion)\</BaseIntermediateOutputPath>
@@ -60,7 +58,6 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\Release\MySql.Data.XML</DocumentationFile>
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -255,8 +252,8 @@
</PostBuildEvent> </PostBuildEvent>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath> <OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>1</WarningLevel>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
+1 -1
View File
@@ -29,7 +29,7 @@
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath> <OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
+8 -3
View File
@@ -8,7 +8,7 @@
<ProjectGuid>{6A635537-E5E9-493E-8B89-E0E5EBB64E72}</ProjectGuid> <ProjectGuid>{6A635537-E5E9-493E-8B89-E0E5EBB64E72}</ProjectGuid>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<RootNamespace>Ntp.Analyzer.Cli</RootNamespace> <RootNamespace>Ntp.Analyzer.Cli</RootNamespace>
<StartupObject>Ntp.Analyzer.Cli.MainClass</StartupObject> <StartupObject>Ntp.Analyzer.Cli.Program</StartupObject>
<ReleaseVersion>0.3</ReleaseVersion> <ReleaseVersion>0.3</ReleaseVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
@@ -29,17 +29,18 @@
<AssemblyName>ntpa</AssemblyName> <AssemblyName>ntpa</AssemblyName>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath> <OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AssemblyName>Ntp.Analyzer.Cli</AssemblyName> <AssemblyName>Ntp.Analyzer.Cli</AssemblyName>
<LangVersion>4</LangVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AssemblyInfo.cs" /> <Compile Include="AssemblyInfo.cs" />
<Compile Include="Program.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>
@@ -63,5 +64,9 @@
<Project>{909C8729-ED63-4603-85EA-34A1FC4D63D9}</Project> <Project>{909C8729-ED63-4603-85EA-34A1FC4D63D9}</Project>
<Name>Ntp.Analyzer.Log</Name> <Name>Ntp.Analyzer.Log</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\Ntp.Config\Ntp.Config.csproj">
<Project>{43A1A769-6ED9-4AE1-821A-43F97814968C}</Project>
<Name>Ntp.Config</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
</Project> </Project>
+124
View File
@@ -0,0 +1,124 @@
//
// Main.cs
//
// Author:
// Carsten Sonne Larsen <cs@innolan.dk>
//
// Copyright (c) 2013-2016 Carsten Sonne Larsen
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Globalization;
using System.IO;
using System.Threading;
using Ntp.Analyzer.Log;
using Ntp.Analyzer.Process;
using Ntp.System;
namespace Ntp.Analyzer.Cli
{
/// <summary>
/// Entry point for CLI application.
/// </summary>
public static class Program
{
/// <summary>
/// The entry point of the program, where the program control starts and ends.
/// </summary>
/// <param name="args">The command-line arguments.</param>
public static void Main (string[] args)
{
// Neutralize.
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
string name = "default";
string tempDir = null;
string configFile = null;
string pidFile = null;
bool exit = false;
OptionSet p = new OptionSet () { { "h|?|help", v => {
ShowUsage ();
exit = true;
}
}, { "daemon=", v => {
name = v;
}
}, { "config=", v => {
configFile = v;
}
}, { "writepid=", v => {
pidFile = v;
}
}, { "temp=", v => {
tempDir = v;
}
}
};
String[] rem = p.Parse (args).ToArray ();
if (exit) {
return;
} else if (rem.Length > 0) {
Console.WriteLine ("Unknown option: " + rem [0]);
return;
} else if (configFile == null) {
Console.WriteLine ("Please specify configuration file with option --config");
return;
} else if (tempDir == null) {
Console.WriteLine ("Please specify temporary folder with option --temp");
return;
}
// Initialize system settings
ShellCommand.WorkingDirectory = tempDir;
int pid = ProcessInfo.ProcessId;
if (pidFile != null) {
try {
File.WriteAllText (pidFile, pid.ToString ());
} catch (Exception e) {
Console.WriteLine ("Failed to write pid file: " + e.Message);
return;
}
}
try {
Main main = new Main (configFile, pid, name);
main.Start ();
} catch (Exception e) {
Console.WriteLine (e.Message);
}
if (pidFile != null) {
try {
File.Delete (pidFile);
} catch {
}
}
}
private static void ShowUsage()
{
Console.WriteLine("NTP Analyzer Daemon " + VersionInfo.Text);
Console.WriteLine("Usage: ntpa --config file --temp dir [--writepid file] [--daemon name]");
}
}
}
+1 -2
View File
@@ -22,7 +22,6 @@
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath> <OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
@@ -30,7 +29,7 @@
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath> <OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
+1 -1
View File
@@ -30,7 +30,7 @@
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath> <OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
@@ -30,7 +30,7 @@
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath> <OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
+4 -6
View File
@@ -50,20 +50,20 @@ namespace Ntp.Analyzer.Process
public sealed class Initializer public sealed class Initializer
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Ntp.Analyzer.Process.Runner" /> class. /// Initializes a new instance of the <see cref="Ntp.Analyzer.Process.Initializer" /> class.
/// </summary> /// </summary>
/// <param name="configFile">Config file to use.</param> /// <param name="configFile">Config file to use.</param>
/// <param name="pid">Process ID. Only used for logging.</param> /// <param name="pid">Process ID. Only used for logging.</param>
/// <param name="name">Name of process ID. Used for shutting down.</param> /// <param name="name">Name of process ID. Used for shutting down.</param>
public Initializer (string version, string configFile, int pid, string name) public Initializer (string configFile, int pid, string name)
{ {
this.version = version;
this.configFile = configFile; this.configFile = configFile;
this.pid = pid; this.pid = pid;
this.name = name; this.name = name;
nodes = new List<IRequest> (); nodes = new List<IRequest> ();
listeners = new List<Listener> (); listeners = new List<Listener> ();
this.version = VersionInfo.Number;
} }
private readonly string version; private readonly string version;
@@ -166,6 +166,7 @@ namespace Ntp.Analyzer.Process
log.WriteLine ("NTP Analyzer " + version + " started.", Severity.Notice); log.WriteLine ("NTP Analyzer " + version + " started.", Severity.Notice);
log.WriteLine ("Using configuration: " + configFile, Severity.Notice); log.WriteLine ("Using configuration: " + configFile, Severity.Notice);
log.WriteLine ("Running with pid: " + pid, Severity.Notice); log.WriteLine ("Running with pid: " + pid, Severity.Notice);
log.WriteLine ("Instance name: " + name, Severity.Notice);
return true; return true;
} }
@@ -182,9 +183,6 @@ namespace Ntp.Analyzer.Process
ApplicationState.Config = config; ApplicationState.Config = config;
ApplicationState.ConfigFile = configFile; ApplicationState.ConfigFile = configFile;
ApplicationState.Log = log; ApplicationState.Log = log;
// Initialize system settings
ShellCommand.WorkingDirectory = "/tmp";
} }
private void InitializeDatabase() private void InitializeDatabase()
+1 -5
View File
@@ -32,22 +32,18 @@ namespace Ntp.Analyzer.Process
{ {
public Main (string configFile, int pid, string name) public Main (string configFile, int pid, string name)
{ {
// Also update solution version.
version = "0.3a";
this.configFile = configFile; this.configFile = configFile;
this.pid = pid; this.pid = pid;
this.name = name; this.name = name;
} }
private readonly string version;
private readonly string configFile; private readonly string configFile;
private readonly int pid; private readonly int pid;
private readonly string name; private readonly string name;
public void Start () public void Start ()
{ {
Initializer i = new Initializer (version, configFile, pid, name); Initializer i = new Initializer (configFile, pid, name);
i.Run (); i.Run ();
if (!i.Ready) { if (!i.Ready) {
@@ -37,7 +37,6 @@
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="Mono.Posix" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
@@ -20,7 +20,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole> <Externalconsole>true</Externalconsole>
<Commandlineparameters>~/code/ntpa/example/ntpa.stat.conf</Commandlineparameters> <Commandlineparameters>~/code/ntpa/example/ntpa.web.conf</Commandlineparameters>
<AssemblyName>ntpav</AssemblyName> <AssemblyName>ntpav</AssemblyName>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
@@ -33,7 +33,7 @@
<AssemblyName>ntpav</AssemblyName> <AssemblyName>ntpav</AssemblyName>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath> <OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AssemblyName>Ntp.Analyzer.Validate.Cli</AssemblyName> <AssemblyName>Ntp.Analyzer.Validate.Cli</AssemblyName>
@@ -55,5 +55,9 @@
<Project>{43A1A769-6ED9-4AE1-821A-43F97814968C}</Project> <Project>{43A1A769-6ED9-4AE1-821A-43F97814968C}</Project>
<Name>Ntp.Config</Name> <Name>Ntp.Config</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\Ntp.System\Ntp.System.csproj">
<Project>{A98DB601-2993-4181-A573-5FCCC5E954C1}</Project>
<Name>Ntp.System</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
</Project> </Project>
+42 -19
View File
@@ -4,7 +4,7 @@
// Author: // Author:
// Carsten Sonne Larsen <cs@innolan.dk> // Carsten Sonne Larsen <cs@innolan.dk>
// //
// Copyright (c) 2013 Carsten Sonne Larsen // Copyright (c) 2013-2016 Carsten Sonne Larsen
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@@ -31,6 +31,7 @@ using System.Threading;
using Ntp.Analyzer.Config; using Ntp.Analyzer.Config;
using Ntp.Analyzer.Export; using Ntp.Analyzer.Export;
using Ntp.Config; using Ntp.Config;
using Ntp.System;
namespace Ntp.Analyzer.Validate.Cli namespace Ntp.Analyzer.Validate.Cli
{ {
@@ -42,31 +43,53 @@ namespace Ntp.Analyzer.Validate.Cli
{ {
// Neutralize. // Neutralize.
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
bool exit = false;
bool verbose = false;
if (args.Length == 0 || args.Length > 2) { Ntp.System.OptionSet p =
ShowUsage (); new Ntp.System.OptionSet () { { "h|?|help", v => {
ShowUsage ();
exit = true;
}
}, { "v|verbose", v => {
verbose = true;
}
}
};
String[] rem = p.Parse (args).ToArray ();
if (exit) {
return;
} else if (rem.Length > 1) {
Console.WriteLine ("Unknown option: " + rem [1]);
return;
} else if (rem.Length == 0) {
Console.WriteLine ("Please specify configuration file");
return;
}
Configuration config = null;
try {
config = LoadConfig (args [0]);
} catch (Exception e) {
Console.WriteLine ("Unexpected error while loading configuration file: " + e.Message);
return; return;
} }
if (args.Length == 1 && args[0] == "help") { if (config == null)
ShowUsage ();
return; return;
}
string configFile = args [0];
Configuration config = LoadConfig (configFile);
if (config == null) {
return;
}
Console.WriteLine ("Parsed config ..."); Console.WriteLine ("Parsed config ...");
if (verbose)
if (args.Length == 2 && args [1] == "verbose") {
Console.WriteLine (config); Console.WriteLine (config);
}
TestFilesystem (config); try {
TestFilesystem (config);
} catch (Exception e) {
Console.WriteLine ("Unexpected error while testing filesystem: " + e.Message);
return;
}
if (!anyErrors) { if (!anyErrors) {
Console.WriteLine ("Filesystem configuration seems valid ..."); Console.WriteLine ("Filesystem configuration seems valid ...");
@@ -132,8 +155,8 @@ namespace Ntp.Analyzer.Validate.Cli
private static void ShowUsage() private static void ShowUsage()
{ {
Console.WriteLine ("NTP Analyzer validator tool."); Console.WriteLine ("NTP Analyzer validator tool " + VersionInfo.Text);
Console.WriteLine ("Usage: ntpav configuration [verbose]"); Console.WriteLine ("Usage: ntpav [--verbose] configuration");
} }
} }
} }
@@ -98,8 +98,8 @@ namespace Ntp.Analyzer.Config.Navigation
string itemName = GetOptionConfigName(options, "Item", "Item", true); string itemName = GetOptionConfigName(options, "Item", "Item", true);
string type = GetOptionString(options, "Type", "Item", false, "Link").ToLower(); string type = GetOptionString(options, "Type", "Item", false, "Link").ToLower();
string caption = GetOptionString(options, "Caption", "Item", true); string caption = GetOptionString(options, "Caption", "Item", false);
string link = GetOptionString(options, "Link", "Item", true); string link = GetOptionString(options, "Link", "Item", false);
string page = GetOptionString(options, "Page", "Item", false); string page = GetOptionString(options, "Page", "Item", false);
string dropdown = GetOptionString(options, "Dropdown", "Item", false); string dropdown = GetOptionString(options, "Dropdown", "Item", false);
ILinkable linkable = null; ILinkable linkable = null;
+1 -1
View File
@@ -30,7 +30,7 @@
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath> <OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
+1 -1
View File
@@ -30,7 +30,7 @@
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath> <OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
+1 -1
View File
@@ -28,7 +28,7 @@
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath> <OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
+1 -1
View File
@@ -31,7 +31,7 @@
<AssemblyName>ntpac</AssemblyName> <AssemblyName>ntpac</AssemblyName>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath> <OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AssemblyName>Ntp.Monitor.Cli</AssemblyName> <AssemblyName>Ntp.Monitor.Cli</AssemblyName>
+1 -1
View File
@@ -30,7 +30,7 @@
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath> <OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
+1 -1
View File
@@ -30,7 +30,7 @@
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath> <OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
+1 -1
View File
@@ -32,7 +32,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath> <OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
+1 -1
View File
@@ -94,7 +94,7 @@ namespace Ntp.Process
} }
if (!otherActive) { if (!otherActive) {
log.WriteLine ("No other nodes active. Activting node.", Severity.Debug); //log.WriteLine ("No other nodes active. Activting node.", Severity.Debug);
try { try {
scheduler.RunOneCycle (); scheduler.RunOneCycle ();
+1 -1
View File
@@ -29,7 +29,7 @@
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath> <OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
+35 -70
View File
@@ -23,104 +23,69 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.IO;
using Ntp.Analyzer.Log; using Ntp.Analyzer.Log;
#if __MonoCS__
using Mono.Unix;
using Mono.Unix.Native;
#else
using System.Threading;
#endif
namespace Ntp.System namespace Ntp.System
{ {
#if __MonoCS__
using Mono.Unix;
public static class InterLock public static class InterLock
{ {
public static bool Release (string name, LogBase log) #if __MonoCS__
{
using (Socket socket = new Socket (AddressFamily.Unix, SocketType.Stream, ProtocolType.IP)) {
try {
socket.Connect (new UnixEndPoint (name));
byte[] bytes = Encoding.UTF8.GetBytes ("RELEASE");
socket.Send (bytes);
socket.Close ();
} catch (Exception e) {
log.WriteLine ("Could not release lock.", Severity.Error);
log.WriteLine (e, Severity.Trace);
return false;
}
}
return true;
}
public static bool Wait (string name, LogBase log) public static bool Wait (string name, LogBase log)
{ {
byte[] buf = new byte[64]; UnixSignal[] signals = new UnixSignal[]{
UnixEndPoint endPoint = null; new UnixSignal (Signum.SIGTERM)
};
using (Socket socket = new Socket (AddressFamily.Unix, SocketType.Stream, ProtocolType.IP)) { try {
try { UnixSignal.WaitAny (signals, -1);
// Unix socket "hack" log.WriteLine ("Received kill signal.", Severity.Notice);
endPoint = new UnixEndPoint (name); } catch (Exception e) {
if (File.Exists (endPoint.Filename)) { log.WriteLine ("Error in Signum handling.", Severity.Error);
File.Delete (endPoint.Filename); log.WriteLine (e, Severity.Trace);
} return false;
socket.Bind (endPoint);
socket.Listen (5);
Socket sock = socket.Accept ();
sock.Receive (buf);
sock.Close ();
} catch (Exception e) {
log.WriteLine ("Could not create socket.", Severity.Error);
log.WriteLine (e, Severity.Trace);
return false;
} finally {
if (socket != null && socket.IsBound) {
socket.Close ();
}
if (endPoint != null && File.Exists (endPoint.Filename)) {
File.Delete (endPoint.Filename);
}
}
} }
return true; return true;
} }
}
#else #else
public static class InterLock public static bool Release (string name, LogBase log)
{
public static string Release (string name)
{ {
try { try {
EventWaitHandle handle = EventWaitHandle.OpenExisting (name); EventWaitHandle handle = EventWaitHandle.OpenExisting (name);
handle.Set (); handle.Set ();
return true;
} catch (Exception e) { } catch (Exception e) {
return e.Message; log.WriteLine ("Error in mutex handling.", Severity.Error);
log.WriteLine (e, Severity.Trace);
return false;
} }
return null;
} }
public static string Wait (string name) public static bool Wait (string name, LogBase log)
{ {
try { try {
EventWaitHandle handle = new EventWaitHandle ( EventWaitHandle handle = new EventWaitHandle (
false, EventResetMode.ManualReset, false, EventResetMode.ManualReset,
name); name);
handle.WaitOne (); handle.WaitOne ();
return true;
} catch (Exception e) { } catch (Exception e) {
return e.Message; log.WriteLine ("Error in mutex handling.", Severity.Error);
log.WriteLine (e, Severity.Trace);
return false;
} }
return null;
} }
}
#endif #endif
} }
}
+3 -1
View File
@@ -30,7 +30,7 @@
<ConsolePause>false</ConsolePause> <ConsolePause>false</ConsolePause>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath> <OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
@@ -43,6 +43,8 @@
<Compile Include="ShellCommand.cs" /> <Compile Include="ShellCommand.cs" />
<Compile Include="InterLock.cs" /> <Compile Include="InterLock.cs" />
<Compile Include="ProcessInfo.cs" /> <Compile Include="ProcessInfo.cs" />
<Compile Include="Options.cs" />
<Compile Include="VersionInfo.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>
File diff suppressed because it is too large Load Diff
+13 -10
View File
@@ -23,22 +23,25 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System;
using System.Runtime.InteropServices; #if __MonoCS__
using Mono.Unix.Native;
#else
System.Diagnostics
#endif
namespace Ntp.System namespace Ntp.System
{ {
public class ProcessInfo public class ProcessInfo
{ {
public static int ProcessId { public static int ProcessId {
get { return getpid (); } get {
#if __MonoCS__
return Syscall.getpid ();
#else
return Process.GetCurrentProcess().Id;
#endif
}
} }
#if __MonoCS__
[DllImport ("libc")]
private static extern int getpid ();
#else
private static int getpid () { return 0; }
#endif
} }
} }
+1 -1
View File
@@ -81,4 +81,4 @@ namespace Ntp.System
return proc.StandardOutput; return proc.StandardOutput;
} }
} }
} }
+36
View File
@@ -0,0 +1,36 @@
//
// VersionInfo.cs
//
// Author:
// Carsten Sonne Larsen <cs@innolan.dk>
//
// Copyright (c) 2016 Carsten Sonne Larsen
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace Ntp.System
{
public static class VersionInfo
{
public static readonly string Number = "0.3a1";
public static readonly string Text = "v" + Number;
}
}
+1 -1
View File
@@ -18,7 +18,7 @@ Database {
# Password for the user # Password for the user
Pass xxxx Pass xxxx
# When set to 1 all tables and data are automatically created. # Set to 1 to automatically create all tables and data.
Create 1 Create 1
} }
+22 -3
View File
@@ -4,10 +4,23 @@
# Connection parameters to MySQL database instance. # Connection parameters to MySQL database instance.
Database { Database {
Host localhost # Address of sql server
Host 127.0.0.1
# Port of sql server. Leave empty to use default.
#Port 2567
# Name of database
Name ntpa Name ntpa
# Database username
User ntpau User ntpau
Pass xxx
# Password for the user
Pass xxxx
# Set to 1 to automatically create all tables and data.
Create 1
} }
# OPTIONAL # OPTIONAL
@@ -20,7 +33,13 @@ Log {
Server { Server {
# Primary key in table 'host' # Primary key in table 'host'
HostID 1 HostID 1
# Address queried by ntpq and ntpdc
HostAddress ntp1.domain.org
# The utility used to query ntpd. Use ntpdc for old hosts.
HostType ntpq
# Domain name of hosting NTP server # Domain name of hosting NTP server
HostAddress ntp1.domain.org HostAddress ntp1.domain.org
+66
View File
@@ -0,0 +1,66 @@
#!/bin/sh
#
# $FreeBSD
#
# PROVIDE: ntpa
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable ntpa:
# ntpa_enable (bool): Set to "NO" by default.
# Set it to "YES" to enable munin-node
# ntpa_config (path): Set to "/usr/local/etc/ntpa/ntpa.conf" by default.
# ntpa_tempdir (path): Set to "/tmp/" by default.
#
# Run additional instances of ntpa with:
# Use ln -s ntpa ntpa_graph
#
. /etc/rc.subr
name="$0"
name="${name##*/}"
rcvar=${name}_enable
start_cmd="ntpa_start"
stop_cmd="ntpa_stop"
load_rc_config ${name}
MONO="/usr/local/bin/mono"
ntpa_start()
{
if [ -f ${pidfile} ]; then
rc_pid=`cat ${pidfile}`
echo 1>&2 "${name} already running? (pid=$rc_pid)."
return 1
else
echo "Starting ${name}."
cd /usr/local/ntpa/
${MONO} ntpa.exe --config ${config} --writepid ${pidfile} --temp ${tempdir} --daemon ${name} &
fi
}
ntpa_stop()
{
if [ ! -f ${pidfile} ]; then
_run_rc_notrunning
return 1
else
echo "Stopping ${name}."
rc_pid=`cat ${pidfile}`
kill -TERM $rc_pid
wait_for_pids ${rc_pid}
fi
}
eval ": \${${name}_enable:=\"NO\"}"
eval ": \${${name}_config:=\"/usr/local/etc/ntpa/${name}.conf\"}"
eval ": \${${name}_tempdir:=\"/tmp/\"}"
config="$(eval echo \${${name}_config})"
tempdir="$(eval echo \${${name}_tempdir})"
pidfile="/var/run/${name}.pid"
run_rc_command "$1"