예제 #1
0
        public void CreateService(DeviceInfo device)
        {
            Console.WriteLine("Creating MQTT bridge service...");
            Console.WriteLine("  Name: " + device.Name);
            Console.WriteLine("  Board: " + device.Board);
            Console.WriteLine("  Port: " + device.Port);

            if (IsOnLocal(device) && device.IsUSBConnected)
            {
                var servicesPath       = Context.IndexDirectory + "/scripts/apps/BridgeArduinoSerialToMqttSplitCsv/svc";
                var exampleServiceFile = "growsense-mqtt-bridge-" + device.Group + "1.service.example";

                var destinationServiceName = "growsense-mqtt-bridge-" + device.Name + ".service";
                var destinationServicePath = SystemCtl.GetServiceFilePath(destinationServiceName);

                if (File.Exists(destinationServicePath))
                {
                    Console.WriteLine("Service already exists. Stopping and removing...");

                    SystemCtl.Stop(destinationServiceName);
                    File.Delete(destinationServicePath);
                }

                var fullExampleServicePath = servicesPath + "/" + exampleServiceFile;

                Console.WriteLine("  Example service file: " + fullExampleServicePath);

                if (!File.Exists(fullExampleServicePath))
                {
                    throw new FileNotFoundException("Can't find example service path: " + fullExampleServicePath);
                }

                Console.WriteLine("  Destination service file: " + destinationServicePath);

                var serviceContent = File.ReadAllText(fullExampleServicePath);

                serviceContent = InsertValues(serviceContent, device);

                File.WriteAllText(destinationServicePath, serviceContent);

                SystemCtl.Reload();

                SystemCtl.Enable(destinationServiceName);
                SystemCtl.Start(destinationServiceName);

                Verifier.Verify(device.Name);
            }
            else
            {
                Console.WriteLine("  Device is on a different host. Skipping creation...");
            }

            Console.WriteLine("Finished creating MQTT bridge service.");
        }
예제 #2
0
        public void AssertSystemctlServiceExists(string serviceName)
        {
            Console.WriteLine("Asserting systemctl service file exists...");

            Console.WriteLine("  Is mock systemctl: " + (this.SystemCtl.GetType().Name.IndexOf("Mock") > -1));

            var fileExists = SystemCtl.Exists(serviceName);

            if (!fileExists)
            {
                var filePath = SystemCtl.GetServiceFilePath(serviceName);

                throw new Exception("Systemctl service file " + serviceName + " doesn't exist at " + filePath);
            }
        }