This commit is contained in:
Your Name 2022-08-14 23:50:12 -06:00
parent 0a1472e6e8
commit f737084eb7
3 changed files with 84 additions and 20 deletions

View File

@ -1,4 +1,4 @@
# Version 3.0.11 # Version 3.0.12
## New Features: ## New Features:
* Manage Containers: Has a new option called "Commit Image" that allows you to update a Docker image with the current running image. * Manage Containers: Has a new option called "Commit Image" that allows you to update a Docker image with the current running image.
@ -10,9 +10,10 @@
* Webconsole: Removed depcreciated BodyParser constructor * Webconsole: Removed depcreciated BodyParser constructor
* Webconsole: Image list shows size and created time. * Webconsole: Image list shows size and created time.
* ElasticSearch: Support for SSL/TLS * ElasticSearch: Support for SSL/TLS
* SystemD unit file generation for containers to start on Boot.
## Removed or Deprecated: ## Removed or Deprecated:
* None * Auto-starting of containers at boot has been replaced with SystemD Unit files.
## Bug Fixes: ## Bug Fixes:
* Docker Swarm fix for adding nodes to existing cluster * Docker Swarm fix for adding nodes to existing cluster

View File

@ -355,6 +355,7 @@ app.post('/run', (req, res) => {
node node
}; };
const check_token = req.body.token; const check_token = req.body.token;
if (check_token !== token) { if (check_token !== token) {
@ -368,16 +369,93 @@ app.post('/run', (req, res) => {
output.output = stderr; output.output = stderr;
} else { } else {
output.output = stdout; output.output = stdout;
if (config.autostart_containers) {
if (req.body.command.indexOf('docker container run') > -1) {
systemd(req.body.command);
} else if (req.body.command.indexOf('docker container rm') > -1) {
systemd_remove(req.body.command);
}
}
res.json(output);
} }
res.json(output);
}, err => { }, err => {
if (err) { if (err) {
console.error('error:', err); console.error('error:', err);
} }
// Console.log('output', output); Console.log('output', output);
}); });
}); });
function systemd(data) {
const systemd = ["[Unit]", "Description=Container", "After=podman.service", "[Service]", "Type=oneshot", "RemainAfterExit=yes", "Environment=\"NAME=", "Environment=\"ARGUMENTS=", "ExecStartPre=/bin/sh -c \"/usr/bin/podman rm -f ${NAME}; exit 0;\"", "ExecStartPre=/bin/sh -c \"/usr/bin/podman build -t ${NAME} /docker/${NAME}; exit 0;\"", "ExecStart=/bin/sh -c \"podman run -d --name ${NAME} ${ARGUMENTS} localhost/${NAME}; exit 0;\"", "ExecStart=/bin/sh -c \"systemctl restart firewalld.service; exit 0;\"", "ExecStart=/bin/sh -c \"podman network reload -a; exit 0;\"", "ExecStop=/usr/bin/podman rm -f ${NAME}\"", "[Install]", "WantedBy=multi-user.target"];
var container_name = data.split(' ');
var name = container_name[container_name.length - 1];
for (const unit_file of systemd) {
if (unit_file.indexOf('Unit') > -1) {
console.log(unit_file);
fs.writeFile('/etc/systemd/system/picluster-' + name + '.service', unit_file + '\n', err => {
if (err) {
console.log(err);
}
});
} else if (unit_file.indexOf('NAME=') > -1) {
let analyze_unit_file = 'Environment=\"NAME=' + name + '"';
fs.appendFile('/etc/systemd/system/picluster-' + name + '.service', analyze_unit_file + '\n', err => {
if (err) {
console.log(err);
}
});
} else if (unit_file.indexOf('ARGUMENTS') > -1) {
final_arguments = data.split(';');
final_line = final_arguments[1].split(name);
end_line = 'Environment=\"ARGUMENTS="' + final_line[1] + '"';
fs.appendFile('/etc/systemd/system/picluster-' + name + '.service', end_line + '\n', err => {
if (err) {
console.log(err);
}
});
} else {
fs.appendFile('/etc/systemd/system/picluster-' + name + '.service', unit_file + '\n', err => {
if (err) {
console.log(err);
}
});
console.log(unit_file);
}
}
exec('systemctl enable picluster-' + name + '.service', (error, stdout, stderr) => {
if (error) {
console.log(error);
}
if (stdout) {
console.log(stdout);
}
});
}
function systemd_remove(data) {
var container_name = data.split(' ');
var name = container_name[container_name.length - 1];
exec('systemctl disable picluster-' + name + '.service', (error, stdout, stderr) => {
if (error) {
console.log(error);
} else {
console.log('\nRemoving picluster-' + name + '.service');
fs.unlink('/etc/systemd/system/picluster-' + name + '.service', error => {
if (error) {
console.log(error);
}
});
}
});
}
if (config.ssl && config.ssl_cert && config.ssl_key) { if (config.ssl && config.ssl_cert && config.ssl_key) {
console.log('SSL Agent API enabled'); console.log('SSL Agent API enabled');
const ssl_options = { const ssl_options = {
@ -441,21 +519,6 @@ bootstrapNode();
function additional_services() { function additional_services() {
monitoring(); monitoring();
if (config.autostart_containers) {
console.log('Starting all the containers.....');
superagent
.get(`${scheme}${server}:${server_port}/start`)
.query({
token: token,
container: '*'
})
.end((err, res) => {
if (err) {
console.log(error);
}
});
}
if (config.vip_ip && config.vip) { if (config.vip_ip && config.vip) {
vip = config.vip_ip; vip = config.vip_ip;

View File

@ -18,7 +18,7 @@ const {
const { const {
exec exec
} = require('child_process'); } = require('child_process');
const version = "3.0.11" const version = "3.0.12"
const bootstrap = { const bootstrap = {
status: 1 status: 1