mirror of
https://github.com/Websoft9/websoft9.git
synced 2024-11-25 09:00:26 +00:00
docker daemon
This commit is contained in:
parent
2f3595b5ce
commit
87affee25d
7 changed files with 107 additions and 46 deletions
4
cockpit/menu_override/sosreport.override.json
Normal file
4
cockpit/menu_override/sosreport.override.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"menu": null,
|
||||||
|
"tools": null
|
||||||
|
}
|
7
docker/daemon.json
Normal file
7
docker/daemon.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"log-driver": "json-file",
|
||||||
|
"log-opts": {
|
||||||
|
"max-size": "10m",
|
||||||
|
"max-file": "5"
|
||||||
|
}
|
||||||
|
}
|
|
@ -158,9 +158,10 @@ check_ports() {
|
||||||
local ports=("$@")
|
local ports=("$@")
|
||||||
|
|
||||||
echo "Stop Websoft9 Proxy and Cockpit service for reserve ports..."
|
echo "Stop Websoft9 Proxy and Cockpit service for reserve ports..."
|
||||||
sudo docker stop websoft9-proxy || echo "docker stop websoft9-proxy failed "
|
sudo docker stop websoft9-proxy 2>/dev/null || echo "docker stop websoft9-proxy not need "
|
||||||
sudo systemctl stop cockpit || echo "systemctl stop cockpit failed"
|
sudo systemctl stop cockpit 2>/dev/null || echo "systemctl stop cockpit not need"
|
||||||
sudo systemctl stop cockpit.socket || echo "systemctl stop cockpit.socket failed"
|
sudo systemctl stop cockpit.socket 2>/dev/null || echo "systemctl stop cockpit.socket not need"
|
||||||
|
|
||||||
|
|
||||||
for port in "${ports[@]}"; do
|
for port in "${ports[@]}"; do
|
||||||
if netstat -tuln | grep ":$port " >/dev/null; then
|
if netstat -tuln | grep ":$port " >/dev/null; then
|
||||||
|
@ -172,9 +173,51 @@ check_ports() {
|
||||||
echo "All ports are available"
|
echo "All ports are available"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
merge_daemon_files() {
|
||||||
|
remote_url="$1"
|
||||||
|
local_file="$2"
|
||||||
|
|
||||||
|
python3 - <<END
|
||||||
|
import json
|
||||||
|
import requests
|
||||||
|
|
||||||
|
# 获取远程 daemon.json 文件的内容
|
||||||
|
response = requests.get("$remote_url")
|
||||||
|
remote_daemon = response.json()
|
||||||
|
|
||||||
|
# 读取本地的 daemon.json 文件
|
||||||
|
with open("$local_file", 'r') as f:
|
||||||
|
local_daemon = json.load(f)
|
||||||
|
|
||||||
|
# 合并本地和远程的 daemon.json 文件内容
|
||||||
|
local_daemon.update(remote_daemon)
|
||||||
|
|
||||||
|
# 将合并后的内容写入到本地的 daemon.json 文件中
|
||||||
|
with open("$local_file", 'w') as f:
|
||||||
|
json.dump(local_daemon, f, indent=4)
|
||||||
|
END
|
||||||
|
}
|
||||||
|
|
||||||
|
set_docker(){
|
||||||
|
echo "Set Docker for Websoft9 backend service..."
|
||||||
|
|
||||||
|
if [ -f "${install_path}/docker/daemon.json" ]; then
|
||||||
|
merge_daemon_files "${install_path}/docker/daemon.json" "/etc/docker/daemon.json"
|
||||||
|
else
|
||||||
|
merge_daemon_files "${source_github_pages}/docker/daemon.json" "/etc/docker/daemon.json"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! docker network inspect websoft9 > /dev/null 2>&1; then
|
||||||
|
sudo docker network create websoft9
|
||||||
|
sudo systemctl restart docker
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
install_backends() {
|
install_backends() {
|
||||||
echo_prefix_backends=$'\n[Backend] - '
|
echo_prefix_backends=$'\n[Backend] - '
|
||||||
echo "$echo_prefix_backends Install backend docker services"
|
echo "$echo_prefix_backends Install backend docker services"
|
||||||
|
set_docker
|
||||||
|
|
||||||
cd "$install_path/docker"
|
cd "$install_path/docker"
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
|
|
|
@ -56,7 +56,7 @@ echo_prefix_cockpit=$'\n[Cockpit] - '
|
||||||
cockpit_packages="cockpit cockpit-ws cockpit-bridge cockpit-system cockpit-pcp cockpit-storaged cockpit-networkmanager cockpit-session-recording cockpit-doc cockpit-packagekit cockpit-sosreport"
|
cockpit_packages="cockpit cockpit-ws cockpit-bridge cockpit-system cockpit-pcp cockpit-storaged cockpit-networkmanager cockpit-session-recording cockpit-doc cockpit-packagekit cockpit-sosreport"
|
||||||
menu_overrides_github_page_url="https://websoft9.github.io/websoft9/cockpit/menu_override"
|
menu_overrides_github_page_url="https://websoft9.github.io/websoft9/cockpit/menu_override"
|
||||||
cockpit_config_github_page_url="https://websoft9.github.io/websoft9/cockpit/cockpit.conf"
|
cockpit_config_github_page_url="https://websoft9.github.io/websoft9/cockpit/cockpit.conf"
|
||||||
cockpit_menu_overrides=(networkmanager.override.json shell.override.json storaged.override.json systemd.override.json users.override.json apps.override.json machines.override.json selinux.override.json subscriptions.override.json kdump.override.json updated.override.json playground.override.json packagekit.override.json session-recording.override.json)
|
cockpit_menu_overrides=()
|
||||||
# export OS release environments
|
# export OS release environments
|
||||||
if [ -f /etc/os-release ]; then
|
if [ -f /etc/os-release ]; then
|
||||||
. /etc/os-release
|
. /etc/os-release
|
||||||
|
@ -207,7 +207,32 @@ Set_Cockpit(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_github_files() {
|
||||||
|
python3 - <<EOF
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
|
url = "https://api.github.com/repos/Websoft9/websoft9/contents/cockpit/menu_override?ref=main"
|
||||||
|
headers = {
|
||||||
|
"Accept": "application/vnd.github.v3+json"
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.get(url, headers=headers)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
files = json.loads(response.text)
|
||||||
|
for file in files:
|
||||||
|
print(file['name'])
|
||||||
|
else:
|
||||||
|
print(f"Error: {response.status_code}")
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Download_Menu_Override(){
|
Download_Menu_Override(){
|
||||||
|
|
||||||
|
cockpit_menu_overrides=($(get_github_files))
|
||||||
|
|
||||||
for file in "${cockpit_menu_overrides[@]}"
|
for file in "${cockpit_menu_overrides[@]}"
|
||||||
do
|
do
|
||||||
|
|
||||||
|
|
|
@ -30,14 +30,20 @@ docker_packages="docker-ce docker-ce-cli containerd.io docker-buildx-plugin dock
|
||||||
echo_prefix_docker=$'\n[Docker] - '
|
echo_prefix_docker=$'\n[Docker] - '
|
||||||
|
|
||||||
# Function to check if apt is locked
|
# Function to check if apt is locked
|
||||||
is_apt_locked(){
|
Wait_apt() {
|
||||||
if [[ -f /var/lib/dpkg/lock-frontend || -f /var/lib/apt/lists/lock ]]; then
|
local lock_files=("/var/lib/dpkg/lock" "/var/lib/apt/lists/lock")
|
||||||
return 0 # Apt is locked
|
|
||||||
else
|
for lock_file in "${lock_files[@]}"; do
|
||||||
return 1 # Apt is not locked
|
while fuser "${lock_file}" >/dev/null 2>&1 ; do
|
||||||
fi
|
echo "${lock_file} is locked by another process. Waiting..."
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "APT locks are not held by any processes. You can proceed."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
docker_exist() {
|
docker_exist() {
|
||||||
# 检查 `docker` 命令是否存在
|
# 检查 `docker` 命令是否存在
|
||||||
if ! command -v docker &> /dev/null; then
|
if ! command -v docker &> /dev/null; then
|
||||||
|
@ -77,12 +83,9 @@ Install_Docker(){
|
||||||
|
|
||||||
# For Ubuntu, Debian, or Raspbian
|
# For Ubuntu, Debian, or Raspbian
|
||||||
if type apt >/dev/null 2>&1; then
|
if type apt >/dev/null 2>&1; then
|
||||||
|
Wait_apt
|
||||||
apt update
|
apt update
|
||||||
# Wait for apt to be unlocked
|
# Wait for apt to be unlocked
|
||||||
while is_apt_locked; do
|
|
||||||
echo "Waiting for apt to be unlocked..."
|
|
||||||
sleep 5
|
|
||||||
done
|
|
||||||
curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh
|
curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -112,39 +115,18 @@ else
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Start_Docker(){
|
||||||
Set_Firewall(){
|
|
||||||
echo "$echo_prefix_cockpit Set Firewalld for Docker"
|
|
||||||
if command -v firewall-cmd &> /dev/null; then
|
|
||||||
if ! systemctl is-active --quiet firewalld; then
|
|
||||||
sudo systemctl start firewalld
|
|
||||||
sudo firewall-cmd --zone=trusted --remove-interface=docker0 --permanent
|
|
||||||
sudo firewall-cmd --reload
|
|
||||||
sudo systemctl stop firewalld
|
|
||||||
else
|
|
||||||
sudo firewall-cmd --zone=trusted --remove-interface=docker0 --permanent
|
|
||||||
sudo firewall-cmd --reload
|
|
||||||
fi
|
|
||||||
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
Set_Docker(){
|
|
||||||
# should have Docker server and Docker cli
|
# should have Docker server and Docker cli
|
||||||
if docker_exist; then
|
if docker_exist; then
|
||||||
echo "$echo_prefix_docker Starting to Set docker..."
|
echo "$echo_prefix_docker Starting Docker"
|
||||||
sudo systemctl enable docker
|
sudo systemctl enable docker
|
||||||
sudo systemctl restart docker
|
sudo systemctl restart docker
|
||||||
if ! docker network inspect websoft9 > /dev/null 2>&1; then
|
|
||||||
sudo docker network create websoft9
|
|
||||||
sudo systemctl restart docker
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo "Docker settings failed, exit..."
|
echo "Docker start failed, exit..."
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Upgrade_Docker
|
Upgrade_Docker
|
||||||
Set_Firewall
|
Start_Docker
|
||||||
Set_Docker
|
|
|
@ -2,6 +2,7 @@
|
||||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||||
export PATH
|
export PATH
|
||||||
|
|
||||||
|
# This script is on development, can not use now
|
||||||
# to do
|
# to do
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,6 @@ systemd_path="/opt/websoft9/systemd"
|
||||||
cockpit_plugin_path="/usr/share/cockpit"
|
cockpit_plugin_path="/usr/share/cockpit"
|
||||||
cockpit_packages="cockpit cockpit-ws cockpit-bridge cockpit-system cockpit-pcp cockpit-storaged cockpit-networkmanager cockpit-session-recording cockpit-doc cockpit-packagekit cockpit-sosreport"
|
cockpit_packages="cockpit cockpit-ws cockpit-bridge cockpit-system cockpit-pcp cockpit-storaged cockpit-networkmanager cockpit-session-recording cockpit-doc cockpit-packagekit cockpit-sosreport"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
echo -e "\n---Remove Websoft9 backend service containers---"
|
echo -e "\n---Remove Websoft9 backend service containers---"
|
||||||
sudo docker compose -p websoft9 down -v
|
sudo docker compose -p websoft9 down -v
|
||||||
|
|
||||||
|
@ -39,15 +37,16 @@ rm -rf /lib/systemd/system/websoft9.service
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
handle_cockpit() {
|
remove_cockpit() {
|
||||||
echo -e "\n---Remove Cockpit---"
|
echo -e "\n---Remove Cockpit---"
|
||||||
sudo systemctl stop cockpit.socket cockpit
|
sudo systemctl stop cockpit.socket cockpit
|
||||||
for package in $cockpit_packages; do
|
for package in $cockpit_packages; do
|
||||||
sudo pkcon remove $package -y || true
|
sudo pkcon remove $package -y || true
|
||||||
done
|
done
|
||||||
|
sudo rm -rf /etc/cockpit/*
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_files() {
|
remove_files() {
|
||||||
echo -e "\n---Remove files---"
|
echo -e "\n---Remove files---"
|
||||||
sudo rm -rf $install_path/* $systemd_path/* $cockpit_plugin_path/*
|
sudo rm -rf $install_path/* $systemd_path/* $cockpit_plugin_path/*
|
||||||
}
|
}
|
||||||
|
@ -56,11 +55,11 @@ for arg in "$@"
|
||||||
do
|
do
|
||||||
case $arg in
|
case $arg in
|
||||||
--cockpit)
|
--cockpit)
|
||||||
handle_cockpit
|
remove_cockpit
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--files)
|
--files)
|
||||||
handle_files
|
remove_files
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
|
Loading…
Reference in a new issue