Published on

Manage Ubuntu with Cockpit

Authors
  • avatar
    Name
    Emil Moe
    Twitter

Introduction

Ubuntu Cockpit is a web-based interface that simplifies the management of your Ubuntu servers. It offers a user-friendly platform where you can easily monitor system performance, manage updates, configure network settings, and handle storage solutions all from your browser.

With Cockpit, you can manage multiple servers, troubleshoot issues, and handle administrative tasks, making server management accessible even for those who prefer a graphical interface over the command line.

Installation

Installing Ubuntu Cockpit on your server is a straightforward process that can be completed in just a few steps. First, ensure your system is updated by running:

apt-get update && apt-get upgrade -y

Next, install Cockpit using the following command:

apt-get install -y cockpit cockpit-pcp

Once installed, enable and start the Cockpit service:

systemctl enable --now cockpit.socket

Cockpit runs on port 9090 by default. To access the Cockpit web interface, open your browser and navigate to http://<your_server_ip>:9090.

Log in using your server's credentials, and you'll find a dashboard that provides an overview of your system's status.

From here, you can explore various features such as system performance monitoring, service management, and network configuration.

Monitor Updates

Create a Slack Incoming Webhook

First, head over to Slack Apps and create a new app by selecting "From Scratch". After your app is set up, navigate to the "Incoming Webhooks" section and enable it.

Generate a new webhook URL for your preferred Slack channel and keep this URL.

Script to Check for Updates and Notify Slack

Next, you'll need to create a script that will check for available updates on your server and send a notification to Slack using the webhook URL.

#!/bin/bash

# Slack webhook URL
WEBHOOK_URL="<your webhook URL>"

# Check for updates
UPDATES=$(apt list --upgradable 2>/dev/null | grep -v "Listing...")

if [ -n "$UPDATES" ]; then
    # Format the message
    MESSAGE="*Updates available on server $(hostname):*\n\`\`\`$UPDATES\`\`\`"

    # Send the message to Slack
    curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"${MESSAGE}\"}" $WEBHOOK_URL
else
    echo "No updates available."
fi

Save the script to /root/monitor and ensure it's executable

nano ~/monitor
chmod +x ~/monitor

Then, set up a cron job to run the script daily at 7 AM:

crontab -e

Add the following line to the crontab file:

0 7 * * * /root/monitor