Ejemplo n.º 1
0
 public void EnsureSystemCtlServiceIsNotRunning()
 {
     // Mosquitto is run as docker container. If it's already running as systemctl service it will conflict so needs to be disabled
     if (SystemCtl.Exists("mosquitto"))
     {
         SystemCtl.Stop("mosquitto");
         SystemCtl.Disable("mosquitto");
     }
 }
Ejemplo n.º 2
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.");
        }