[1.0.0] First Version

This commit is contained in:
BlubbFish 2019-04-17 19:14:05 +02:00
parent 5e1a38fd9e
commit 82f19ec1fa
13 changed files with 199 additions and 57 deletions

View File

@ -70,5 +70,18 @@
<Name>Utils</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="config-example\settings.conf.example">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="dpkg\control" />
<None Include="dpkg\create-Builds.bat" />
<None Include="dpkg\monicascral-logrotate" />
<None Include="dpkg\monicascral.service" />
<None Include="dpkg\make-deb.sh" />
<None Include="dpkg\postinst" />
<None Include="dpkg\preinst" />
<None Include="dpkg\prerm" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -12,50 +12,50 @@ namespace Fraunhofer.Fit.IoT.MonicaScral {
static void Main(String[] args) => new Program(args);
public Program(String[] args) {
MqttListener m = new MqttListener(new Dictionary<String, String>() { { "type", "mqtt" }, { "server", "10.100.0.20" }, { "topic", "lora/data/+;lora/panic/+" } });
ScralPusher s = new ScralPusher(new Dictionary<String, String>() {
{ "server", "http://monappdwp3.monica-cloud.eu:8250" },
{ "register_addr", "/scral/v1.0/gps-tracker-gw/gps-tag" },
{ "register_method", "post" },
{ "update_addr", "/scral/v1.0/gps-tracker-gw/gps-tag/localization" },
{ "update_method", "put" },
{ "panic_addr", "/scral/v1.0/gps-tracker-gw/gps-tag/alert" },
{ "panic_method", "put" },});
InIReader.SetSearchPath(new List<String>() { "/etc/monicascral", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\monicascral" });
if(!InIReader.ConfigExist("settings")) {
Helper.WriteError("No settings.ini found. Abord!");
return;
}
InIReader settings = InIReader.GetInstance("settings");
this.logger.SetPath(settings.GetValue("logging", "path"));
MqttListener m = new MqttListener(settings.GetSection("mqtt"));
ScralPusher s = new ScralPusher(settings.GetSection("scral"));
m.Update += s.DataInput;
this.WaitForShutdown();
m.Dispose();
s.Dispose();
}
protected void WaitForShutdown() {
if(Type.GetType("Mono.Runtime") != null) {
this.sig_thread = new Thread(delegate () {
Mono.Unix.UnixSignal[] signals = new Mono.Unix.UnixSignal[] {
new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGTERM),
new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGINT)
};
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Mono attached.");
while(true) {
Int32 i = Mono.Unix.UnixSignal.WaitAny(signals, -1);
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Mono INT recieved " + i + ".");
this.RunningProcess = false;
break;
}
});
this.sig_thread.Start();
} else {
Console.CancelKeyPress += new ConsoleCancelEventHandler(this.SetupShutdown);
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Windows attached.");
}
while(this.RunningProcess) {
Thread.Sleep(100);
}
protected void WaitForShutdown() {
if(Type.GetType("Mono.Runtime") != null) {
this.sig_thread = new Thread(delegate () {
Mono.Unix.UnixSignal[] signals = new Mono.Unix.UnixSignal[] {
new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGTERM),
new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGINT)
};
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Mono attached.");
while(true) {
Int32 i = Mono.Unix.UnixSignal.WaitAny(signals, -1);
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Mono INT recieved " + i + ".");
this.RunningProcess = false;
break;
}
});
this.sig_thread.Start();
} else {
Console.CancelKeyPress += new ConsoleCancelEventHandler(this.SetupShutdown);
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Windows attached.");
}
while(this.RunningProcess) {
Thread.Sleep(100);
}
}
private void SetupShutdown(Object sender, ConsoleCancelEventArgs e) {
e.Cancel = true;
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.SetupShutdown: Signalhandler Windows INT recieved.");
this.RunningProcess = false;
private void SetupShutdown(Object sender, ConsoleCancelEventArgs e) {
e.Cancel = true;
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.SetupShutdown: Signalhandler Windows INT recieved.");
this.RunningProcess = false;
}
}
}

View File

@ -1,18 +1,19 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Resources;
using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("MonicaScral")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("Pushes Loratracker data to Monica Scral endpoint")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("Fraunhofer FIT")]
[assembly: AssemblyProduct("MonicaScral")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCopyright("Copyright © 2019 - 17.04.2019")]
[assembly: AssemblyTrademark("Fraunhofer FIT, BlubbFish")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("de-DE")]
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
@ -32,5 +33,9 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("1.0.0")]
/*
* 1.0.0 First Version
*/

View File

