Skip to content

Instantly share code, notes, and snippets.

@jesherdevsk8
Created October 11, 2024 14:10
Show Gist options
  • Save jesherdevsk8/89f87dbf4f10f32be45de37ee51a6bc9 to your computer and use it in GitHub Desktop.
Save jesherdevsk8/89f87dbf4f10f32be45de37ee51a6bc9 to your computer and use it in GitHub Desktop.

Revisions

  1. jesherdevsk8 created this gist Oct 11, 2024.
    77 changes: 77 additions & 0 deletions systemd-commands.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,77 @@
    ### Comandos básicos do `systemctl`:

    - **Verificar status de serviços:**
    ```bash
    systemctl status nginx
    systemctl status apache2.service
    systemctl status cups
    systemctl status bluetooth.service
    ```

    - **Iniciar, parar e reiniciar serviços:**
    ```bash
    sudo systemctl start apache2.service
    sudo systemctl stop apache2.service
    sudo systemctl restart apache2.service
    ```

    - **Ativar e desativar serviços no boot:**
    ```bash
    sudo systemctl enable apache2.service --now # Ativa e inicia o serviço
    sudo systemctl disable apache2.service --now # Desativa e para o serviço
    ```

    - **Verificar se um serviço está habilitado no boot:**
    ```bash
    sudo systemctl is-enabled apache2.service
    ```

    ### Serviços múltiplos (cups, bluetooth, etc.):

    - **Status de múltiplos serviços:**
    ```bash
    sudo systemctl status cups-browsed.service accounts-daemon.service cups.service cups.socket
    ```

    - **Habilitar e desabilitar múltiplos serviços:**
    ```bash
    sudo systemctl enable cups-browsed.service cups.socket cups.service
    sudo systemctl disable cups-browsed.service cups.socket cups.service --now
    ```

    - **Verificar se múltiplos serviços estão habilitados:**
    ```bash
    systemctl is-enabled cups-browsed.service cups.socket cups.service
    ```

    ### Análise e diagnósticos:

    - **Analisar tempos de inicialização de serviços:**
    ```bash
    systemd-analyze
    systemd-analyze blame
    ```

    - **Monitorar uso de cgroups:**
    ```bash
    systemd-cgtop
    sudo systemd-cgtop -m
    ```

    ### Outros comandos úteis:

    - **Visualizar o conteúdo de unidades de serviço:**
    ```bash
    systemctl cat docker.socket
    systemctl cat cups.socket
    systemctl cat bluetooth

    # SysVinit Service
    cat /etc/init.d/bluetooth
    ```

    - **Listar unidades e verificações adicionais:**
    ```bash
    ls /etc/systemd/system
    ls -l /etc/systemd/system/bluetooth.target.wants
    ```