Azure-Samples / iot-edge-opc-plc

Sample OPC UA server with nodes that generate random and increasing data, anomalies and much more ...
MIT License
223 stars 95 forks source link

chore: Add snapcraft.yaml and run script #390

Closed s-themis closed 2 months ago

s-themis commented 2 months ago

WIP, OPC UA server won't currently run inside the snap. Snap configuration will be added after this issue has been resolved.

s-themis commented 2 months ago

Build logs

$ snapcraft

Launching instance...                                                                    
Executed: pull opc-plc                                                                   
Executed: pull scripts                                                                   
Executed: build opc-plc                                                                  
Executed: build scripts                                                                  
Executed: stage opc-plc                                                                  
Executed: stage scripts                                                                  
Executed: prime opc-plc                                                                  
Executed: prime scripts                                                                  
Executed parts lifecycle                                                                 
Generated snap metadata                                                                  
Lint warnings:                                                                           
- library: InstrumentationEngine/alpine/x64/libCoverageInstrumentationMethod.so: missing dependency 'libc.musl-x86_64.so.1'. (https://snapcraft.io/docs/linters-library)           
- library: InstrumentationEngine/alpine/x64/libInstrumentationEngine.so: missing dependency 'libc.musl-x86_64.so.1'. (https://snapcraft.io/docs/linters-library)                   
- library: InstrumentationEngine/alpine/x64/libInstrumentationEngine.so: missing dependency 'libintl.so.8'. (https://snapcraft.io/docs/linters-library)                            
- library: InstrumentationEngine/alpine/x64/libInstrumentationEngine.so: missing dependency 'libxml2.so.2'. (https://snapcraft.io/docs/linters-library)                            
- library: InstrumentationEngine/ubuntu/x64/libInstrumentationEngine.so: missing dependency 'libxml2.so.2'. (https://snapcraft.io/docs/linters-library)                            
- library: libcoreclrtraceptprovider.so: missing dependency 'liblttng-ust.so.0'. (https://snapcraft.io/docs/linters-library)                                                       
Created snap package iot-edge-opc-plc_0.1_amd64.snap

Run logs

$ snap install iot-edge-opc-plc_0.1_amd64.snap --dangerous
$ iot-edge-opc-plc.opc-plc

<6>2024-09-04T15:12:55.494Z - 
 ██████╗ ██████╗  ██████╗    ██████╗ ██╗      ██████╗
██╔═══██╗██╔══██╗██╔════╝    ██╔══██╗██║     ██╔════╝
██║   ██║██████╔╝██║         ██████╔╝██║     ██║
██║   ██║██╔═══╝ ██║         ██╔═══╝ ██║     ██║
╚██████╔╝██║     ╚██████╗    ██║     ███████╗╚██████╗
 ╚═════╝ ╚═╝      ╚═════╝    ╚═╝     ╚══════╝ ╚═════╝

<6>2024-09-04T15:12:55.519Z - Min worker threads: 20, min completion port threads: 20
<6>2024-09-04T15:12:55.520Z - Current directory: /home/s-themistoklis/workspace/dmeng/forks/iot-edge-opc-plc
<6>2024-09-04T15:12:55.520Z - Log file: /home/s-themistoklis/snap/iot-edge-opc-plc/x1/hostname-port-plc.log
<6>2024-09-04T15:12:55.520Z - Log level: info
<6>2024-09-04T15:12:55.614Z - OpcPlc v2.12.23 from 09/04/2024 15:11:50 starting up ...
<6>2024-09-04T15:12:55.617Z - OPC UA SDK 1.5.374.98 from 08/16/2024 11:46:58
<6>2024-09-04T15:12:56.415Z - Alternate base addresses (for server binding and certificate DNSNames and IPAddresses extensions): opc.tcp://zenbook:50000
<6>2024-09-04T15:12:56.796Z - Application Certificate store type is: Directory
<6>2024-09-04T15:12:56.797Z - Application Certificate store path is: /home/s-themistoklis/snap/iot-edge-opc-plc/x1/pki/own
<6>2024-09-04T15:12:56.797Z - Rejection of SHA1 signed certificates is disabled
<6>2024-09-04T15:12:56.797Z - Minimum certificate key size set to 1024
<6>2024-09-04T15:12:56.797Z - Trusted Issuer store type is: Directory
<6>2024-09-04T15:12:56.797Z - Trusted Issuer Certificate store path is: /home/s-themistoklis/snap/iot-edge-opc-plc/x1/pki/issuer
<6>2024-09-04T15:12:56.797Z - Trusted Peer Certificate store type is: Directory
<6>2024-09-04T15:12:56.797Z - Trusted Peer Certificate store path is: /home/s-themistoklis/snap/iot-edge-opc-plc/x1/pki/trusted
<6>2024-09-04T15:12:56.797Z - Rejected certificate store type is: Directory
<6>2024-09-04T15:12:56.797Z - Rejected Certificate store path is: /home/s-themistoklis/snap/iot-edge-opc-plc/x1/pki/rejected
<6>2024-09-04T15:12:56.798Z - Added security policy http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256 with mode SignAndEncrypt
<6>2024-09-04T15:12:56.798Z - Added security policy http://opcfoundation.org/UA/SecurityPolicy#Aes128_Sha256_RsaOaep with mode SignAndEncrypt
<6>2024-09-04T15:12:56.798Z - Added security policy http://opcfoundation.org/UA/SecurityPolicy#Aes256_Sha256_RsaPss with mode SignAndEncrypt
<6>2024-09-04T15:12:56.798Z - Added security policy http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256 with mode Sign
<6>2024-09-04T15:12:56.798Z - Added security policy http://opcfoundation.org/UA/SecurityPolicy#Aes128_Sha256_RsaOaep with mode Sign
<6>2024-09-04T15:12:56.798Z - Added security policy http://opcfoundation.org/UA/SecurityPolicy#Aes256_Sha256_RsaPss with mode Sign
<6>2024-09-04T15:12:56.798Z - LDS(-ME) registration interval set to 0 ms (0 means no registration)
<6>2024-09-04T15:12:56.799Z - No existing application certificate found. Creating a self-signed application certificate valid since yesterday for 12 months, with a 2048 bit key and 256 bit hash
<6>2024-09-04T15:12:56.802Z - Checking application instance certificate.
<6>2024-09-04T15:12:56.805Z - Creating application instance certificate.
<6>2024-09-04T15:12:57.079Z - Imported the PFX private key for [44A59ED9A193DE9EBBF90A1A97F61A391626FF25].
<6>2024-09-04T15:12:57.083Z - Certificate created for urn:OpcPlc:zenbook. [CN=OpcPlc] [44A59ED9A193DE9EBBF90A1A97F61A391626FF25]
<6>2024-09-04T15:12:57.084Z - Application certificate with thumbprint 44A59ED9A193DE9EBBF90A1A97F61A391626FF25 created
<6>2024-09-04T15:12:57.084Z - Application certificate is for ApplicationUri urn:OpcPlc:zenbook, ApplicationName OpcPlc and Subject is CN=OpcPlc
<6>2024-09-04T15:12:57.090Z - Application store contains 1 certs
<6>2024-09-04T15:12:57.090Z - 01: Subject CN=OpcPlc (thumbprint: 44A59ED9A193DE9EBBF90A1A97F61A391626FF25)
<6>2024-09-04T15:12:57.091Z - Trusted issuer store contains 0 certs
<6>2024-09-04T15:12:57.091Z - Trusted issuer store has 0 CRLs
<6>2024-09-04T15:12:57.091Z - Trusted peer store contains 0 certs
<6>2024-09-04T15:12:57.092Z - Trusted peer store has 0 CRLs
<6>2024-09-04T15:12:57.092Z - Rejected certificate store contains 0 certs
<6>2024-09-04T15:12:57.092Z - Application configured with MaxSessionCount 100 and MaxSubscriptionCount 100
<6>2024-09-04T15:12:57.092Z - Starting server on endpoint opc.tcp://zenbook:50000 ...
<6>2024-09-04T15:12:57.092Z - Simulation settings are:
<6>2024-09-04T15:12:57.092Z - One simulation phase consists of 50 cycles
<6>2024-09-04T15:12:57.092Z - One cycle takes 100 ms
<6>2024-09-04T15:12:57.093Z - Reference test simulation: Enabled
<6>2024-09-04T15:12:57.093Z - Simple events: Disabled
<6>2024-09-04T15:12:57.093Z - Alarms: Disabled
<6>2024-09-04T15:12:57.093Z - Deterministic alarms: Disabled
<6>2024-09-04T15:12:57.093Z - Anonymous authentication: Enabled
<6>2024-09-04T15:12:57.093Z - Reject chain validation with CA certs with unknown revocation status: Enabled
<6>2024-09-04T15:12:57.093Z - Username/Password authentication: Enabled
<6>2024-09-04T15:12:57.093Z - Certificate authentication: Enabled
<4>2024-09-04T15:12:57.509Z - Failed to create IPv4 listening socket: Address already in use
<6>2024-09-04T15:12:57.515Z - Server - Start application OpcPlc.
<6>2024-09-04T15:12:57.519Z - Server - CreateResourceManager.
<6>2024-09-04T15:12:57.529Z - Server - CreateRequestManager.
<6>2024-09-04T15:12:57.529Z - Server - CreateMasterNodeManager.
<6>2024-09-04T15:12:57.559Z - MasterNodeManager.Startup - NodeManagers=5
<3>2024-09-04T15:12:58.363Z - Unexpected error creating address space for NodeManager #2.
System.IO.DirectoryNotFoundException: Could not find a part of the path '/home/s-themistoklis/workspace/dmeng/forks/iot-edge-opc-plc/CompanionSpecs/DI/Opc.Ua.DI.PredefinedNodes.uanodes'.
   at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode, Boolean failForSymlink, Boolean& wasSymlink, Func`4 createOpenException)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Boolean failForSymlink, Boolean& wasSymlink, Func`4 createOpenException)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.FileInfo.OpenRead()
   at Opc.Ua.NodeStateCollection.LoadFromBinaryResource(ISystemContext context, String resourcePath, Assembly assembly, Boolean updateTables)
   at OpcPlc.CompanionSpecs.DI.DiNodeManager.LoadPredefinedNodes(ISystemContext context) in /root/parts/opc-plc/build/src/CompanionSpecs/DI/DiNodeManager.cs:line 33
   at Opc.Ua.Server.CustomNodeManager2.LoadPredefinedNodes(ISystemContext context, IDictionary`2 externalReferences)
   at Opc.Ua.Server.CustomNodeManager2.CreateAddressSpace(IDictionary`2 externalReferences)
   at Opc.Ua.Server.MasterNodeManager.Startup()
<3>2024-09-04T15:12:58.414Z - Unexpected error starting application
System.IO.DirectoryNotFoundException: Could not find a part of the path '/home/s-themistoklis/workspace/dmeng/forks/iot-edge-opc-plc/CompanionSpecs/DI/Opc.Ua.DI.PredefinedNodes.uanodes'.
   at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode, Boolean failForSymlink, Boolean& wasSymlink, Func`4 createOpenException)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Boolean failForSymlink, Boolean& wasSymlink, Func`4 createOpenException)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.FileInfo.OpenRead()
   at Opc.Ua.NodeStateCollection.LoadFromBinaryResource(ISystemContext context, String resourcePath, Assembly assembly, Boolean updateTables)
   at OpcPlc.CompanionSpecs.DI.DiNodeManager.LoadPredefinedNodes(ISystemContext context) in /root/parts/opc-plc/build/src/CompanionSpecs/DI/DiNodeManager.cs:line 33
   at Opc.Ua.Server.CustomNodeManager2.LoadPredefinedNodes(ISystemContext context, IDictionary`2 externalReferences)
   at Opc.Ua.Server.CustomNodeManager2.CreateAddressSpace(IDictionary`2 externalReferences)
   at Opc.Ua.Server.MasterNodeManager.Startup()
   at Opc.Ua.Server.StandardServer.StartApplication(ApplicationConfiguration configuration)
<3>2024-09-04T15:12:58.418Z - OPC UA server failed unexpectedly
Opc.Ua.ServiceResultException: Unexpected error starting application
   at Opc.Ua.Server.StandardServer.StartApplication(ApplicationConfiguration configuration)
   at Opc.Ua.ServerBase.Start(ApplicationConfiguration configuration)
   at OpcPlc.OpcPlcServer.StartPlcServerAndSimulationAsync() in /root/parts/opc-plc/build/src/OpcPlcServer.cs:line 311
   at OpcPlc.OpcPlcServer.StartPlcServerAsync(CancellationToken cancellationToken) in /root/parts/opc-plc/build/src/OpcPlcServer.cs:line 247
   at OpcPlc.OpcPlcServer.StartAsync(String[] args, CancellationToken cancellationToken) in /root/parts/opc-plc/build/src/OpcPlcServer.cs:line 136
Unhandled exception. System.AggregateException: One or more errors occurred. (Unexpected error starting application)
 ---> Opc.Ua.ServiceResultException: Unexpected error starting application
   at Opc.Ua.Server.StandardServer.StartApplication(ApplicationConfiguration configuration)
   at Opc.Ua.ServerBase.Start(ApplicationConfiguration configuration)
   at OpcPlc.OpcPlcServer.StartPlcServerAndSimulationAsync() in /root/parts/opc-plc/build/src/OpcPlcServer.cs:line 311
   at OpcPlc.OpcPlcServer.StartPlcServerAsync(CancellationToken cancellationToken) in /root/parts/opc-plc/build/src/OpcPlcServer.cs:line 247
   at OpcPlc.OpcPlcServer.StartAsync(String[] args, CancellationToken cancellationToken) in /root/parts/opc-plc/build/src/OpcPlcServer.cs:line 136
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at OpcPlc.Program.Main(String[] args) in /root/parts/opc-plc/build/src/Program.cs:line 15
Aborted (core dumped)

Looks like the app is trying to access the build directory.

s-themis commented 2 months ago

Accidentally opened PR on original repo instead of forked repo. Closing this PR for now.