Skip to content
Merged
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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
- [st install](#st-install)
- [st uninstall](#st-uninstall)
- [st system](#st-system)
- [st systemctl](#st-systemctl)
- [st network](#st-network)
- [st telegram](#st-telegram)
- [st tmux](#st-tmux)
Expand Down Expand Up @@ -236,6 +237,23 @@ System management utilities for updates and diagnostics:
| Show SSD SMART stats | `st system smart` | `st sys smart` |
| Show disk usage stats | `st system disk` | `st sys disk` |

### st systemctl

Systemd control utilities for managing services and viewing logs:

| Description | Full Command | Alias |
| --------------------------------- | ------------------------------------------- | --------------- |
| Systemd Control Utilities | `st systemctl` | `st sc` |
| Start a systemd service | `st systemctl start <service>` | `st sc start` |
| Stop a systemd service | `st systemctl stop <service>` | `st sc stop` |
| Restart a systemd service | `st systemctl restart <service>` | `st sc restart` |
| Check status of a systemd service | `st systemctl status <service>` | `st sc status` |
| Enable a service to start on boot | `st systemctl enable <service>` | `st sc enable` |
| Disable a service from starting | `st systemctl disable <service>` | `st sc disable` |
| List all systemd services | `st systemctl list` | `st sc list` |
| View service logs | `st systemctl logs <service>` | `st sc logs` |
| Reload systemd manager config | `st systemctl daemon-reload` | `st sc daemon-reload` |

### st network

Network helper scripts:
Expand Down
1 change: 1 addition & 0 deletions bashly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ help: Server Tools CLI
version: 1.0.0
commands:
- import: src/config/system.yml
- import: src/config/systemctl.yml
- import: src/config/install.yml
- import: src/config/uninstall.yml
- import: src/config/rclone.yml
Expand Down
4 changes: 4 additions & 0 deletions spells/systemctl/daemon-reload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

log_info "Reloading daemon to apply systemd unit file changes"
systemctl daemon-reload
log_info "Daemon reloaded successfully."
10 changes: 10 additions & 0 deletions spells/systemctl/disable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SERVICE_NAME="${args[service]}"
# Check argument
if [[ -z "$SERVICE_NAME" ]]; then
log_error "Please provide a service name. Usage: systemctl disable <service-name>"
exit 1
fi

log_info "Disabling systemd service from starting on boot: $SERVICE_NAME"
systemctl disable "$SERVICE_NAME"
log_info "Service '$SERVICE_NAME' disabled from starting on boot."
10 changes: 10 additions & 0 deletions spells/systemctl/enable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SERVICE_NAME="${args[service]}"
# Check argument
if [[ -z "$SERVICE_NAME" ]]; then
log_error "Please provide a service name. Usage: systemctl enable <service-name>"
exit 1
fi

log_info "Enabling systemd service to start on boot: $SERVICE_NAME"
systemctl enable "$SERVICE_NAME"
log_info "Service '$SERVICE_NAME' enabled to start on boot."
3 changes: 3 additions & 0 deletions spells/systemctl/list.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
log_info "Listing all systemd services:"
systemctl list-units --type=service --all --no-pager
log_info "Service listing completed."
22 changes: 22 additions & 0 deletions spells/systemctl/logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
SERVICE_NAME="${args[service]}"
# Check argument
if [[ -z "$SERVICE_NAME" ]]; then
log_error "Please provide a service name. Usage: systemctl logs <service-name>"
exit 1
fi

log_info "Fetching logs for systemd service: $SERVICE_NAME"
journalctl -u "$SERVICE_NAME" --no-pager
log_info "Logs fetched."

log_warn "Note: You can use 'journalctl -u $SERVICE_NAME -f' to follow the logs in real-time."

log_info "Do you want to do that now? (y/n)"
read -r FOLLOW_LOGS
if [[ "$FOLLOW_LOGS" != "y" && "$FOLLOW_LOGS" != "Y" ]]; then
log_info "Exiting without following logs."
exit 0
else
log_info "Following logs for service: $SERVICE_NAME"
journalctl -u "$SERVICE_NAME" -f
fi
10 changes: 10 additions & 0 deletions spells/systemctl/restart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SERVICE_NAME="${args[service]}"
# Check argument
if [[ -z "$SERVICE_NAME" ]]; then
log_error "Please provide a service name. Usage: systemctl restart <service-name>"
exit 1
fi

log_info "Restarting systemd service: $SERVICE_NAME"
systemctl restart "$SERVICE_NAME"
log_info "Service '$SERVICE_NAME' restarted."
10 changes: 10 additions & 0 deletions spells/systemctl/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SERVICE_NAME="${args[service]}"
# Check argument
if [[ -z "$SERVICE_NAME" ]]; then
log_error "Please provide a service name. Usage: systemctl start <service-name>"
exit 1
fi

log_info "Starting systemd service: $SERVICE_NAME"
systemctl start "$SERVICE_NAME"
log_info "Service '$SERVICE_NAME' started."
14 changes: 14 additions & 0 deletions spells/systemctl/status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SERVICE_NAME="${args[service]}"

# Check argument
if [[ -z "$SERVICE_NAME" ]]; then
log_error "Please provide a service name. Usage: systemctl status <service-name>"
exit 1
fi

log_info "Checking status of systemd service: $SERVICE_NAME"


systemctl status "$SERVICE_NAME" --no-pager

log_info "Status check completed."
11 changes: 11 additions & 0 deletions spells/systemctl/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SERVICE_NAME="${args[service]}"

# Check argument
if [[ -z "$SERVICE_NAME" ]]; then
log_error "Please provide a service name. Usage: systemctl stop <service-name>"
exit 1
fi

log_info "Stopping systemd service: $SERVICE_NAME"
systemctl stop "$SERVICE_NAME"
log_info "Service '$SERVICE_NAME' stopped."
23 changes: 22 additions & 1 deletion spells/ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fi
# Ordered Menu Definitions
# -------------------------------

MAIN_MENU_ORDER=(install uninstall system docker network ssh rclone restic resticprofile tmux tailscale config)
MAIN_MENU_ORDER=(install uninstall system systemctl docker network ssh rclone restic resticprofile tmux tailscale config)

declare -A COMMAND_GROUPS=(
[install]="Install popular packages"
Expand Down Expand Up @@ -41,6 +41,7 @@ declare -A SUBCOMMANDS_order_resticprofile=( [0]=show [1]=snapshots [2]=stats [3
declare -A SUBCOMMANDS_order_tmux=( [0]=list-sessions [1]=new-session [2]=attach-session [3]=kill-session [4]=cheatsheet )
declare -A SUBCOMMANDS_order_tailscale=( [0]=up [1]=down [2]=status )
declare -A SUBCOMMANDS_order_config=( [0]=show [1]=edit [2]=verify [3]=source )
declare -A SUBCOMMANDS_order_systemctl=( [0]=start [1]=stop [2]=restart [3]=status [4]=enable [5]=disable [6]=list [7]=logs [8]=daemon-reload )

# Subcommand descriptions per group
declare -A SUBCOMMANDS_install=( [all]="Install all packages" )
Expand All @@ -59,6 +60,17 @@ declare -A SUBCOMMANDS_docker=(
[start-all]="Start all containers"
[manage-stacks]="Manage Compose stacks"
)
declare -A SUBCOMMANDS_systemctl=(
[start]="Start a systemd service"
[stop]="Stop a systemd service"
[restart]="Restart a systemd service"
[status]="Check the status of a systemd service"
[enable]="Enable a service to start on boot"
[disable]="Disable a service from starting on boot"
[list]="List all systemd services"
[logs]="View logs for a systemd service"
[daemon-reload]="Reload systemd manager configuration"
)
declare -A SUBCOMMANDS_network=(
[interfaces]="Show interfaces"
[linkspeed]="Link speed"
Expand Down Expand Up @@ -248,6 +260,15 @@ cmd::tmux_cheatsheet() { st tmux cheatsheet; }

cmd::tailscale_up() { st tailscale up; }
cmd::tailscale_down() { st tailscale down; }
cmd::systemctl_start() { st systemctl start; }
cmd::systemctl_stop() { st systemctl stop; }
cmd::systemctl_restart() { st systemctl restart; }
cmd::systemctl_status() { st systemctl status; }
cmd::systemctl_enable() { st systemctl enable; }
cmd::systemctl_disable() { st systemctl disable; }
cmd::systemctl_list() { st systemctl list; }
cmd::systemctl_logs() { st systemctl logs; }
cmd::systemctl_daemon-reload(){ st systemctl daemon-reload; }
cmd::tailscale_status() { st tailscale status; }

cmd::rclone_dry-sync() {
Expand Down
93 changes: 93 additions & 0 deletions src/config/systemctl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: systemctl
alias: sc
help: Systemd Control Utilities
examples:
- st systemctl start nginx
- st sc stop apache2
- st systemctl restart mysql
- st sc status postgresql
- st systemctl enable docker
- st sc disable ufw
- st systemctl list
- st sc logs nginx --follow
- st systemctl daemon-reload
commands:
- name: start
help: Start a systemd service
examples:
- st systemctl start nginx
- st sc start apache2
args:
- name: service
help: Name of the service to start

- name: stop
help: Stop a systemd service
examples:
- st systemctl stop nginx
- st sc stop apache2
args:
- name: service
help: Name of the service to stop

- name: restart
help: Restart a systemd service
examples:
- st systemctl restart mysql
- st sc restart postgresql
args:
- name: service
help: Name of the service to restart

- name: status
help: Check the status of a systemd service
examples:
- st systemctl status nginx
- st sc status apache2
args:
- name: service
help: Name of the service to check status for

- name: enable
help: Enable a systemd service to start on boot
alias: e
examples:
- st systemctl enable docker
- st sc enable ufw
args:
- name: service
help: Name of the service to enable

- name: disable
help: Disable a systemd service from starting on boot
alias: d
examples:
- st systemctl disable docker
- st sc disable ufw
args:
- name: service
help: Name of the service to disable

- name: list
help: List all systemd services and their statuses
alias: ls
examples:
- st systemctl list
- st sc list

- name: logs
help: View logs for a systemd service
alias: lg
examples:
- st systemctl logs nginx --follow
- st sc logs apache2 --since "1 hour ago"
args:
- name: service
help: Name of the service to view logs for

- name: daemon-reload
help: Reload systemd manager configuration
alias: dr
examples:
- st systemctl daemon-reload
- st sc daemon-reload