GNU/Linux - systemd Servis Yönetim Aracı v2.1

Programlama ve Script dilleri konusunda bilgi paylaşım alanıdır.
Cevapla
Kullanıcı avatarı
TRWE_2012
Zettabyte1
Zettabyte1
Mesajlar: 15597
Kayıt: 25 Eyl 2013, 13:38
cinsiyet: Erkek
Teşekkür etti: 2708 kez
Teşekkür edildi: 5621 kez

GNU/Linux - systemd Servis Yönetim Aracı v2.1

Mesaj gönderen TRWE_2012 »

Resim
KOD İÇERİĞİ : (servis_yonetim.sh)

Kod: Tümünü seç

#!/bin/bash
# ============================================================
# Servis Yonetim Araci v2.1
# Yazan   : TRWE_2012
# Gelistirme : TRWE_2012
# Sistem  : GNU/Linux - systemd
# ============================================================

# Renk tanimlari
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # Renk sifirla

# ------------------------------------------------------------
# FONKSIYONLAR
# ------------------------------------------------------------

# Çıkış fonksiyonu
cikis() {
    echo -e "${YELLOW}Cikiliyor...${NC}"
    exit "${1:-0}"
}

# Başlık yazdır
baslik() {
    clear
    echo -e "${BLUE}============================================${NC}"
    echo -e "${BLUE}   Servis Yonetim Aracı v2.1               ${NC}"
    echo -e "${BLUE}============================================${NC}"
    echo
}

# Servis durumunu özet göster
servis_durum_goster() {
    local servis="$1"
    echo -e "${BLUE}--- Servis Bilgisi ---${NC}"
    echo -e "Ad          : ${servis}"
    echo -ne "Aktif durum : "
    if systemctl is-active --quiet "$servis"; then
        echo -e "${GREEN}Calisiyor${NC}"
    else
        echo -e "${RED}Calısmiyor${NC}"
    fi
    echo -ne "Baslatma    : "
    ENABLED=$(systemctl is-enabled "$servis" 2>/dev/null)
    case "$ENABLED" in
        enabled)  echo -e "${GREEN}Otomatik (enabled)${NC}" ;;
        disabled) echo -e "${YELLOW}Elle (disabled)${NC}" ;;
        masked)   echo -e "${RED}Devre Disi (masked)${NC}" ;;
        *)        echo -e "${YELLOW}${ENABLED}${NC}" ;;
    esac
    echo
}

# Servisleri listele
servis_listele() {
    baslik
    echo -e "${BLUE}--- Sistemdeki Servisler ---${NC}"
    echo
    echo -e "${BLUE}Filtre secin:${NC}"
    echo "  1 - Tum servisler"
    echo "  2 - Sadece çalısan servisler"
    echo "  3 - Sadece durdurulmuş servisler"
    echo "  4 - Sadece otomatik başlayanlar (enabled)"
    echo "  5 - Sadece devre dışı olanlar (disabled)"
    echo "  6 - Geri dön(menü)"
    echo
    read -rp "Seciminiz [1-6] : " FILTRE

    echo
    case $FILTRE in
        1)
            echo -e "${YELLOW}Tum servisler listeleniyor...${NC}\n"
            systemctl list-unit-files --type=service --no-pager | \
                awk 'NR>1 && NF>0 {printf "%-45s %s\n", $1, $2}' | \
                grep -v "^$" | head -60
            ;;
        2)
            echo -e "${GREEN}Calisan servisler:${NC}\n"
            systemctl list-units --type=service --state=running --no-pager | \
                awk 'NR>1 && /\.service/ {printf "%-45s %-10s %s\n", $1, $3, $4}'
            ;;
        3)
            echo -e "${RED}Durmus servisler:${NC}\n"
            systemctl list-units --type=service --state=dead --no-pager | \
                awk 'NR>1 && /\.service/ {printf "%-45s %-10s %s\n", $1, $3, $4}'
            ;;
        4)
            echo -e "${GREEN}Otomatik baslayan servisler (enabled):${NC}\n"
            systemctl list-unit-files --type=service --state=enabled --no-pager | \
                awk 'NR>1 && NF>0 {print $1}'
            ;;
        5)
            echo -e "${YELLOW}Devre disi servisler (disabled):${NC}\n"
            systemctl list-unit-files --type=service --state=disabled --no-pager | \
                awk 'NR>1 && NF>0 {print $1}'
            ;;
        6) return ;;
        *)
            echo -e "${RED}Gecersiz secim.${NC}"
            ;;
    esac
    echo
    read -rp "Devam etmek icin Enter'a basin..." _
}

