Esempio n. 1
0
        private static bool SetUnitForTunnel(string remoteHost)
        {
            var lines = new List <string> {
                "[Unit]",
                "Description=ExtUnit, VpnConnection",
                "",
                "[Service]",
                $"ExecStart=/usr/bin/ssh -o Tunnel=ethernet -f -w 1:1 root@{remoteHost} true",
                "SuccessExitStatus=1 2 3 4 5 6 7 8 9 0",
                "RemainAfterExit=yes",
                "Type=oneshot",
                "",
                "[Install]",
                "WantedBy=antd.target"
            };
            var unitName = $"/mnt/cdrom/Units/antd.target.wants/antd-{remoteHost}-vpn.service";

            ConsoleLogger.Log(unitName);
            if (!File.Exists(unitName))
            {
                FileWithAcl.WriteAllLines(unitName, lines, "644", "root", "wheel");
                Systemctl.DaemonReload();
            }
            Systemctl.Restart($"antd-{remoteHost}-vpn.service");
            return(Systemctl.IsActive($"antd-{remoteHost}-vpn.service"));
        }
Esempio n. 2
0
        public string CreateLauncherUnit(string name, string exeName, string exePath)
        {
            var unitName = $"app-{name.ToLower()}-{exeName.ToLower().Replace(".exe", "")}-launcher.service";
            var fileName = $"{Parameter.AppsUnits}/{unitName}";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            var oldUnitName = $"{Parameter.ApplicativeUnits}/{unitName}";

            if (File.Exists(oldUnitName))
            {
                File.Delete(oldUnitName);
            }
            var lines = new List <string> {
                "[Unit]",
                $"Description=External Volume Unit, Application: {exeName} Launcher Service",
                $"After=app-{name.ToLower()}-02-mount.service".Replace(" ", ""),
                "",
                "[Service]",
                $"ExecStart=/usr/bin/mono {exePath}",
                "Restart=on-failure",
                "RemainAfterExit=no",
                "TasksMax=infinity",
                "LimitNOFILE=1024000",
                "",
                "[Install]",
                "WantedBy=app.target"
            };

            File.WriteAllLines(fileName, lines);
            Systemctl.DaemonReload();
            return(unitName);
        }
Esempio n. 3
0
        public string CreatePrepareUnit(string name, string frameworkDir)
        {
            var unitName = $"app-{name.ToLower()}-01-prepare.service".Replace(" ", "");
            var fileName = $"{Parameter.AppsUnits}/{unitName}";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            var oldUnitName = $"{Parameter.ApplicativeUnits}/{unitName}";

            if (File.Exists(oldUnitName))
            {
                File.Delete(oldUnitName);
            }
            var lines = new List <string> {
                "[Unit]",
                "Description=External Volume Unit, Application: {name} Prepare Service",
                $"Before=app-{name.ToLower()}-02-mount.service".Replace(" ", ""),
                "",
                "[Service]",
                $"ExecStart=/bin/mkdir -p {frameworkDir}",
                "SuccessExitStatus=0",
                "RemainAfterExit=yes",
                "",
                "[Install]",
                "WantedBy=app.target"
            };

            File.WriteAllLines(fileName, lines);
            Systemctl.DaemonReload();
            return(unitName);
        }
Esempio n. 4
0
        public string CreateMountUnit(string name, string sourcePath, string frameworkDir)
        {
            var unitName = $"app-{name.ToLower()}-02-mount.service".Replace(" ", "");
            var fileName = $"{Parameter.AppsUnits}/{unitName}";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            var oldUnitName = $"{Parameter.ApplicativeUnits}/{unitName}";

            if (File.Exists(oldUnitName))
            {
                File.Delete(oldUnitName);
            }
            var lines = new List <string> {
                "[Unit]",
                $"Description=External Volume Unit, Application: {frameworkDir} Mount",
                "",
                "[Service]",
                $"ExecStart=/bin/mount {sourcePath} {frameworkDir}",
                "SuccessExitStatus=0",
                "RemainAfterExit=yes",
                "",
                "[Install]",
                "WantedBy=applicative.target"
            };

            FileWithAcl.WriteAllLines(fileName, lines, "644", "root", "wheel");
            Systemctl.DaemonReload();
            return(unitName);
        }