@ -117,21 +117,21 @@ namespace Fraunhofer.Fit.IoT.MonicaScral {
private String RequestString(String address, String json = "", Boolean withoutput = true, RequestMethod method = RequestMethod.GET) {
String ret = null;
lock(this.getLock) {
HttpWebRequest request = WebRequest.CreateHttp(this.config["server"] + address);
request.Timeout = 2000;
if(this.authRequired) {
request.Headers.Add(HttpRequestHeader.Authorization, this.auth);
}
if(method == RequestMethod.POST || method == RequestMethod.PUT) {
Byte[] requestdata = Encoding.ASCII.GetBytes(json);
request.ContentLength = requestdata.Length;
request.Method = method.ToString();
request.ContentType = "application/json";
using(Stream stream = request.GetRequestStream()) {
stream.Write(requestdata, 0, requestdata.Length);
}
}
try {
HttpWebRequest request = WebRequest.CreateHttp(this.config["server"] + address);
request.Timeout = 2000;
if(this.authRequired) {
request.Headers.Add(HttpRequestHeader.Authorization, this.auth);
}
if(method == RequestMethod.POST || method == RequestMethod.PUT) {
Byte[] requestdata = Encoding.ASCII.GetBytes(json);
request.ContentLength = requestdata.Length;
request.Method = method.ToString();
request.ContentType = "application/json";
using(Stream stream = request.GetRequestStream()) {
stream.Write(requestdata, 0, requestdata.Length);
}
}
using(HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
if(response.StatusCode == HttpStatusCode.Unauthorized) {
Console.Error.WriteLine("Benutzer oder Passwort falsch!");

View File

@ -0,0 +1,16 @@
[logging]
path=/var/log/monicascral.log
[mqtt]
type=mqtt
server=127.0.01
topic=lora/data/+;lora/panic/+
[scral]
server=http://example.org:8080
register_addr=/gps-tag
register_method=post
update_addr=/gps-tag/localization
update_method=put
panic_addr=/gps-tag/alert
panic_method=put

9
MonicaScral/dpkg/control Normal file
View File

@ -0,0 +1,9 @@
Package: monicascral
Version: x.x-x
Section: base
Priority: optional
Architecture: any
Depends: mono-runtime (>= 5.18), libmono-posix4.0-cil (>= 5.18)
Maintainer: BlubbFish <dev@blubbfish.net>
Description: MonicaScral
Pushes Loratracker data to Monica Scral endpoint

View File

@ -0,0 +1,2 @@
bash.exe -c "./make-deb.sh amd64"
pause

View File

@ -0,0 +1,49 @@
#!/bin/bash
HOMEDIR=$HOME
ROOT="$HOMEDIR/deb"
OUTPUT="../bin/Release"
EXEC="$ROOT/usr/local/bin/monicascral"
CONFIG="$ROOT/etc/monicascral"
SYSTEMD="$ROOT/lib/systemd/system"
LOGROTATE="$ROOT/etc/logrotate.d"
DEBIAN="$ROOT/DEBIAN"
VMAJOR=$(grep -e "^\[assembly: AssemblyVersion(\"" ../Properties/AssemblyInfo.cs | cut -d'"' -f 2 | cut -d'.' -f 1)
VMINOR=$(grep -e "^\[assembly: AssemblyVersion(\"" ../Properties/AssemblyInfo.cs | cut -d'"' -f 2 | cut -d'.' -f 2)
VBUILD=$(grep -e "^\[assembly: AssemblyVersion(\"" ../Properties/AssemblyInfo.cs | cut -d'"' -f 2 | cut -d'.' -f 3)
ARCHT=$1
mkdir -p $EXEC
mkdir -p $CONFIG
mkdir -p $DEBIAN
mkdir -p $SYSTEMD
mkdir -p $LOGROTATE
cp control $DEBIAN
cp preinst $DEBIAN
cp postinst $DEBIAN
cp prerm $DEBIAN
sed -i s/Version:\ x\.x-x/"Version: $VMAJOR.$VMINOR-$VBUILD"/ $DEBIAN/control
sed -i s/Architecture:\ any/"Architecture: $ARCHT"/ $DEBIAN/control
chmod 755 $DEBIAN -R
cp monicascral.service $SYSTEMD
chmod 644 $SYSTEMD/monicascral.service
cp $OUTPUT/*.exe $EXEC/
find $OUTPUT -name \*.dll -exec cp {} $EXEC/ \;
chmod 644 $EXEC/*
chmod 755 $EXEC
cp $OUTPUT/config-example/* $CONFIG
chmod 644 $CONFIG/*
chmod 755 $CONFIG
cp monicascral-logrotate $LOGROTATE/monicascral
chmod 644 $LOGROTATE/*
dpkg-deb --build $ROOT
mv $HOMEDIR/deb.deb ../../../Builds/"$ARCHT-monicascral_$VMAJOR.$VMINOR-$VBUILD.deb"
rm $HOMEDIR/deb -r

View File

@ -0,0 +1,10 @@
/var/log/monicascral.log {
compress
copytruncate
daily
delaycompress
missingok
notifempty
rotate 4
size=10M
}

View File

@ -0,0 +1,20 @@
# If you modify this, please also make sure to edit init.sh
[Unit]
Description=MonicaScral
After=network-online.target
[Service]
User=root
Group=root
WorkingDirectory=/usr/local/bin/monicascral
ExecStart=/usr/bin/mono /usr/local/bin/monicascral/MonicaScral.exe
KillMode=control-group
TimeoutStopSec=5
Restart=on-failure
StandardOutput=null
StandardError=syslog
[Install]
WantedBy=multi-user.target
Alias=monicascral.service

View File

@ -0,0 +1,9 @@
#!/bin/bash
systemctl enable monicascral
systemctl daemon-reload
if [ -f /tmp/monicascral_service_runner ]; then
service monicascral start
rm /tmp/monicascral_service_runner
fi

2
MonicaScral/dpkg/preinst Normal file
View File

@ -0,0 +1,2 @@
#!/bin/bash

7
MonicaScral/dpkg/prerm Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
if [[ $(systemctl is-active monicascral || true) == "active" ]]
then
touch /tmp/monicascral_service_runner
service monicascral stop
fi