public void Setup() { if (Systemctl.IsEnabled("systemd-networkd.service") == false) { Systemctl.Enable("systemd-networkd.service"); } if (Systemctl.IsActive("systemd-networkd.service") == false) { Systemctl.Start("systemd-networkd.service"); } if (Systemctl.IsEnabled("systemd-resolved.service") == false) { Systemctl.Enable("systemd-resolved.service"); } if (Systemctl.IsActive("systemd-resolved.service") == false) { Systemctl.Start("systemd-resolved.service"); } _bash.Execute("ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf", false); if (!Directory.Exists(NetworkdFolder)) { Directory.CreateDirectory(NetworkdFolder); } }
private static void EnableRequiredServices() { Systemctl.Start("systemd-networkd.service"); Systemctl.Start("systemd-resolved.service"); Systemctl.Enable("systemd-networkd.service"); Systemctl.Enable("systemd-resolved.service"); }
public UnitsModule() : base("/units") { Get["/"] = x => { List <UnitModel> units = Units.All; return(View["page-units", units]); }; Post["/mgmt/enable/{unit}"] = x => { string unit = x.unit; CommandModel r = Systemctl.Enable(unit); string json = JsonConvert.SerializeObject(r.outputTable); return(json); }; Post["/mgmt/disable/{unit}"] = x => { string unit = x.unit; CommandModel r = Systemctl.Disable(unit); string json = JsonConvert.SerializeObject(r.outputTable); return(json); }; Post["/mgmt/start/{unit}"] = x => { string unit = x.unit; CommandModel r = Systemctl.Start(unit); string json = JsonConvert.SerializeObject(r.outputTable); return(json); }; Post["/mgmt/stop/{unit}"] = x => { string unit = x.unit; CommandModel r = Systemctl.Stop(unit); string json = JsonConvert.SerializeObject(r.outputTable); return(json); }; Post["/mgmt/restart/{unit}"] = x => { string unit = x.unit; CommandModel r = Systemctl.Restart(unit); string json = JsonConvert.SerializeObject(r.outputTable); return(json); }; Post["/mgmt/reload/{unit}"] = x => { string unit = x.unit; CommandModel r = Systemctl.Reload(unit); string json = JsonConvert.SerializeObject(r.outputTable); return(json); }; Get["/mgmt/status/{unit}"] = x => { string unit = x.unit; CommandModel r = Systemctl.Status(unit); string json = JsonConvert.SerializeObject(r.outputTable); return(json); }; }
public UnitsModule() { this.RequiresAuthentication(); Get["/units"] = x => { var units = Units.All; return(View["page-units", units]); }; Get["/units/list"] = x => { return(JsonConvert.SerializeObject(Units.All.OrderBy(u => u.name))); }; Post["/units/mgmt/enable/{unit}"] = x => { string unit = x.unit; var r = Systemctl.Enable(unit); return(JsonConvert.SerializeObject(r.outputTable)); }; Post["/units/mgmt/disable/{unit}"] = x => { string unit = x.unit; var r = Systemctl.Disable(unit); return(JsonConvert.SerializeObject(r.outputTable)); }; Post["/units/mgmt/start/{unit}"] = x => { string unit = x.unit; var r = Systemctl.Start(unit); return(JsonConvert.SerializeObject(r.outputTable)); }; Post["/units/mgmt/stop/{unit}"] = x => { string unit = x.unit; var r = Systemctl.Stop(unit); return(JsonConvert.SerializeObject(r.outputTable)); }; Post["/units/mgmt/restart/{unit}"] = x => { string unit = x.unit; var r = Systemctl.Restart(unit); return(JsonConvert.SerializeObject(r.outputTable)); }; Post["/units/mgmt/reload/{unit}"] = x => { string unit = x.unit; var r = Systemctl.Reload(unit); return(JsonConvert.SerializeObject(r.outputTable)); }; Get["/units/mgmt/status/{unit}"] = x => { string unit = x.unit; var r = Systemctl.Status(unit); return(JsonConvert.SerializeObject(r.outputTable)); }; }
public AntdServicesModule() { Get["/services"] = x => { var model = new PageServicesModel(); var machineInfo = new MachineInfo(); var services = machineInfo.GetUnits("service"); var mounts = machineInfo.GetUnits("mount"); var targets = machineInfo.GetUnits("target"); var timers = machineInfo.GetUnits("timer"); services.AddRange(mounts); services.AddRange(targets); services.AddRange(timers); model.Units = services; return(JsonConvert.SerializeObject(model)); }; Get["/services/log"] = x => { string unit = Request.Query.unit; var launcher = new CommandLauncher(); var model = launcher.Launch("journactl-service", new Dictionary <string, string> { { "$service", unit } }); return(JsonConvert.SerializeObject(model)); }; Post["/services/start"] = x => { string unit = Request.Form.Unit; Systemctl.Start(unit); return(HttpStatusCode.OK); }; Post["/services/restart"] = x => { string unit = Request.Form.Unit; Systemctl.Restart(unit); return(HttpStatusCode.OK); }; Post["/services/stop"] = x => { string unit = Request.Form.Unit; Systemctl.Stop(unit); return(HttpStatusCode.OK); }; Post["/services/enable"] = x => { string unit = Request.Form.Unit; Systemctl.Enable(unit); return(HttpStatusCode.OK); }; Post["/services/disable"] = x => { string unit = Request.Form.Unit; Systemctl.Disable(unit); return(HttpStatusCode.OK); }; }
public void StartService() { var svcs = HostParametersConfiguration.Conf.ServicesStart; foreach (var svc in svcs) { if (Systemctl.IsEnabled(svc) == false) { Systemctl.Enable(svc); } if (Systemctl.IsActive(svc) == false) { Systemctl.Start(svc); } } }
public static void Launch() { ConsoleLogger.Log("[gluster] launch"); var config = ServiceModel; SetHostnameFile(config); Systemctl.Enable(ServiceName); Systemctl.Start(ServiceName); ConsoleLogger.Log("[gluster] include nodes"); foreach (var node in config.Nodes) { IncludeNode(node.Hostname); } ConsoleLogger.Log("[gluster] start volumes"); foreach (var volume in config.Volumes) { SetVolume(volume, config.Nodes); } }
//public static void CreateUnits() { // if (Units.CheckFiles() == false) { // Units.SetAnthillaSp(); // Units.MountFramework(); // Units.LaunchAnthillaSp(); // Units.LaunchAnthillaServer(); // } // Systemctl.DaemonReload(); //} //private static void SetDirectories() { // var app = Management.DetectApps().FirstOrDefault(a => a.Name == "anthillasp"); // if (app == null) { // ConsoleLogger.Log("no appinfo detected"); // } // else { // var dirs = Management.GetWantedDirectories(app); // if (dirs.Length <= 0) { // ConsoleLogger.Log("no app directory found"); // } // else { // foreach (var dir in dirs) { // Directory.CreateDirectory(dir.Trim()); // Directory.CreateDirectory(Mount.SetDirsPath(dir.Trim())); // Mount.Dir(dir.Trim()); // } // } // } //} public static void Start() { if (!Systemctl.Status("app-anthillasp-01-prepare.service").output.Contains("Active: active (running)")) { Systemctl.Start("app-anthillasp-01-prepare.service"); } if (!Systemctl.Status("app-anthillasp-02-mount.service").output.Contains("Active: active (running)")) { Systemctl.Start("app-anthillasp-02-mount.service"); } if (!Systemctl.Status("app-anthillasp-03-srv-launcher.service").output.Contains("Active: active (running)")) { Systemctl.Start("app-anthillasp-03-srv-launcher.service"); } if (!Systemctl.Status("app-anthillasp-04-wui-launcher.service").output.Contains("Active: active (running)")) { Systemctl.Start("app-anthillasp-04-wui-launcher.service"); } }
public static void ApplyInterfaceSetting(NetworkInterfaceConfigurationModel model) { var netif = model.Interface; switch (model.Type) { case NetworkAdapterType.Physical: break; case NetworkAdapterType.Virtual: break; case NetworkAdapterType.Bond: CommandLauncher.Launch("bond-set", new Dictionary <string, string> { { "$bond", netif } }); foreach (var nif in model.InterfaceList) { CommandLauncher.Launch("bond-add-if", new Dictionary <string, string> { { "$bond", netif }, { "$net_if", nif } }); } break; case NetworkAdapterType.Bridge: CommandLauncher.Launch("brctl-add", new Dictionary <string, string> { { "$bridge", netif } }); foreach (var nif in model.InterfaceList) { CommandLauncher.Launch("brctl-add-if", new Dictionary <string, string> { { "$bridge", netif }, { "$net_if", nif } }); } break; case NetworkAdapterType.Other: break; } switch (model.Mode) { case NetworkInterfaceMode.Null: return; case NetworkInterfaceMode.Static: var networkdIsActive = Systemctl.IsActive("systemd-networkd"); if (networkdIsActive) { Systemctl.Stop("systemd-networkd"); } CommandLauncher.Launch("dhcpcd-killall"); CommandLauncher.Launch("ip4-flush-configuration", new Dictionary <string, string> { { "$net_if", netif } }); CommandLauncher.Launch("ip4-add-addr", new Dictionary <string, string> { { "$net_if", netif }, { "$address", model.StaticAddress }, { "$range", model.StaticRange } }); if (networkdIsActive) { Systemctl.Start("systemd-networkd"); } break; case NetworkInterfaceMode.Dynamic: CommandLauncher.Launch("dhcpcd", new Dictionary <string, string> { { "$net_if", netif } }); break; default: return; } CommandLauncher.Launch("ip4-set-mtu", new Dictionary <string, string> { { "$net_if", netif }, { "$mtu", model.Mtu } }); CommandLauncher.Launch("ip4-set-txqueuelen", new Dictionary <string, string> { { "$net_if", netif }, { "$txqueuelen", model.Txqueuelen } }); if (!string.IsNullOrEmpty(model.Route) && !string.IsNullOrEmpty(model.Gateway)) { CommandLauncher.Launch("ip4-add-route", new Dictionary <string, string> { { "$net_if", netif }, { "$gateway", model.Gateway }, { "$ip_address", model.Route } }); } var status = model.Status; switch (status) { case NetworkInterfaceStatus.Down: CommandLauncher.Launch("ip4-disable-if", new Dictionary <string, string> { { "$net_if", netif } }); break; case NetworkInterfaceStatus.Up: CommandLauncher.Launch("ip4-enable-if", new Dictionary <string, string> { { "$net_if", netif } }); ConsoleLogger.Log($"[network] interface '{model.Interface}' configured"); break; default: CommandLauncher.Launch("ip4-disable-if", new Dictionary <string, string> { { "$net_if", netif } }); break; } }
public static void StartServer() { Systemctl.Start("app-anthillasp-03-srv-launcher.service"); }
public static void StartSp() { Systemctl.Start("app-anthillasp-04-wui-launcher.service"); }
public static CommandModel StartAnthillaFirewall() { return(Systemctl.Start("anthillafirewall.service")); }
public static CommandModel StartAnthillaStorage() { return(Systemctl.Start("anthillastorage.service")); }
public void CreateScript() { var script = new BashScript { Comment("Setup environment"), Set("INSTANCE_ID", "$(curl -s http://169.254.169.254/latest/meta-data/instance-id)"), new IfStatement(IsDefined("$1"), Set("APP_NAME", "$1")), new IfStatement(IsDefined("$2"), Set("APP_VERSION", "$2")), // TODO: Use shorter syntax... new IfStatement(IsDefined("$3"), then: new[] { Set("APP_PACKAGE_URL", "$3") }, elseThen: new[] { Set("APP_PACKAGE_URL", "s3://folder/$APP_NAME/$APP_VERSION.tar.gz") } ), Set("APP_ROOT", "/var/apps/$APP_NAME/$APP_VERSION"), Empty, Echo("Configuring $APP_NAME/$APP_VERSION"), // Install depedencies Apt.Install("awscli", "nginx", "libunwind8", "libcurl4-openssl-dev"), // Configure S3 to allow encrypted package downloads "sudo aws configure set s3.signature_version s3v4", // Install SSM agent "cd /tmp", Wget.Download( new Uri("https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb") ), "sudo dpkg -i amazon-ssm-agent.deb", Systemctl.Enable("amazon-ssm-agent"), // Configure Ngnix ------------------------------------------------------------------------------------------------ Empty, Echo("Configuring nginx"), Wget.Download( url: new Uri("https://unknown/nginx.config"), destination: "/etc/nginx/sites-available/default", sudo: true ), Nginx.Reload(), // Setup program directories "mkdir -p $APP_ROOT", // Install the app ------------------------------------------------------------------------------------------------ // Create a working directory for download "mkdir -r /tmp/programs/$APP_NAME/$APP_VERSION", // Download the app Aws.S3.Copy( source: "$APP_PACKAGE_URL", target: "/tmp/programs/$APP_NAME/$APP_VERSION", options: AwsOptions.Quiet, sudo: true ), // Extract the app Tar.Extract( file: "/tmp/programs/$APP_NAME/$APP_VERSION", directory: "$APP_ROOT", stripFirstLevel: true ), // Create a symbolic link CreateSymbolicLink( target: "$APP_ROOT", link: "/var/apps/$APP_NAME/latest", options: SymbolicLinkOptions.Symbolic | SymbolicLinkOptions.Force, // update if it already exists sudo: true ), // Give permissions to www-data Chown(owner: "www-data", path: "/var/apps", recursive: true, sudo: true), // Configure the service ------------------------------------------------------------------------------------------ Empty, Echo("Configuring $APP_NAME.service"), // Setup the service Aws.S3.Copy( source: "s3://folder/$APP_NAME/$APPNAME.service", target: "/etc/systemd/system/$APP_NAME.service", options: AwsOptions.Quiet, sudo: true ), Systemctl.Enable("$APP_NAME.service"), Systemctl.Start("$APP_NAME.service"), // Cleanup ------------------------------------------------------------------------------------------------------- Empty, Echo("Cleaning up"), new Command("rm -r /tmp/programs/$APP_NAME/$APP_VERSION"), // Report to homebase --------------------------------------------------------------------------------------------- Empty, Echo("Phoning home $INSTANCE_ID"), "curl --data \"status=running\" https://cloud/hosts/aws:$INSTANCE_ID" }; Assert.Equal(@"#!/bin/bash # Setup environment INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) if [ -n ""$1"" ]; then APP_NAME=$1; fi if [ -n ""$2"" ]; then APP_VERSION=$2; fi if [ -n ""$3"" ]; then APP_PACKAGE_URL=$3; else APP_PACKAGE_URL=s3://folder/$APP_NAME/$APP_VERSION.tar.gz; fi APP_ROOT=/var/apps/$APP_NAME/$APP_VERSION echo ""Configuring $APP_NAME/$APP_VERSION"" sudo apt install -y awscli nginx libunwind8 libcurl4-openssl-dev sudo aws configure set s3.signature_version s3v4 cd /tmp wget -v ""https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb"" sudo dpkg -i amazon-ssm-agent.deb sudo systemctl enable amazon-ssm-agent echo ""Configuring nginx"" sudo wget -v ""https://unknown/nginx.config"" -O /etc/nginx/sites-available/default sudo nginx -s reload mkdir -p $APP_ROOT mkdir -r /tmp/programs/$APP_NAME/$APP_VERSION sudo aws s3 cp --quiet $APP_PACKAGE_URL /tmp/programs/$APP_NAME/$APP_VERSION tar -xf /tmp/programs/$APP_NAME/$APP_VERSION --strip 1 -C $APP_ROOT sudo ln -sfn $APP_ROOT /var/apps/$APP_NAME/latest sudo chown -R www-data /var/apps echo ""Configuring $APP_NAME.service"" sudo aws s3 cp --quiet s3://folder/$APP_NAME/$APPNAME.service /etc/systemd/system/$APP_NAME.service sudo systemctl enable $APP_NAME.service sudo systemctl start $APP_NAME.service echo ""Cleaning up"" rm -r /tmp/programs/$APP_NAME/$APP_VERSION echo ""Phoning home $INSTANCE_ID"" curl --data ""status=running"" https://cloud/hosts/aws:$INSTANCE_ID", script.ToString()); }
private void SetInterface(NetworkInterface configuration, NetworkInterfaceConfiguration interfaceConfiguration, NetworkGatewayConfiguration gatewayConfiguration) { if (interfaceConfiguration == null) { return; } var deviceName = configuration.Device; var nAt = NetworkAdapterType.Other; if (Network2Configuration.InterfacePhysical.Contains(deviceName)) { nAt = NetworkAdapterType.Physical; } else if (Network2Configuration.InterfaceBridge.Contains(deviceName)) { nAt = NetworkAdapterType.Bridge; } else if (Network2Configuration.InterfaceBond.Contains(deviceName)) { nAt = NetworkAdapterType.Bond; } else if (Network2Configuration.InterfaceVirtual.Contains(deviceName)) { nAt = NetworkAdapterType.Virtual; } switch (nAt) { case NetworkAdapterType.Physical: break; case NetworkAdapterType.Virtual: break; case NetworkAdapterType.Bond: CommandLauncher.Launch("bond-set", new Dictionary <string, string> { { "$bond", deviceName } }); foreach (var nif in interfaceConfiguration.ChildrenIf) { CommandLauncher.Launch("bond-add-if", new Dictionary <string, string> { { "$bond", deviceName }, { "$net_if", nif } }); CommandLauncher.Launch("ip4-flush-configuration", new Dictionary <string, string> { { "$net_if", nif } }); CommandLauncher.Launch("ip4-enable-if", new Dictionary <string, string> { { "$net_if", nif } }); } break; case NetworkAdapterType.Bridge: CommandLauncher.Launch("brctl-add", new Dictionary <string, string> { { "$bridge", deviceName } }); foreach (var nif in interfaceConfiguration.ChildrenIf) { CommandLauncher.Launch("brctl-add-if", new Dictionary <string, string> { { "$bridge", deviceName }, { "$net_if", nif } }); CommandLauncher.Launch("ip4-flush-configuration", new Dictionary <string, string> { { "$net_if", nif } }); CommandLauncher.Launch("ip4-enable-if", new Dictionary <string, string> { { "$net_if", nif } }); } break; case NetworkAdapterType.Other: return; } CommandLauncher.Launch("ip4-set-mtu", new Dictionary <string, string> { { "$net_if", deviceName }, { "$mtu", "6000" } }); CommandLauncher.Launch("ip4-set-txqueuelen", new Dictionary <string, string> { { "$net_if", deviceName }, { "$txqueuelen", "10000" } }); CommandLauncher.Launch("ip4-promisc-on", new Dictionary <string, string> { { "$net_if", deviceName } }); switch (interfaceConfiguration.Mode) { case NetworkInterfaceMode.Null: return; case NetworkInterfaceMode.Static: var networkdIsActive = Systemctl.IsActive("systemd-networkd"); if (networkdIsActive) { Systemctl.Stop("systemd-networkd"); } CommandLauncher.Launch("dhcpcd-killall"); CommandLauncher.Launch("ip4-flush-configuration", new Dictionary <string, string> { { "$net_if", deviceName } }); CommandLauncher.Launch("ip4-add-addr", new Dictionary <string, string> { { "$net_if", deviceName }, { "$address", interfaceConfiguration.Ip }, { "$range", interfaceConfiguration.Subnet } }); if (networkdIsActive) { Systemctl.Start("systemd-networkd"); } break; case NetworkInterfaceMode.Dynamic: CommandLauncher.Launch("dhcpcd", new Dictionary <string, string> { { "$net_if", deviceName } }); break; default: return; } switch (configuration.Status) { case NetworkInterfaceStatus.Down: CommandLauncher.Launch("ip4-disable-if", new Dictionary <string, string> { { "$net_if", deviceName } }); return; case NetworkInterfaceStatus.Up: CommandLauncher.Launch("ip4-enable-if", new Dictionary <string, string> { { "$net_if", deviceName } }); ConsoleLogger.Log($"[network] interface '{deviceName}' configured"); break; default: CommandLauncher.Launch("ip4-disable-if", new Dictionary <string, string> { { "$net_if", deviceName } }); return; } if (gatewayConfiguration == null) { return; } CommandLauncher.Launch("ip4-add-route", new Dictionary <string, string> { { "$net_if", deviceName }, { "$ip_address", "default" }, { "$gateway", gatewayConfiguration.GatewayAddress } }); }
public static CommandModel StartAnthillaAS() { return(Systemctl.Start("anthillaas.service")); }
public static CommandModel StartAnthillaServer() { return(Systemctl.Start("anthillaserver.service")); }