diff --git a/build/repo.props b/build/repo.props index b5cf7d7..f7137d5 100644 --- a/build/repo.props +++ b/build/repo.props @@ -14,6 +14,9 @@ _SYSTEMD + + _LAUNCHD + diff --git a/src/azbridge/Program.cs b/src/azbridge/Program.cs index c0708f4..c9b9127 100644 --- a/src/azbridge/Program.cs +++ b/src/azbridge/Program.cs @@ -54,7 +54,7 @@ static int Run(CommandLineSettings settings, string[] args) return 0; } #endif -#if _WINDOWS || _SYSTEMD +#if _WINDOWS || _SYSTEMD || _LAUNCHD if (settings.ServiceRun.HasValue && settings.ServiceRun.Value) { ServiceLauncher.RunAsync(settings).GetAwaiter().GetResult(); diff --git a/src/azbridge/RelayBridgeService.cs b/src/azbridge/RelayBridgeService.cs index 6a46b2c..75b309b 100644 --- a/src/azbridge/RelayBridgeService.cs +++ b/src/azbridge/RelayBridgeService.cs @@ -1,4 +1,4 @@ -#if _WINDOWS || _SYSTEMD +#if _WINDOWS || _SYSTEMD || _LAUNCHD using Microsoft.Azure.Relay.Bridge.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; diff --git a/src/azbridge/ServiceLauncher.cs b/src/azbridge/ServiceLauncher.cs index a585e29..bc49c97 100644 --- a/src/azbridge/ServiceLauncher.cs +++ b/src/azbridge/ServiceLauncher.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if _WINDOWS || _SYSTEMD +#if _WINDOWS || _SYSTEMD || _LAUNCHD namespace azbridge { using Microsoft.Azure.Relay.Bridge.Configuration; @@ -9,6 +9,7 @@ namespace azbridge using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Configuration; + using Microsoft.Extensions.Logging.Console; using Microsoft.Extensions.Logging.EventLog; using System; using System.Collections; @@ -95,6 +96,8 @@ internal static async Task RunAsync(CommandLineSettings settings) }) #elif _SYSTEMD .UseSystemd() +#elif _LAUNCHD + .UseLaunchd() #endif .ConfigureServices(services => @@ -183,6 +186,23 @@ internal static bool IsInstalled() return true; #endif } + + private static IHostBuilder UseLaunchd(this IHostBuilder hostBuilder) + { + hostBuilder.ConfigureServices(services => + { + services.Configure(options => + { + options.FormatterName = ConsoleFormatterNames.Simple; + }); + services.Configure(options => + { + options.SingleLine = true; + }); + }); + + return hostBuilder; + } } } #endif \ No newline at end of file diff --git a/src/azbridge/azbridge.csproj b/src/azbridge/azbridge.csproj index 86c3e86..c2bb332 100644 --- a/src/azbridge/azbridge.csproj +++ b/src/azbridge/azbridge.csproj @@ -66,6 +66,9 @@ /etc/systemd/system/azbridge.service + + /Library/LaunchDaemons/com.azure.relay.bridge.plist + /etc/profile.d/azbridge.sh 0555 diff --git a/src/azbridge/azbridge.plist b/src/azbridge/azbridge.plist new file mode 100644 index 0000000..40758e6 --- /dev/null +++ b/src/azbridge/azbridge.plist @@ -0,0 +1,24 @@ + + + + + Label + com.azure.relay.bridge + ProgramArguments + + /usr/local/share/azbridge/azbridge + --svc + + RunAtLoad + + KeepAlive + + Crashed + + + StandardOutPath + /var/log/azbridge.log + StandardErrorPath + /var/log/azbridge.log + +