mirror of
https://github.com/islehorse/HISP.git
synced 2025-05-06 03:24:50 +12:00
Add ability to run as a linux service
This commit is contained in:
parent
fb8eab0f8e
commit
1735c35a7c
30 changed files with 935 additions and 489 deletions
|
@ -25,7 +25,7 @@
|
|||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<NoWin32Manifest>true</NoWin32Manifest>
|
||||
<ApplicationIcon>icon.ico</ApplicationIcon>
|
||||
<StartupObject>HISP.Program</StartupObject>
|
||||
<StartupObject>HISP.Cli.Program</StartupObject>
|
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
||||
<DebugType>embedded</DebugType>
|
||||
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
|
||||
|
|
4
HorseIsleServer/HISPCli/HISPCli.csproj.user
Normal file
4
HorseIsleServer/HISPCli/HISPCli.csproj.user
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
|
@ -1,43 +1,133 @@
|
|||
using HISP.Server;
|
||||
using System;
|
||||
using HISP.Server;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HISP
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static bool ShuttingDown = false;
|
||||
public static string LogFile;
|
||||
public static string BaseDir;
|
||||
|
||||
public static void OnShutdown()
|
||||
{
|
||||
ShuttingDown = true;
|
||||
}
|
||||
public static void LogToFile(string text)
|
||||
namespace HISP.Cli
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
private static StreamWriter sw = null;
|
||||
private static FileStream fs = null;
|
||||
private static string logFile;
|
||||
|
||||
public static bool ShuttingDown = false;
|
||||
public static string BaseDir;
|
||||
public static string LogFile
|
||||
{
|
||||
File.AppendAllTextAsync(text, LogFile);
|
||||
}
|
||||
public static void LogStdout(string text)
|
||||
get
|
||||
{
|
||||
return logFile;
|
||||
}
|
||||
set
|
||||
{
|
||||
logFile = value;
|
||||
if(sw != null)
|
||||
{
|
||||
sw.Flush();
|
||||
sw.Dispose();
|
||||
sw = null;
|
||||
}
|
||||
if(fs != null)
|
||||
{
|
||||
fs.Flush();
|
||||
fs.Dispose();
|
||||
fs = null;
|
||||
}
|
||||
|
||||
fs = File.OpenWrite(logFile);
|
||||
sw = new StreamWriter(fs);
|
||||
}
|
||||
}
|
||||
|
||||
public static void OnShutdown()
|
||||
{
|
||||
Console.Out.WriteAsync(text + Console.Out.NewLine);
|
||||
}
|
||||
public static void Main(string[] args)
|
||||
ShuttingDown = true;
|
||||
}
|
||||
public static void LogToFile(bool error, string type,string text)
|
||||
{
|
||||
sw.WriteLineAsync(text + sw.NewLine);
|
||||
}
|
||||
public static void LogStdout(bool error, string type, string text)
|
||||
{
|
||||
if (error)
|
||||
Console.Error.WriteAsync("[" + type + "] " + text + Console.Error.NewLine);
|
||||
else
|
||||
Console.Out.WriteAsync("[" + type + "] " + text + Console.Out.NewLine);
|
||||
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
string BaseDir = Directory.GetCurrentDirectory();
|
||||
#if DEB_PACKAGE
|
||||
ConfigReader.ConfigurationFileName = "/etc/hisp.conf"
|
||||
LogFile = "/var/log/hisp.log"
|
||||
Logger.SetCallback(LogToFile);
|
||||
#else
|
||||
Logger.SetCallback(LogStdout);
|
||||
#endif
|
||||
|
||||
Entry.SetShutdownCallback(OnShutdown);
|
||||
Entry.Start();
|
||||
|
||||
while (!ShuttingDown) { /* Allow asyncronous operations to happen. */ };
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Logger.SetCallback(LogStdout);
|
||||
|
||||
string HispConfVar = Environment.GetEnvironmentVariable("HISP_CONF_FILE");
|
||||
string HispLogVar = Environment.GetEnvironmentVariable("HISP_LOG_FILE");
|
||||
string HispBaseDir = Environment.GetEnvironmentVariable("HISP_BASE_DIR");
|
||||
|
||||
foreach (string arg in args)
|
||||
{
|
||||
switch (arg)
|
||||
{
|
||||
case "--install-service":
|
||||
#if OS_LINUX
|
||||
File.WriteAllText("/etc/systemd/system/HISP.service", Properties.Resources.HISPService);
|
||||
LogStdout(false, "INFO", "Crreated Service! enable it with \"sudo systemctl enable HISP\"");
|
||||
#else
|
||||
LogStdout(true, "ERROR", "Installing as a service unsupported on this platform");
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
if (arg.Contains("="))
|
||||
{
|
||||
string[] argu = arg.Split("=");
|
||||
if (argu.Length >= 2)
|
||||
{
|
||||
switch (argu[0])
|
||||
{
|
||||
case "--config-file":
|
||||
ConfigReader.ConfigurationFileName = argu[1];
|
||||
break;
|
||||
case "--log-to-file":
|
||||
LogFile = argu[1];
|
||||
Logger.SetCallback(LogToFile);
|
||||
break;
|
||||
case "--base-directory":
|
||||
BaseDir = argu[1];
|
||||
Directory.SetCurrentDirectory(BaseDir);
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (HispConfVar != null)
|
||||
{
|
||||
ConfigReader.ConfigurationFileName = HispConfVar;
|
||||
}
|
||||
|
||||
if (HispLogVar != null)
|
||||
{
|
||||
LogFile = HispLogVar;
|
||||
Logger.SetCallback(LogToFile);
|
||||
}
|
||||
|
||||
if (HispBaseDir != null)
|
||||
{
|
||||
BaseDir = HispBaseDir;
|
||||
Directory.SetCurrentDirectory(BaseDir);
|
||||
}
|
||||
|
||||
Entry.SetShutdownCallback(OnShutdown);
|
||||
Entry.Start();
|
||||
while (!ShuttingDown) { /* Allow asyncronous operations to happen. */ };
|
||||
Task.WaitAll();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace HISP.Properties {
|
||||
namespace HISP.Cli.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
|
@ -60,57 +60,9 @@ namespace HISP.Properties {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to <cross-domain-policy>
|
||||
/// <allow-access-from domain="*" to-ports="12321" secure="false"/>
|
||||
///</cross-domain-policy>.
|
||||
/// </summary>
|
||||
internal static string DefaultCrossDomain {
|
||||
internal static string HISPService {
|
||||
get {
|
||||
return ResourceManager.GetString("DefaultCrossDomain", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to # HorseIsleServer Default Configuration File
|
||||
///
|
||||
///# Ip address the server will bind to (default: 0.0.0.0 ALL INTERFACES)
|
||||
///ip=0.0.0.0
|
||||
///# Port the server will bind to (default: 12321)
|
||||
///port=12321
|
||||
///
|
||||
///# MariaDB Database
|
||||
///db_ip=127.0.0.1
|
||||
///db_name=beta
|
||||
///db_username=root
|
||||
///db_password=test123
|
||||
///db_port=3306
|
||||
///
|
||||
///# Map Data
|
||||
///map=HI1.MAP
|
||||
///
|
||||
///# JSON Format Data
|
||||
///
|
||||
///gamedata=gamedata.json
|
||||
///
|
||||
///# Cross-Domain Policy File
|
||||
///crossdomain=CrossDomainPolicy.xml
|
||||
///
|
||||
///# Red Text Stating "Todays Note:"
|
||||
///motd=April 11, 2020. New breed, C [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string DefaultServerProperties {
|
||||
get {
|
||||
return ResourceManager.GetString("DefaultServerProperties", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UNKNOWN COMMIT HASH
|
||||
/// </summary>
|
||||
internal static string GitCommit {
|
||||
get {
|
||||
return ResourceManager.GetString("GitCommit", resourceCulture);
|
||||
return ResourceManager.GetString("HISPService", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,120 +1,124 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="HISPService" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\HISP.service;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
</root>
|
25
HorseIsleServer/HISPCli/Resources/HISP.service
Normal file
25
HorseIsleServer/HISPCli/Resources/HISP.service
Normal file
|
@ -0,0 +1,25 @@
|
|||
[Unit]
|
||||
Description=HISP (Horse Isle Server Program)
|
||||
|
||||
After=syslog.target
|
||||
After=network.target
|
||||
|
||||
Wants=mariadb.service
|
||||
After=mariadb.service
|
||||
|
||||
|
||||
[Service]
|
||||
RestartSec=2s
|
||||
Type=simple
|
||||
|
||||
User=horseisle
|
||||
Group=horseisle
|
||||
|
||||
WorkingDirectory=/etc/hisp
|
||||
ExecStart=/usr/bin/HISPCli
|
||||
|
||||
Restart=always
|
||||
Environment=USER=horseisle HOME=/etc/hisp/home HISP_BASE_DIR=/etc/hisp HISP_CONF_FILE=/etc/hisp/server.properties
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Add table
Add a link
Reference in a new issue