1
0
mirror of https://bitbucket.org/anguist/ntpa synced 2025-11-23 20:09:20 +00:00

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

View File

@ -3,10 +3,16 @@ all:
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:
xbuild Ntp.Analyzer.sln /property:Configuration=Release
rm -R bin
clean:
xbuild Ntp.Analyzer.sln /t:clean
rm -Rf bin

View File

@ -47,10 +47,8 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<UseVSHostingProcess>true</UseVSHostingProcess>
<Prefer32Bit>false</Prefer32Bit>
<DocumentationFile>bin\$(TargetFrameworkVersion)\Debug\MySql.Data.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<BaseOutputPath>$(TargetFrameworkVersion)\</BaseOutputPath>
<BaseIntermediateOutputPath>obj\$(TargetFrameworkVersion)\</BaseIntermediateOutputPath>
@ -60,7 +58,6 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\Release\MySql.Data.XML</DocumentationFile>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
@ -255,8 +252,8 @@
</PostBuildEvent>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel>
<WarningLevel>1</WarningLevel>
</PropertyGroup>
</Project>

View File

@ -29,7 +29,7 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

View File

@ -8,7 +8,7 @@
<ProjectGuid>{6A635537-E5E9-493E-8B89-E0E5EBB64E72}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Ntp.Analyzer.Cli</RootNamespace>
<StartupObject>Ntp.Analyzer.Cli.MainClass</StartupObject>
<StartupObject>Ntp.Analyzer.Cli.Program</StartupObject>
<ReleaseVersion>0.3</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
@ -29,17 +29,18 @@
<AssemblyName>ntpa</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel>
<AssemblyName>Ntp.Analyzer.Cli</AssemblyName>
<LangVersion>4</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Program.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
@ -63,5 +64,9 @@
<Project>{909C8729-ED63-4603-85EA-34A1FC4D63D9}</Project>
<Name>Ntp.Analyzer.Log</Name>
</ProjectReference>
<ProjectReference Include="..\Ntp.Config\Ntp.Config.csproj">
<Project>{43A1A769-6ED9-4AE1-821A-43F97814968C}</Project>
<Name>Ntp.Config</Name>
</ProjectReference>
</ItemGroup>
</Project>

124
Ntp.Analyzer.Cli/Program.cs Normal file
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]");
}
}
}

View File

@ -22,7 +22,6 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
@ -30,7 +29,7 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

View File

@ -30,7 +30,7 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

View File

@ -30,7 +30,7 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

View File

@ -50,20 +50,20 @@ namespace Ntp.Analyzer.Process
public sealed class Initializer
{
/// <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>
/// <param name="configFile">Config file to use.</param>
/// <param name="pid">Process ID. Only used for logging.</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.pid = pid;
this.name = name;
nodes = new List<IRequest> ();
listeners = new List<Listener> ();
this.version = VersionInfo.Number;
}
private readonly string version;
@ -166,6 +166,7 @@ namespace Ntp.Analyzer.Process
log.WriteLine ("NTP Analyzer " + version + " started.", Severity.Notice);
log.WriteLine ("Using configuration: " + configFile, Severity.Notice);
log.WriteLine ("Running with pid: " + pid, Severity.Notice);
log.WriteLine ("Instance name: " + name, Severity.Notice);
return true;
}
@ -182,9 +183,6 @@ namespace Ntp.Analyzer.Process
ApplicationState.Config = config;
ApplicationState.ConfigFile = configFile;
ApplicationState.Log = log;
// Initialize system settings
ShellCommand.WorkingDirectory = "/tmp";
}
private void InitializeDatabase()

View File

