#!/bin/bash # My simple bash script to turn on, off, and check state of docker and containerd # by dn0r containerd_state=$(systemctl is-active containerd) docker_state=$(systemctl is-active docker) dockon () { sudo systemctl start containerd && sudo systemctl start docker if (($containerd_state == "active")) && (($docker_state == "active")) then clear sleep 1 echo -e "\nSuccess [✔]\n" else echo -e \n"Failed [✗]\n" fi } dockoff () { sudo systemctl stop containerd && sudo systemctl stop docker if (($containerd_state == "inactive")) && (($docker_state == "inactive")) then clear sleep 1 echo -e "\nDocker (and services) stopped [✔]\n" else echo -e "\nUh oh, something went wrong.. [✗]\n" fi } dockstat () { echo -e "\nContainerd: ${containerd_state}" echo -e "\nDocker: ${docker_state}\n" } commands () { echo -e "\nList of commands:" echo "----------------" echo -e "\non - turns on containerd & docker" echo -e "\noff - turns off containerd & docker" echo -e "\nstat - returns service status of docker & containred\n" } case "$1" in $null | "") echo "For commands, use the flag 'help'";; "help") commands;; "on") dockon;; "off") dockoff;; "stat") dockstat;; esac