# ------------------------------------------------------------
# KONTROLLER
# ------------------------------------------------------------

# Root kontrolü
if [ "$EUID" -eq 0 ]; then
    echo -e "${YELLOW}Uyari: Script root olarak calistirilıyor.${NC}"
    echo -e "${YELLOW}Sudo kullanmaya gerek yok, devam ediliyor...${NC}"
    SUDO_CMD=""
else
    SUDO_CMD="sudo"
fi

# systemd kontrolü
if ! command -v systemctl >/dev/null 2>&1; then
    echo -e "${RED}Hata: Bu sistem systemd kullanmiyor.${NC}"
    cikis 1
fi

# systemd aktif mi
if ! systemctl is-system-running >/dev/null 2>&1; then
    echo -e "${YELLOW}Uyari: systemd tam olarak aktif degil (${$(systemctl is-system-running)}). Devam ediliyor...${NC}"
fi

# ------------------------------------------------------------
# ANA MENU
# ------------------------------------------------------------

while true; do
    baslik
    echo -e "${BLUE}--- Ana Menu ---${NC}"
    echo "  1 - Servisleri Listele"
    echo "  2 - Servis Yonet (enable/disable/mask)"
    echo "  3 - Çıkış"
    echo
    read -rp "Seciminiz [1-3] : " ANA_SECIM

    case $ANA_SECIM in
        1)
            servis_listele
            ;;
        2)
            baslik

            # Servis adı al
            read -rp "Servis adini girin (ornek: ssh.service) : " SERVICE

            # Bos giris kontrolu
            if [ -z "$SERVICE" ]; then
                echo -e "${YELLOW}Bos giris. Islem iptal edildi.${NC}"
                continue
            fi

            # .service uzantisi yoksa ekle
            if [[ "$SERVICE" != *.* ]]; then
                SERVICE="${SERVICE}.service"
                echo -e "${YELLOW}Not: Uzanti eklendi -> ${SERVICE}${NC}"
            fi

            # Servis var mi kontrolu
            if ! systemctl list-unit-files --type=service | grep -q "^${SERVICE}"; then
                if ! systemctl list-units --type=service --all | grep -q "${SERVICE}"; then
                    echo -e "${RED}Hata: Servis bulunamadi -> ${SERVICE}${NC}"
                    read -rp "Devam etmek icin Enter'a basin..." _
                    continue
                fi
            fi

            echo
            servis_durum_goster "$SERVICE"

            # Islem menusu
            echo -e "${BLUE}--- Baslatma Turunu Secin ---${NC}"
            echo "  1 - Otomatik (enable)    : Sistem acilisinda otomatik baslar"
            echo "  2 - Elle    (disable)    : Sistem acilisinda baslamaz"
            echo "  3 - Devre Disi (mask)    : Tamamen kilitleniyor, baslatilamaz"
            echo "  4 - Unmask               : Mask kilidini kaldir"
            echo "  5 - Geri don"
            echo
            read -rp "Seciminiz [1-5] : " CHOICE

            case $CHOICE in
                1) ACTION="enable"  ;;
                2) ACTION="disable" ;;
                3) ACTION="mask"    ;;
                4) ACTION="unmask"  ;;
                5) continue ;;
                *)
                    echo -e "${RED}Gecersiz secim.${NC}"
                    read -rp "Devam etmek icin Enter'a basin..." _
                    continue
                    ;;
            esac

            # Onay
            echo
            echo -e "${YELLOW}Islem  : ${ACTION}${NC}"
            echo -e "${YELLOW}Servis : ${SERVICE}${NC}"
            echo
            read -rp "Devam edilsin mi? (e/h) : " CONFIRM

            if [[ "$CONFIRM" != "e" && "$CONFIRM" != "E" ]]; then
                echo -e "${YELLOW}Islem iptal edildi.${NC}"
                read -rp "Devam etmek icin Enter'a basin..." _
                continue
            fi

            # Islemi uygula
            echo
            if $SUDO_CMD systemctl "$ACTION" "$SERVICE"; then
                echo -e "${GREEN}Islem basariyla tamamlandi.${NC}"
                echo
                servis_durum_goster "$SERVICE"
            else
                echo -e "${RED}Hata: Islem basarisiz oldu.${NC}"
            fi
            read -rp "Devam etmek icin Enter'a basin..." _
            ;;
        3)
            cikis 0
            ;;
        *)
            echo -e "${RED}Gecersiz secim.${NC}"
            sleep 1
            ;;
    esac