@ -32,22 +32,18 @@ namespace Ntp.Analyzer.Process
{
public Main (string configFile, int pid, string name)
{
// Also update solution version.
version = "0.3a";
this.configFile = configFile;
this.pid = pid;
this.name = name;
}
private readonly string version;
private readonly string configFile;
private readonly int pid;
private readonly string name;
public void Start ()
{
Initializer i = new Initializer (version, configFile, pid, name);
Initializer i = new Initializer (configFile, pid, name);
i.Run ();
if (!i.Ready) {

View File

@ -37,7 +37,6 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Mono.Posix" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -20,7 +20,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<Commandlineparameters>~/code/ntpa/example/ntpa.stat.conf</Commandlineparameters>
<Commandlineparameters>~/code/ntpa/example/ntpa.web.conf</Commandlineparameters>
<AssemblyName>ntpav</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
@ -33,7 +33,7 @@
<AssemblyName>ntpav</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel>
<AssemblyName>Ntp.Analyzer.Validate.Cli</AssemblyName>
@ -55,5 +55,9 @@
<Project>{43A1A769-6ED9-4AE1-821A-43F97814968C}</Project>
<Name>Ntp.Config</Name>
</ProjectReference>
<ProjectReference Include="..\Ntp.System\Ntp.System.csproj">
<Project>{A98DB601-2993-4181-A573-5FCCC5E954C1}</Project>
<Name>Ntp.System</Name>
</ProjectReference>
</ItemGroup>
</Project>

View File

@ -4,7 +4,7 @@
// Author:
// 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
// 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.Export;
using Ntp.Config;
using Ntp.System;
namespace Ntp.Analyzer.Validate.Cli
{
@ -42,31 +43,53 @@ namespace Ntp.Analyzer.Validate.Cli
{
// Neutralize.
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
bool exit = false;
bool verbose = false;
if (args.Length == 0 || args.Length > 2) {
ShowUsage ();
Ntp.System.OptionSet p =
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;
}
if (args.Length == 1 && args[0] == "help") {
ShowUsage ();
if (config == null)
return;
}
string configFile = args [0];
Configuration config = LoadConfig (configFile);
if (config == null) {
return;
}
Console.WriteLine ("Parsed config ...");
if (args.Length == 2 && args [1] == "verbose") {
if (verbose)
Console.WriteLine (config);
}
TestFilesystem (config);
try {
TestFilesystem (config);
} catch (Exception e) {
Console.WriteLine ("Unexpected error while testing filesystem: " + e.Message);
return;
}
if (!anyErrors) {
Console.WriteLine ("Filesystem configuration seems valid ...");
@ -132,8 +155,8 @@ namespace Ntp.Analyzer.Validate.Cli
private static void ShowUsage()
{
Console.WriteLine ("NTP Analyzer validator tool.");
Console.WriteLine ("Usage: ntpav configuration [verbose]");
Console.WriteLine ("NTP Analyzer validator tool " + VersionInfo.Text);
Console.WriteLine ("Usage: ntpav [--verbose] configuration");
}
}
}

View File

@ -98,8 +98,8 @@ namespace Ntp.Analyzer.Config.Navigation
string itemName = GetOptionConfigName(options, "Item", "Item", true);
string type = GetOptionString(options, "Type", "Item", false, "Link").ToLower();
string caption = GetOptionString(options, "Caption", "Item", true);
string link = GetOptionString(options, "Link", "Item", true);
string caption = GetOptionString(options, "Caption", "Item", false);
string link = GetOptionString(options, "Link", "Item", false);
string page = GetOptionString(options, "Page", "Item", false);
string dropdown = GetOptionString(options, "Dropdown", "Item", false);
ILinkable linkable = null;

View File

@ -30,7 +30,7 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

View File

@ -30,7 +30,7 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

View File

@ -28,7 +28,7 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

View File

@ -31,7 +31,7 @@
<AssemblyName>ntpac</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel>
<AssemblyName>Ntp.Monitor.Cli</AssemblyName>

View File

@ -30,7 +30,7 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

View File

@ -30,7 +30,7 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

View File

@ -32,7 +32,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

View File

@ -94,7 +94,7 @@ namespace Ntp.Process
}
if (!otherActive) {
log.WriteLine ("No other nodes active. Activting node.", Severity.Debug);
//log.WriteLine ("No other nodes active. Activting node.", Severity.Debug);
try {
scheduler.RunOneCycle ();

View File

@ -29,7 +29,7 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

View File

@ -23,104 +23,69 @@
// 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.Net.Sockets;
using System.Text;
using System.Threading;
using System.IO;
using Ntp.Analyzer.Log;
#if __MonoCS__
using Mono.Unix;
using Mono.Unix.Native;
#else
using System.Threading;
#endif
namespace Ntp.System
{
#if __MonoCS__
using Mono.Unix;
public static class InterLock
{
public static bool Release (string name, LogBase log)
{
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;
}
#if __MonoCS__
public static bool Wait (string name, LogBase log)
{
byte[] buf = new byte[64];
UnixEndPoint endPoint = null;
UnixSignal[] signals = new UnixSignal[]{
new UnixSignal (Signum.SIGTERM)
};
using (Socket socket = new Socket (AddressFamily.Unix, SocketType.Stream, ProtocolType.IP)) {
try {
// Unix socket "hack"
endPoint = new UnixEndPoint (name);
if (File.Exists (endPoint.Filename)) {
File.Delete (endPoint.Filename);
}
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);
}
}
try {
UnixSignal.WaitAny (signals, -1);
log.WriteLine ("Received kill signal.", Severity.Notice);
} catch (Exception e) {
log.WriteLine ("Error in Signum handling.", Severity.Error);
log.WriteLine (e, Severity.Trace);
return false;
}
return true;
}
}
#else
public static class InterLock
{
public static string Release (string name)
#else
public static bool Release (string name, LogBase log)
{
try {
EventWaitHandle handle = EventWaitHandle.OpenExisting (name);
handle.Set ();
return true;
} 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 {
EventWaitHandle handle = new EventWaitHandle (
false, EventResetMode.ManualReset,
name);
false, EventResetMode.ManualReset,
name);
handle.WaitOne ();
return true;
} 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
}
}

View File

@ -30,7 +30,7 @@
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Server|AnyCPU' ">
<Optimize>false</Optimize>
<Optimize>true</Optimize>
<OutputPath>bin\Server</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -43,6 +43,8 @@
<Compile Include="ShellCommand.cs" />
<Compile Include="InterLock.cs" />
<Compile Include="ProcessInfo.cs" />
<Compile Include="Options.cs" />
<Compile Include="VersionInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>

1405
Ntp.System/Options.cs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -23,22 +23,25 @@
// 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.Runtime.InteropServices;
#if __MonoCS__
using Mono.Unix.Native;
#else
System.Diagnostics
#endif
namespace Ntp.System
{
public class ProcessInfo
{
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
}
}

View File

@ -81,4 +81,4 @@ namespace Ntp.System
return proc.StandardOutput;
}
}
}
}

36
Ntp.System/VersionInfo.cs Normal file
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;
}
}

View File

@ -18,7 +18,7 @@ Database {
# Password for the user
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
}

View File

@ -4,10 +4,23 @@
# Connection parameters to MySQL database instance.
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
# Database username
User ntpau
Pass xxx
# Password for the user
Pass xxxx
# Set to 1 to automatically create all tables and data.
Create 1
}
# OPTIONAL
@ -20,7 +33,13 @@ Log {
Server {
# Primary key in table 'host'
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
HostAddress ntp1.domain.org

66
script/ntpa Normal file
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"