Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cockpit: add support for KVM management #348

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes
16 changes: 16 additions & 0 deletions tools/include/markdown/COC001-header.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Cockpit is a web-based graphical interface for servers, intended for everyone.

Here’s a subset of tasks you can perform on each host running Cockpit

- inspect and change network settings
- configure a firewall
- manage storage (including RAID and LUKS partitions)
- create and manage virtual machines
- download and run containers
- browse and search system logs
- inspect a system’s hardware
- upgrade software
- manage user accounts
- inspect and interact with systemd-based services
- use a terminal on a remote server in your local web browser
- switch between multiple Cockpit servers
11 changes: 0 additions & 11 deletions tools/include/markdown/MAN001-footer.md

This file was deleted.

20 changes: 15 additions & 5 deletions tools/json/config.software.json
Original file line number Diff line number Diff line change
Expand Up @@ -1304,14 +1304,24 @@
"description": "Remote Management tools",
"sub": [
{
"id": "MAN001",
"description": "Cockpit web-based management tool",
"id": "COC001",
"description": "Cockpit OS and VM management tool",
"command": [
"see_menu module_cockpit"
"module_cockpit install"
],
"status": "Stable",
"author": "@Tearran",
"condition": ""
"author": "@igorpecovnik",
"condition": "! module_cockpit status"
},
{
"id": "COC002",
"description": "Remove Cockpit",
"command": [
"module_cockpit remove"
],
"status": "Stable",
"author": "@igorpecovnik",
"condition": "module_cockpit status"
},
{
"id": "MAN005",
Expand Down
2 changes: 1 addition & 1 deletion tools/modules/runtime/config.runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ update_sub_submenu_data "Software" "Monitoring" "MON006" "http://$LOCALIPADD:${m
update_sub_submenu_data "Software" "Monitoring" "GRA002" "http://$LOCALIPADD:${module_options["module_grafana,port"]}"

# Management
update_sub_submenu_data "Software" "Management" "MAN001" "http://$LOCALIPADD:${module_options["module_cockpit,port"]}"
update_sub_submenu_data "Software" "Management" "COC002" "https://$LOCALIPADD:${module_options["module_cockpit,port"]}"

# Downloaders
update_sub_submenu_data "Software" "Downloaders" "DOW002" "http://$LOCALIPADD:${module_options["module_qbittorrent,port"]%% *}" # removing second port from url
Expand Down
123 changes: 53 additions & 70 deletions tools/modules/software/module_cockpit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module_options+=(
["module_cockpit,author"]="@tearran"
["module_cockpit,maintainer"]="@igorpecovnik"
["module_cockpit,feature"]="module_cockpit"
["module_cockpit,example"]="help install remove start stop enable disable status check"
["module_cockpit,example"]="install remove status help"
["module_cockpit,desc"]="Cockpit setup and service setting."
["module_cockpit,status"]="Stable"
["module_cockpit,doc_link"]="https://cockpit-project.org/guide/latest/"
Expand All @@ -14,91 +14,74 @@ module_options+=(
function module_cockpit() {
local title="cockpit"
local condition=$(dpkg -s "cockpit" 2>/dev/null | sed -n "s/Status: //p")

# Convert the example string to an array
local commands
IFS=' ' read -r -a commands <<< "${module_options["module_cockpit,example"]}"

case "$1" in

"${commands[0]}")
## help/menu options for the module
echo -e "\nUsage: ${module_options["module_cockpit,feature"]} <command>"
echo -e "Commands: ${module_options["module_cockpit,example"]}"
echo "Available commands:"
if [[ -z "$condition" ]]; then
echo -e " install\t- Install $title."
else
if [[ "$(systemctl is-active cockpit.socket 2>/dev/null)" == "active" ]]; then
echo -e "\tstop\t- Stop the $title service."
else
echo -e "\tstart\t- Start the $title service."
fi
if [[ $(systemctl is-enabled cockpit.socket) == "enabled" ]]; then
echo -e "\tdisable\t- Disable $title from starting on boot."
elif [[ $(systemctl is-enabled cockpit.socket) == "disabled" ]]; then
echo -e "\tenable\t- Enable $title to start on boot."

## install cockpit
pkg_update
pkg_install cockpit cockpit-ws cockpit-system cockpit-storaged cockpit-machines dnsmasq virtinst qemu-kvm qemu-utils

usermod -a -G libvirt libvirtdbus
usermod -a -G libvirt libvirt-qemu

# add bridged networking if bridges exists on the system
for f in /sys/class/net/*; do
intf=$(basename $f)
if [[ $intf =~ ^br[0-9] ]]; then
cat <<- EOF > /etc/libvirt/kvm-hostbridge-${intf}.xml
<network>
<name>hostbridge-${intf}</name>
<forward mode="bridge"/>
<bridge name="${intf}"/>
</network>
EOF
virsh net-define /etc/libvirt/kvm-hostbridge-${intf}.xml
virsh net-start hostbridge-${intf}
virsh net-autostart hostbridge-${intf}
fi
done
if $DIALOG --title " Reboot required " --yes-button "Reboot" --no-button "Cancel" --yesno \
"A reboot is required to start $title properly. Shall we reboot now?" 7 34; then
reboot
fi
echo -e "\tstatus\t- Show the status of the $title service."
echo -e "\tremove\t- Remove $title."
fi
echo

;;
"${commands[1]}")
## install cockpit
pkg_update
pkg_install cockpit cockpit-ws cockpit-system cockpit-storaged
echo "Cockpit installed successfully."
## remove cockpit
systemctl stop cockpit.socket 2>/dev/null
systemctl stop cockpit 2>/dev/null
systemctl disable cockpit 2>/dev/null
for bridge in $(grep hostbridge /etc/libvirt/kvm-hostbridge-br* | grep -o -P '(?<=name>).*(?=\</name)'); do
virsh net-destroy ${bridge}
virsh net-undefine ${bridge}
done
pkg_remove cockpit cockpit-ws cockpit-system cockpit-storaged cockpit-machines dnsmasq virtinst qemu-kvm qemu-utils

;;
"${commands[2]}")
## remove cockpit
systemctl disable cockpit cockpit.socket
pkg_remove cockpit
echo "Cockpit removed successfully."
if pkg_installed cockpit; then
return 0
else
return 1
fi
;;
"${commands[3]}")
## start cockpit

systemctl start cockpit.socket
echo "Cockpit service started."
;;
"${commands[4]}")
## stop cockpit

systemctl stop cockpit.socket
echo "Cockpit service stopped."
;;
"${commands[5]}")
## enable cockpit
#systemctl enable cockpit
systemctl enable cockpit.socket
echo "Cockpit service enabled."
;;
"${commands[6]}")
## disable cockpit
#systemctl disable cockpit
systemctl disable cockpit.socket
echo "Cockpit service disabled."
;;
"${commands[7]}")
## status cockpit
#systemctl status cockpit
systemctl status cockpit.socket
;;
"${commands[-1]}")
## check cockpit status
if [[ $(systemctl is-active cockpit.socket) == "active" ]]; then
echo "Cockpit service is active."
return 0
elif [[ $(systemctl is-enabled cockpit.socket) == "disabled" ]]; then
echo "Cockpit service is disabled."
return 0
else
return 1
fi
echo -e "\nUsage: ${module_options["module_cockpit,feature"]} <command>"
echo -e "Commands: ${module_options["module_cockpit,example"]}"
echo "Available commands:"
echo -e "\tinstall\t- Install $title."
echo -e "\tremove\t- Remove $title."
echo -e "\tstatus\t- Status $title."
echo
;;
*)
echo "Invalid command. Try: '${module_options["module_cockpit,example"]}'"
${module_options["module_cockpit,feature"]} ${commands[3]}
;;
esac
}

Loading