mirror of
https://git.v0l.io/Kieran/void.cat.git
synced 2025-10-10 13:32:33 +02:00
add service install script and stop memory leak
This commit is contained in:
10
utils/ga-page-view/ga-page-view.service
Normal file
10
utils/ga-page-view/ga-page-view.service
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=GA page view batching
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/usr/bin/dotnet /usr/local/ga-page-view/ga-page-view.dll
|
||||||
|
Restart=on-failure
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
@@ -20,15 +20,17 @@ namespace ga_page_view
|
|||||||
private static async Task startSvc()
|
private static async Task startSvc()
|
||||||
{
|
{
|
||||||
var c = await ConnectionMultiplexer.ConnectAsync("localhost");
|
var c = await ConnectionMultiplexer.ConnectAsync("localhost");
|
||||||
await c.GetSubscriber().SubscribeAsync("ga-page-view", (a, b) =>
|
await c.GetSubscriber().SubscribeAsync("ga-page-view", queueMsg);
|
||||||
{
|
|
||||||
_queue.Post(b.ToString());
|
|
||||||
});
|
|
||||||
|
|
||||||
Console.WriteLine("Connected to redis");
|
Console.WriteLine("Connected to redis");
|
||||||
await sendStats();
|
await sendStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void queueMsg(RedisChannel a, RedisValue b)
|
||||||
|
{
|
||||||
|
_queue.Post(b.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
private static async Task sendStats()
|
private static async Task sendStats()
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
@@ -54,7 +56,8 @@ namespace ga_page_view
|
|||||||
await sw.WriteAsync(string.Join("\r\n", payload));
|
await sw.WriteAsync(string.Join("\r\n", payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
var rsp = (HttpWebResponse)await req.GetResponseAsync();
|
using (var rsp = (HttpWebResponse)await req.GetResponseAsync())
|
||||||
|
{
|
||||||
if (rsp.StatusCode != HttpStatusCode.OK)
|
if (rsp.StatusCode != HttpStatusCode.OK)
|
||||||
{
|
{
|
||||||
using (StreamReader sr = new StreamReader(rsp.GetResponseStream()))
|
using (StreamReader sr = new StreamReader(rsp.GetResponseStream()))
|
||||||
@@ -63,6 +66,7 @@ namespace ga_page_view
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Error sending stats {ex.ToString()}");
|
Console.WriteLine($"Error sending stats {ex.ToString()}");
|
||||||
|
12
utils/ga-page-view/install.sh
Normal file
12
utils/ga-page-view/install.sh
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
dotnet publish -c Release
|
||||||
|
|
||||||
|
mkdir /usr/local/ga-page-view
|
||||||
|
|
||||||
|
cp ./ga-page-view/bin/Release/netcoreapp2.0/publish/* /usr/local/ga-page-view
|
||||||
|
cp ./ga-page-view.service /lib/systemd/system/
|
||||||
|
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable ga-page-view
|
||||||
|
systemctl start ga-page-view
|
Reference in New Issue
Block a user