Esempio n. 5
0
        public static void Setup()
        {
            if (!Directory.Exists("/mnt/cdrom/Units"))
            {
                return;
            }
            if (!Directory.Exists("/mnt/cdrom/Units/antd.target.wants"))
            {
                return;
            }
            var edit = false;

            if (!File.Exists(Service01PreparePath))
            {
                FileWithAcl.WriteAllLines(Service01PreparePath, Service01Prepare(), "644", "root", "wheel");
                edit = true;
            }

            if (!File.Exists(Service02MountPath))
            {
                FileWithAcl.WriteAllLines(Service02MountPath, Service02Mount(), "644", "root", "wheel");
                edit = true;
            }

            if (!File.Exists(Service03LauncherPath))
            {
                FileWithAcl.WriteAllLines(Service03LauncherPath, Service03Launcher(), "644", "root", "wheel");
                edit = true;
            }

            if (edit)
            {
                Systemctl.DaemonReload();

                if (Systemctl.IsActive(Service01PrepareUnit) == false)
                {
                    Systemctl.Restart(Service01PrepareUnit);
                }

                if (Systemctl.IsActive(Service02MountUnit) == false)
                {
                    Systemctl.Restart(Service02MountUnit);
                }

                if (Systemctl.IsActive(Service03LauncherUnit) == false)
                {
                    Systemctl.Restart(Service03LauncherUnit);
                }
            }
        }
Esempio n. 6
0
        public static void Setup()
        {
            var edit = false;

            if (!File.Exists(Service01PreparePath))
            {
                File.WriteAllLines(Service01PreparePath, Service01Prepare());
                edit = true;
            }

            if (!File.Exists(Service02MountPath))
            {
                File.WriteAllLines(Service02MountPath, Service02Mount());
                edit = true;
            }

            if (!File.Exists(Service03LauncherPath))
            {
                File.WriteAllLines(Service03LauncherPath, Service03Launcher());
                edit = true;
            }

            if (edit)
            {
                Systemctl.DaemonReload();

                if (Systemctl.IsActive(Service01PrepareUnit) == false)
                {
                    Systemctl.Restart(Service01PrepareUnit);
                }

                if (Systemctl.IsActive(Service02MountUnit) == false)
                {
                    Systemctl.Restart(Service02MountUnit);
                }

                if (Systemctl.IsActive(Service03LauncherUnit) == false)
                {
                    Systemctl.Restart(Service03LauncherUnit);
                }
            }
        }
Esempio n. 7
0
            public static void LaunchAnthillaServer()
            {
                var path = Name.LaunchServer;

                if (!File.Exists(path))
                {
                    using (var sw = File.CreateText(path)) {
                        sw.WriteLine("[Unit]");
                        sw.WriteLine("Description=External Volume Unit, Application: AnthillaServer Launcher Service");
                        sw.WriteLine("Requires=local-fs.target sysinit.target");
                        sw.WriteLine("After=app-anthillasp-02-Mount.service");
                        sw.WriteLine("");
                        sw.WriteLine("[Service]");
                        sw.WriteLine("ExecStart=/usr/bin/mono /framework/anthillasp/anthillaserver/AnthillaServer.exe");
                        sw.WriteLine("");
                        sw.WriteLine("[Install]");
                        sw.WriteLine("WantedBy=applicative.target");
                    }
                }
                Systemctl.DaemonReload();
            }
Esempio n. 8
0
            public static void SetAnthillaSp()
            {
                var path = Name.Prepare;

                if (!File.Exists(path))
                {
                    using (var sw = File.CreateText(path)) {
                        sw.WriteLine("[Unit]");
                        sw.WriteLine("Description=External Volume Unit, Application: AnthillaSP Prepare Service");
                        sw.WriteLine("Requires=local-fs.target sysinit.target");
                        sw.WriteLine("Before=app-anthillasp-02-Mount.service");
                        sw.WriteLine("");
                        sw.WriteLine("[Service]");
                        sw.WriteLine("ExecStart=/bin/mkdir -p /framework/anthillasp");
                        sw.WriteLine("");
                        sw.WriteLine("[Install]");
                        sw.WriteLine("WantedBy=applicative.target");
                    }
                }
                Systemctl.DaemonReload();
            }
Esempio n. 9
0
            public static void MountFramework()
            {
                var path = Name.Mount;

                if (!File.Exists(path))
                {
                    using (var sw = File.CreateText(path)) {
                        sw.WriteLine("[Unit]");
                        sw.WriteLine("Description = ExtUnit, Application: Anthillasp 02 Mount Service");
                        sw.WriteLine("Before=app-anthillasp-03-srv-launcher.service");
                        sw.WriteLine("");
                        sw.WriteLine("[Service]");
                        sw.WriteLine("ExecStart=/bin/mount /mnt/cdrom/Apps/Anthilla_AnthillaSP/active-version /framework/anthillasp");
                        sw.WriteLine("SuccessExitStatus=0");
                        sw.WriteLine("RemainAfterExit=yes");
                        sw.WriteLine("");
                        sw.WriteLine("[Install]");
                        sw.WriteLine("WantedBy=applicative.target");
                    }
                }
                Systemctl.DaemonReload();
            }