Azure IoT EdgeのedgeHubでUnable to start Kestrel


Azure IoT EdgeのedgeHubで、Unable to start Kestrelエラーが発生したときの対処方法。

事象

edgeHubモジュールを起動直後、止まってしまう。

iotedge logs edgeHubコマンドでログを確認すると、Unable to start Kestrelエラーと共に、System.Net.Sockets.SocketException (13): Permission deniedが発生している。

2018-12-29 06:10:47.175 +00:00 [FTL] - Unable to start Kestrel.
System.Net.Sockets.SocketException (13): Permission denied
   at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Bind(EndPoint localEP)
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransport.BindAsync()
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.<>c__DisplayClass22_0`1.<<StartAsync>g__OnBind|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindEndpointAsync(ListenOptions endpoint, AddressBindContext context)
   at Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions.BindAsync(AddressBindContext context)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.EndpointsStrategy.BindAsync(AddressBindContext context)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func`2 createBinding)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
2018-12-29 06:10:47.314 +00:00 [INF] - Stopping

わたしは、TinkerOS v2.0.8 (Debian stretch based)で発生しました。←このOSはAzure IoT Edgeでサポートされていません。

原因

ファイルシステムがCAP_NET_BIND_SERVICEに対応していないため、Http Server(Kestrel)の起動に失敗している。

回避方法

Http Serverを無効にする。

無効にすると、HTTPプロトコルに応答しなくなります。Transparent Gatewayなど、ゲートウェイ用途で使おうとしているときは、AMQPやMQTTで接続するようにしましょう。

設定方法

Azure Portalで対象のIoT Edgeデバイスを選択して、モジュールの設定にあるEdgeランタイムの詳細設定を構成するをクリックし、Edge Hubの環境変数に名前:httpSettings__enabled、値:falseを追加してください。

image.png

参考