A modern, Flask-based web interface for managing systemd services on a Linux server. Provides a clean UI built with Tailwind CSS, featuring frosted glass effects, for viewing, controlling, and even editing service unit files.
⚠️ Security Warning: This application grants specific sudo
privileges to the web server user (www-data
by default) to interact with systemctl
. The file editing feature, while powerful, is extremely dangerous if not properly secured and configured. Incorrect usage or security misconfiguration could severely compromise or break your system. Use with extreme caution, especially in production environments. Consider disabling the editing feature if not strictly required.
.service
units (active and inactive).daemon-reload
).systemctl status <service>
.systemctl cat
.sudoers
configuration.python3-venv
).sudo
privileges for installation.The provided install.sh
script automates most of the setup process.
Important: Review the install.sh
script before running it to understand the actions it will perform on your system.
Clone the Repository:
git clone https://github.com/1999AZZAR/Systemd-Service-Manager-Web-UI.git
cd Systemd-Service-Manager-Web-UI
Run the Installation Script:
sudo ./install.sh
The script will:
python3-venv
)./opt/servicemanager
).app.py
, static/
, templates/
).venv
) and install Flask.www-data:www-data
).sudoers
rules for the service user in /etc/sudoers.d/90-servicemanager
(allowing specific systemctl
commands and tee
if file editing is intended).systemd
service (servicemanager.service
).service_manager
) to the invoking user's .bashrc
for easy access.Verify Service Status:
sudo systemctl status servicemanager.service
It should show as active (running)
.
(Optional) Source Bashrc: If the alias was added, open a new terminal or run source ~/.bashrc
for the service_manager
command to become available.
Several parts of the application can be configured:
app.py
:
SERVICE_USER
: The user the Flask app runs as (must match servicemanager.service
and sudoers
). Default: www-data
.ALLOWED_WRITE_DIRS
: Critical for security if editing is enabled. A list of absolute directory paths where the application is allowed to write files using sudo tee
. Default: ["/etc/systemd/system/"]
. Restrict this as much as possible.servicemanager.service
:
User
, Group
: Must match SERVICE_USER
in app.py
.WorkingDirectory
: Should point to the application directory (e.g., /opt/servicemanager
).ExecStart
: Ensure this points to the correct Python executable within the virtual environment (the install.sh
script attempts to set this automatically). If using Gunicorn/uWSGI, modify this line accordingly.install.sh
:
APP_NAME
, APP_DIR
, SERVICE_USER
, FLASK_PORT
, etc.) can be modified before running the script.Sudoers (/etc/sudoers.d/90-servicemanager
):
SERVICE_USER
./usr/bin/tee
lines should only be present if you intend to use the file editing feature. Ensure the path(s) specified for tee
match the locations you actually want to allow writing to (e.g., /etc/systemd/system/*.service
). Avoid overly broad permissions like /usr/bin/tee /etc/*
!Tailwind (templates/index.html
):
tailwind.config
object within the <script>
tag can be modified to customize colors, fonts, etc., without needing a build step (thanks to the Play CDN).visudo
)The install.sh
script creates the necessary sudoers
file (/etc/sudoers.d/90-servicemanager
) automatically. However, if you need to modify it later (e.g., to add or remove tee
permissions for file editing, or change the allowed commands), always use the visudo
command. Never edit sudoers
files directly with a text editor like nano
or vim
.
visudo
locks the sudoers
file and performs syntax checking before saving, preventing you from locking yourself out of sudo
access due to errors.
Steps:
Open the specific file with visudo
:
sudo visudo -f /etc/sudoers.d/90-servicemanager
(Replace 90-servicemanager
if you changed the SUDOERS_FILE_NAME
in install.sh
)
Edit the file: visudo
will open the file in your system's default command-line editor (often nano
or vi
). Make your changes carefully. For example, to enable editing service files in /etc/systemd/system/
:
# Add or uncomment these lines:
www-data ALL=(ALL) NOPASSWD: /usr/bin/tee /etc/systemd/system/*.service
To disable editing, comment out or delete those /usr/bin/tee
lines.
Save and Exit:
Ctrl+X
, then Y
to confirm saving, then Enter
to confirm the filename.Esc
, then type :wq
and press Enter
.Syntax Check: visudo
will automatically check the syntax.
"parsed OK"
, the changes are saved.e
) to fix the error. Do not exit without fixing the error, as this could break sudo
.Important: Always double-check the permissions you are granting, especially NOPASSWD
commands and file writing permissions like tee
.
⚠️ WARNING: Granting
NOPASSWD
for service file editing and/or journal access effectively grants root privileges for those operations without requiring a password. Misconfiguration or compromise of the web UI could:
- Modify or delete critical system unit files.
- Enable an attacker to install or alter services.
- Expose or tamper with sensitive system logs.
Recommendations:
- Restrict commands to the narrowest possible paths and arguments (e.g.,
/etc/systemd/system/*.service
).- Avoid broad wildcards that may cover unintended files.
- Always validate changes with
visudo -c
and keep backup copies of sudoers files.- Consider enabling logging/auditing (e.g., via
auditd
) to monitor sudo and journal access.
Access the UI: Open your web browser and navigate to:
http://<your-server-ip>:5001
(Replace <your-server-ip>
and 5001
if you changed the port).http://localhost:5001
if accessing from the server itself.service_manager
.Interface Overview:
sudo systemctl daemon-reload
. * **Status Modal:** Shows unit load/active/sub status and provides a **View Logs** button to fetch recent journal entries.
* **File Modal:** Displays and optionally edits unit file content within configured `ALLOWED_WRITE_DIRS`.
Please read carefully:
www-data
) is granted passwordless sudo
access for specific systemctl
commands and potentially tee
. This is the primary security risk. Ensure the sudoers
file (/etc/sudoers.d/90-servicemanager
) is correctly configured, has 0440
permissions, is owned by root:root
, and only allows necessary commands. Use visudo
for editing.sudoers
rules for /usr/bin/tee
to function.ALLOWED_WRITE_DIRS
in app.py
) and checks against symlinks, but these might not be foolproof.app.py
and the sudoers
file.0.0.0.0
, making the UI accessible from any machine on the network.sudo journalctl -u servicemanager.service -f
sudo
, systemctl
, or Python parsing (parse_list_units
).sudoers
configuration: sudo visudo -c
and check permissions/content of /etc/sudoers.d/90-servicemanager
. Use sudo visudo -f /etc/sudoers.d/90-servicemanager
to edit if needed.sudo -u www-data /bin/systemctl list-units --type=service --all --no-legend --no-pager
. Does it work? Does the output look parseable?sudoers
file. See previous point and the "Editing Sudoers Safely" section.sudo systemctl status servicemanager.service
): Check the logs (journalctl -u servicemanager.service
) for Python errors, path issues, or port conflicts. Ensure the ExecStart
path in the .service
file is correct.sudoers
rules for /usr/bin/tee
using sudo visudo -f /etc/sudoers.d/90-servicemanager
. Are they present and correct for the target path?ALLOWED_WRITE_DIRS
in app.py
. Does it include the parent directory of the target file?journalctl
) for specific errors from app.py
or the tee
command.A script is provided to remove the application and its configurations.
Warning: This will permanently delete the application files and configuration.
cd ..
).sudo ./service-manager/uninstall.sh # Adjust path if you cloned to a different name
The script will attempt to:servicemanager.service
./etc/systemd/system/servicemanager.service
)./etc/sudoers.d/90-servicemanager
)./opt/servicemanager
, will prompt for confirmation)..bashrc
.Contributions are welcome! Please feel free to submit pull requests or open issues for bugs, feature requests, or improvements.