Merge pull request 'SystemD Support and security updates' (#1) from dev into master
Reviewed-on: https://git.pooper.social/verita84/picluster/pulls/1
This commit is contained in:
commit
8407ebe1d9
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules
|
@ -1,8 +1,9 @@
|
||||
# Version 3.0.11
|
||||
# Version 3.0.12
|
||||
|
||||
## New Features:
|
||||
* Manage Containers: Has a new option called "Commit Image" that allows you to update a Docker image with the current running image.
|
||||
* Operations: Has a new option called "Edit Hosts" which will let you modify /etc/hosts on the server and then it will be copied to each node.
|
||||
* SystemD unit file generation for containers to start on Boot (Podman Only).
|
||||
|
||||
## Enhancements:
|
||||
* Added PiCluster version to /nodes API
|
||||
@ -12,7 +13,7 @@
|
||||
* ElasticSearch: Support for SSL/TLS
|
||||
|
||||
## Removed or Deprecated:
|
||||
* None
|
||||
* Auto-starting of containers at boot has been replaced with SystemD Unit files.
|
||||
|
||||
## Bug Fixes:
|
||||
* Docker Swarm fix for adding nodes to existing cluster
|
||||
|
@ -355,6 +355,7 @@ app.post('/run', (req, res) => {
|
||||
node
|
||||
};
|
||||
|
||||
|
||||
const check_token = req.body.token;
|
||||
|
||||
if (check_token !== token) {
|
||||
@ -368,16 +369,93 @@ app.post('/run', (req, res) => {
|
||||
output.output = stderr;
|
||||
} else {
|
||||
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 => {
|
||||
if (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) {
|
||||
console.log('SSL Agent API enabled');
|
||||
const ssl_options = {
|
||||
@ -441,21 +519,6 @@ bootstrapNode();
|
||||
function additional_services() {
|
||||
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) {
|
||||
vip = config.vip_ip;
|
||||
|
1188
agent/package-lock.json
generated
1188
agent/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,7 @@
|
||||
"unsafe-perm": true
|
||||
},
|
||||
"dependencies": {
|
||||
"async": "latest",
|
||||
"async": "^3.2.4",
|
||||
"body-parser": "latest",
|
||||
"child-process-promise": "",
|
||||
"cpu-stats": "latest",
|
||||
|
12833
package-lock.json
generated
12833
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -36,7 +36,7 @@
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"xo": "^0.32.1"
|
||||
"xo": "^0.51.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"eslint": "^7.24.0",
|
||||
|
3059
server/package-lock.json
generated
3059
server/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -18,7 +18,7 @@ const {
|
||||
const {
|
||||
exec
|
||||
} = require('child_process');
|
||||
const version = "3.0.11"
|
||||
const version = "3.0.12"
|
||||
|
||||
const bootstrap = {
|
||||
status: 1
|
||||
|
1090
web/package-lock.json
generated
1090
web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -9,7 +9,7 @@
|
||||
"express": "^4.17.1",
|
||||
"font-logos": "",
|
||||
"jquery": "^3.6.0",
|
||||
"jquery.terminal": "^1.23.2",
|
||||
"jquery.terminal": "^2.34.0",
|
||||
"line-reader": "^0.4.0",
|
||||
"moment": "^2.29.1",
|
||||
"multer": "^1.3.0",
|
||||
|
Loading…
Reference in New Issue
Block a user