Skip to content

Commit

Permalink
Run as a service on macOS (#84)
Browse files Browse the repository at this point in the history
* Run as a service on macOS

* macOS Launchd documentation updates

* Pin mysql to 8.0.35 to get around libssl and libicu dependency errors

* MySql pinning no longer needed

* AzIdentity 1.11.0
  • Loading branch information
paveliak authored Apr 13, 2024
1 parent d4f7606 commit 387a967
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 6 deletions.
12 changes: 12 additions & 0 deletions OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ which is described in [CONFIG.md](CONFIG.md#configuration-file).

The file requires administrative permissions to change.

### MacOS Launchd daemon

On MacOS, the service is registered with Launchd as "com.azure.relay.bridge" and can
be managed with `launchctl`.

To run either the client or the server side in that daemon, merge the
configuration file snippets above into the
`/etc/azbridge/azbridge_config.svc.yml` file, which is described in
[CONFIG.md](CONFIG.md#configuration-file).

The file requires administrative permissions to change.

## Downloads

Unsigned (!) binaries are available for direct download from the [Github
Expand Down
3 changes: 3 additions & 0 deletions build/repo.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith('linux'))">
<DefineConstants>_SYSTEMD</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith('osx'))">
<DefineConstants>_LAUNCHD</DefineConstants>
</PropertyGroup>
<ItemGroup>
<DotNetCoreRuntime Include="$(MicrosoftNETCoreAppPackageVersion)" />
</ItemGroup>
Expand Down
12 changes: 12 additions & 0 deletions examples/rdp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,16 @@ configuration file snippets above into the
`/etc/azbridge/azbridge_config.svc.yml` file, which is described in
[CONFIG.md](CONFIG.md#configuration-file).

The file requires administrative permissions to change.

### MacOS Launchd daemon

On MacOS, the service is registered with Launchd as "com.azure.relay.bridge" and can
be managed with `launchctl`.

To run either the client or the server side in that daemon, merge the
configuration file snippets above into the
`/etc/azbridge/azbridge_config.svc.yml` file, which is described in
[CONFIG.md](CONFIG.md#configuration-file).

The file requires administrative permissions to change.
17 changes: 16 additions & 1 deletion examples/sqlserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,19 @@ configuration file snippets above into the
The file requires administrative permissions to change.

As with Windows above, you can also override connection strings at the forwarder
level on Linux.
level on Linux.

### MacOS Launchd daemon

On MacOS, the service is registered with Launchd as "com.azure.relay.bridge" and can
be managed with `launchctl`.

To run either the client or the server side in that daemon, merge the
configuration file snippets above into the
`/etc/azbridge/azbridge_config.svc.yml` file, which is described in
[CONFIG.md](CONFIG.md#configuration-file).

The file requires administrative permissions to change.

As with Windows and Linux above, you can also override connection strings at the forwarder
level on macOS.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.10.2" />
<PackageReference Include="Azure.Identity" Version="1.11.0" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="$(McMasterExtensionsCommandLineUtilsPackageVersion)" />
<PackageReference Include="Microsoft.Azure.Relay" Version="$(MicrosoftAzureRelayPackageVersion)" />
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
Expand Down
2 changes: 1 addition & 1 deletion src/azbridge/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/azbridge/RelayBridgeService.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
22 changes: 21 additions & 1 deletion src/azbridge/ServiceLauncher.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// 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;
using Microsoft.Extensions.DependencyInjection;
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;
Expand Down Expand Up @@ -95,6 +96,8 @@ internal static async Task RunAsync(CommandLineSettings settings)
})
#elif _SYSTEMD
.UseSystemd()
#elif _LAUNCHD
.UseLaunchd()
#endif

.ConfigureServices(services =>
Expand Down Expand Up @@ -183,6 +186,23 @@ internal static bool IsInstalled()
return true;
#endif
}

private static IHostBuilder UseLaunchd(this IHostBuilder hostBuilder)
{
hostBuilder.ConfigureServices(services =>
{
services.Configure<ConsoleLoggerOptions>(options =>
{
options.FormatterName = ConsoleFormatterNames.Simple;
});
services.Configure<SimpleConsoleFormatterOptions>(options =>
{
options.SingleLine = true;
});
});

return hostBuilder;
}
}
}
#endif
3 changes: 3 additions & 0 deletions src/azbridge/azbridge.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<Content Include="azbridge.service" CopyToPublishDirectory="PreserveNewest" Condition="$(DefineConstants.Contains('_SYSTEMD'))">
<LinuxPath>/etc/systemd/system/azbridge.service</LinuxPath>
</Content>
<Content Include="azbridge.plist" CopyToPublishDirectory="PreserveNewest" Condition="$(DefineConstants.Contains('_LAUNCHD'))">
<LinuxPath>/Library/LaunchDaemons/com.azure.relay.bridge.plist</LinuxPath>
</Content>
<Content Include="azbridge.sh" CopyToPublishDirectory="PreserveNewest" Condition="! $(RuntimeIdentifier.StartsWith('win'))" RemoveOnUninstall="true">
<LinuxPath>/etc/profile.d/azbridge.sh</LinuxPath>
<LinuxFileMode Condition="$(RuntimeIdentifier.StartsWith('linux'))">0555</LinuxFileMode>
Expand Down
24 changes: 24 additions & 0 deletions src/azbridge/azbridge.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.azure.relay.bridge</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/share/azbridge/azbridge</string>
<string>--svc</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<dict>
<key>Crashed</key>
<true/>
</dict>
<key>StandardOutPath</key>
<string>/var/log/azbridge.log</string>
<key>StandardErrorPath</key>
<string>/var/log/azbridge.log</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion test/mysql/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ else
echo AZBRIDGE_TEST_CXNSTRING environment variable must be set to valid relay connection string
exit 2
fi

# start the web server
server_name=$(docker run -v $(pwd):/tests -d -v $(pwd)/my.cnf:/etc/mysqld/conf.d/my.cnf --rm -d -e AZBRIDGE_TEST_CXNSTRING="$_CXNSTRING" -e MYSQL_ROOT_PASSWORD=PaSsWoRd112233 -e MYSQL_PASSWORD=PaSsWoRd112233 -e MYSQL_USER=mysql azbridge-mysql-server:latest)
# wait for server to start
Expand Down

0 comments on commit 387a967

Please sign in to comment.