done
EKRAN GÖRÜNTÜLERİ : (Sistem : GNU/Linux Mint 22.2 LXDE v13.0 x64)
Resim
Resim
Kullanıcı avatarı
burak35
Zettabyte4
Zettabyte4
Mesajlar: 18103
Kayıt: 07 Eki 2016, 13:06
cinsiyet: Erkek
Teşekkür etti: 10513 kez
Teşekkür edildi: 12293 kez

Re: GNU/Linux - systemd Servis Yönetim Aracı v2.1

Mesaj gönderen burak35 »

Windowstaki cmd uzantılı kodlar gibi sanırım.
Kullanıcı avatarı
TRWE_2012
Zettabyte1
Zettabyte1
Mesajlar: 15597
Kayıt: 25 Eyl 2013, 13:38
cinsiyet: Erkek
Teşekkür etti: 2708 kez
Teşekkür edildi: 5621 kez

Re: GNU/Linux - systemd Servis Yönetim Aracı v2.1

Mesaj gönderen TRWE_2012 »

burak35 yazdı: 04 Mar 2026, 16:46 Windowstaki cmd uzantılı kodlar gibi sanırım.
Evet..Zaten .vbs kodlarından dönüştürüldü benim tarafımdan.... :-) 8)
Kullanıcı avatarı
burak35
Zettabyte4
Zettabyte4
Mesajlar: 18103
Kayıt: 07 Eki 2016, 13:06
cinsiyet: Erkek
Teşekkür etti: 10513 kez
Teşekkür edildi: 12293 kez

Re: GNU/Linux - systemd Servis Yönetim Aracı v2.1

Mesaj gönderen burak35 »

Servis olayı biraz değişken olduğu için ben reg tweak hazırlamamıştım. Elle deneyerek kapattım hepsini.
sonrada öylece kaldı.
Kullanıcı avatarı
TRWE_2012
Zettabyte1
Zettabyte1
Mesajlar: 15597
Kayıt: 25 Eyl 2013, 13:38
cinsiyet: Erkek
Teşekkür etti: 2708 kez
Teşekkür edildi: 5621 kez

Re: GNU/Linux - systemd Servis Yönetim Aracı v2.1

Mesaj gönderen TRWE_2012 »

burak35 yazdı: 04 Mar 2026, 16:49 Servis olayı biraz değişken olduğu için ben reg tweak hazırlamamıştım. Elle deneyerek kapattım hepsini.
sonrada öylece kaldı.
Manuel daha iyidir.En azından ne yaptığını bilirsin.
Kullanıcı avatarı
burak35
Zettabyte4
Zettabyte4
Mesajlar: 18103
Kayıt: 07 Eki 2016, 13:06
cinsiyet: Erkek
Teşekkür etti: 10513 kez
Teşekkür edildi: 12293 kez

Re: GNU/Linux - systemd Servis Yönetim Aracı v2.1

Mesaj gönderen burak35 »

Aynen. Windows 10 a ilk geçtiğimde sırayla kapatarak deneyerek devam etmiştim. Bi sıkıntı yaşanmamıştı.
Tabikide herşeyide kapatmamak lazım. İnsanları uyaralımda.
Cevapla

“Programlama ve Script dilleri” sayfasına dön