44using InEngine . Core ;
55using Mono . Unix ;
66using Mono . Unix . Native ;
7- using NLog ;
87
98namespace InEngine
109{
@@ -15,6 +14,11 @@ class Program
1514
1615 static void Main ( string [ ] args )
1716 {
17+ /*
18+ * Set current working directory as services use the system directory by default.
19+ * Also, maybe run from the CLI from a different directory than the application root.
20+ */
21+ Directory . SetCurrentDirectory ( AppDomain . CurrentDomain . BaseDirectory ) ;
1822 new ArgumentInterpreter ( ) . Interpret ( args ) ;
1923 }
2024
@@ -23,39 +27,34 @@ static void Main(string[] args)
2327 /// </summary>
2428 public static void RunServer ( )
2529 {
26- var isRunningUnderMono = Type . GetType ( "Mono.Runtime" ) != null ;
27-
28- if ( isRunningUnderMono ) {
29- var serverHost = new ServerHost ( ) ;
30- serverHost . Start ( ) ;
30+ ServerHost = new ServerHost ( ) ;
31+ if ( Type . GetType ( "Mono.Runtime" ) != null ) {
32+ ServerHost . Start ( ) ;
3133 Console . WriteLine ( "CTRL+C to exit." ) ;
3234 UnixSignal . WaitAny ( new [ ] {
3335 new UnixSignal ( Signum . SIGINT ) ,
3436 new UnixSignal ( Signum . SIGTERM ) ,
3537 new UnixSignal ( Signum . SIGQUIT ) ,
3638 new UnixSignal ( Signum . SIGHUP )
3739 } ) ;
40+ ServerHost . Dispose ( ) ;
3841 }
39- else if ( ! Environment . UserInteractive && ! isRunningUnderMono )
42+ else if ( ! Environment . UserInteractive )
4043 {
41- // Set current working directory as services use the system directory by default.
42- Directory . SetCurrentDirectory ( AppDomain . CurrentDomain . BaseDirectory ) ;
4344 using ( var service = new Service ( ) )
4445 ServiceBase . Run ( service ) ;
4546 }
4647 else
4748 {
48- var serverHost = new ServerHost ( ) ;
49- serverHost . Start ( ) ;
50- Console . WriteLine ( "Press any key to stop..." ) ;
49+ ServerHost . Start ( ) ;
50+ Console . WriteLine ( "Any key to exit..." ) ;
5151 Console . ReadLine ( ) ;
52- serverHost . Dispose ( ) ;
52+ ServerHost . Dispose ( ) ;
5353 }
5454 }
5555
5656 static void Start ( string [ ] args )
5757 {
58- ServerHost = new ServerHost ( ) ;
5958 ServerHost . Start ( ) ;
6059 }
6160
0 commit comments