Command-Line Tool: servbayctl
servbayctl
is a powerful command-line tool provided by ServBay, designed to enable developers to directly manage ServBay's background services from the terminal. With servbayctl
, you can easily perform operations such as starting, stopping, reloading, restarting, force-killing, checking status, and stopping all services. This is especially useful for script automation, quickly toggling service states, or for developers who prefer the command line interface.
This article provides a detailed guide on how to use servbayctl
, including supported commands, parameters, and services.
Overview
ServBay not only offers an intuitive graphical user interface (GUI) to manage your local web development environment, but also includes the command-line interface (CLI) tool servbayctl
. Located in the script
folder within the ServBay installation directory, servbayctl
allows you to control the running state of various software packages installed by ServBay as background services, all through simple commands.
Benefits of using servbayctl
include:
- Automation: Easily integrate service management into your development workflow scripts.
- Efficiency: Quickly start or stop specific services without launching the GUI.
- Flexibility: Ideal for remote SSH connections or headless environments.
- Granular Control: Operate on specific services or versions as needed.
Prerequisites
Before using servbayctl
, please ensure:
ServBay is installed successfully.
You have terminal access on your system.
(Optional but recommended) To make usage convenient, you can add the
/Applications/ServBay/script
directory to your system PATH. This allows you to run theservbayctl
command from anywhere without typing the full path.For Bash or Zsh users, edit your
~/.bash_profile
,~/.bashrc
,~/.zshrc
, or~/.profile
file and add the following line:bashexport PATH="/Applications/ServBay/script:$PATH"
1After saving the file, run
source ~/.bash_profile
(or whichever file you edited) to apply the changes, or simply restart your terminal session.
Syntax
The basic syntax for the servbayctl
command is as follows:
servbayctl <command> <service> [parameters]
<command>
: The operation you wish to perform (e.g.,start
,stop
,restart
).<service>
: The service name you want to operate on (e.g.,php
,mysql
,caddy
).[parameters]
: Optional parameter to specify the version or scope (e.g.,7.4
or-all
).
According to the servbayctl
usage info from ServBay, supported commands and the syntax structure are as follows:
Usage: /Applications/ServBay/script/servbayctl {start|stop|reload|restart|kill|status|stop-all} {php|mariadb|mysql|postgresql|redis|memcached|caddy|nginx|apache|dnsmasq|mongodb|rabbitmq|cloudflared|frpc|mailpit|web|ollama} [-all|version]
Note: The stop-all
command does not accept a service name or parameters. It stops all services managed by ServBay.
Detailed Command Reference
Below are explanations and examples for each command supported by servbayctl
:
start
- Start a Service
Starts the specified service. You may specify a particular version or use the -all
parameter to start all installed versions of the service.
servbayctl start <service> [-all|version]
- Example: Start PHP 8.1 servicebash
servbayctl start php 8.1
1 - Example: Start all installed PHP versionsbash
servbayctl start php -all
1 - Example: Start MySQL service with default configurationbash
servbayctl start mysql
1
stop
- Stop a Service
Stops the specified service. You may specify a particular version or use -all
to stop all versions of the service.
servbayctl stop <service> [-all|version]
- Example: Stop PHP 7.4 servicebash
servbayctl stop php 7.4
1 - Example: Stop all MariaDB versions installedbash
servbayctl stop mariadb -all
1 - Example: Stop Redis servicebash
servbayctl stop redis
1
reload
- Reload Service Configuration
Reloads the configuration of the specified service. This is often used to apply configuration changes without a full restart. Not all services support hot reload.
servbayctl reload <service> [-all|version]
- Example: Reload configuration for Caddy web serverbash
servbayctl reload caddy
1 - Example: Reload configuration for all installed PHP versions (if supported)bash
servbayctl reload php -all
1
restart
- Restart a Service
Restarts the specified service. This is equivalent to stopping and then starting the service.
servbayctl restart <service> [-all|version]
- Example: Restart PostgreSQL database servicebash
servbayctl restart pgsql
1 - Example: Restart all installed Redis versions (if multiple are installed)bash
servbayctl restart redis -all
1
kill
- Force Kill the Service Process
Force-terminates the process of the specified service. This is a more aggressive form of stopping a service and should be used with caution, as it may lead to data loss or corruption (especially for database services). Typically used only when the service cannot be stopped normally.
servbayctl kill <service> [-all|version]
- Example: Force-kill PHP 7.4 service processbash
servbayctl kill php 7.4
1 - Example: Force-kill all Memcached service processesbash
servbayctl kill memcached -all
1
status
- Check Service Status
Displays the current running status of the specified service.
servbayctl status <service> [-all|version]
- Example: Check Caddy service statusbash
servbayctl status caddy
1 - Example: Check status for all installed MySQL versionsbash
servbayctl status mysql -all
1
stop-all
- Stop All ServBay Services
Stops all currently running background services managed by ServBay. This is a global command and does not accept service names or version parameters.
servbayctl stop-all
- Example: Stop all ServBay background servicesbash
servbayctl stop-all
1
List of Supported Services
Based on the servbayctl
usage information, the tool can directly control the following types of background services:
php
: Manage multiple versions of PHP-FPM processes.mariadb
: Manage MariaDB database service.mysql
: Manage MySQL database service.postgresql
: Manage PostgreSQL database service.redis
: Manage Redis cache/database service.memcached
: Manage Memcached cache service.caddy
: Manage Caddy web server service.nginx
: Manage Nginx web server service.apache
: Manage Apache HTTP server service.dnsmasq
: Manage the built-in DNS service of ServBay.mongodb
: Manage MongoDB database service.rabbitmq
: Manage RabbitMQ message queue service.cloudflared
: Manage Cloudflare Tunnel service (if installed and configured).frpc
: Manage Fatedier/frp client service (if installed and configured).mailpit
: Manage Mailpit email capture tool service.web
: Manage Web services (the exact meaning may vary depending on actual usage, e.g., active web server or ServBay-related web interfaces).ollama
: Manage Ollama local LLM service.
Note that servbayctl
can now directly manage a wide range of core background services including Nginx and Apache. Although ServBay supports the installation and use of various other software packages (like Java, Python, Go, .NET, Ruby, Rust, etc.), these packages are generally not run as background services directly controlled by servbayctl
. Instead, they are typically invoked from the terminal or have their own management systems. servbayctl
mainly focuses on managing the core background daemon services listed above.
Common Usage Examples
Here are several common scenarios where servbayctl
is used:
Quickly switch PHP versions for testing:
bashservbayctl stop php -all servbayctl start php 8.2
1
2Restart database service to apply config changes:
bash# Assume you've edited my.cnf or my.ini servbayctl restart mysql
1
2Ensure all services are stopped (e.g., before shutting down or updating ServBay):
bashservbayctl stop-all
1Check if a web server is running:
bashservbayctl status caddy
1Automate environment startup via script:
bash#!/bin/bash echo "Stopping all ServBay services..." servbayctl stop-all echo "Starting required services..." servbayctl start php 8.1 servbayctl start mysql servbayctl start caddy servbayctl start redis echo "ServBay services started."
1
2
3
4
5
6
7
8
9
10
11
12
Notes and Best Practices
- Add to PATH: It's strongly recommended to add the directory containing
servbayctl
to your system PATH to simplify command input. - Use
kill
with caution: Thekill
command forcibly terminates processes and may result in unsaved data loss or abnormal service states. Unless a service cannot be stopped normally, prefer usingstop
orrestart
. stop-all
is a global action:stop-all
will halt all ServBay-managed background services. Make sure this is what you intend to do.- Version parameter: When using the
version
parameter, make sure the specified version is already installed and supported by ServBay. You can check installed versions in the ServBay GUI. - Error handling: If a
servbayctl
command fails, it may output error messages to the terminal. Troubleshoot based on these messages or check the ServBay log files (usually located in thelogs
folder in the ServBay installation directory) for more details. - Combining GUI and CLI:
servbayctl
complements the GUI. For complex configuration changes or an overview, the GUI remains convenient and user-friendly.
Frequently Asked Questions (FAQ)
Q: What should I do if I get a command not found
error when running servbayctl
?
A: This usually means the /Applications/ServBay/script
directory hasn’t been added to your system PATH. Please refer to the “Prerequisites” section above for instructions on adding it.
Q: I ran servbayctl start <service>
, but the service didn't start. How do I troubleshoot?
A:
- Use
servbayctl status <service>
to check the service status again. - Check the
logs
folder under the ServBay install directory for the error log file corresponding to the service. This often provides details on why startup failed. - Try starting the same service via the ServBay GUI, as the GUI may show friendlier error messages.
- Verify the service’s configuration file for errors.
Q: Does the -all
parameter apply to all services?
A: The -all
parameter primarily applies to services that support installing multiple versions, such as PHP. For most databases (MySQL, PostgreSQL, etc.) and web servers (Caddy), there’s usually only one active instance—using -all
is the same as not specifying any version, but for clarity, just use the service name. For services like Redis or Memcached, which may run multiple instances on different ports, -all
could control all those instances (the specific behavior depends on ServBay’s implementation).
Summary
servbayctl
is ServBay’s robust command-line interface for developers, dramatically increasing flexibility and efficiency when managing local development environment services. Mastering commands like start
, stop
, reload
, restart
, kill
, status
, and stop-all
—along with using the version
and -all
parameters—enables you to control a wide range of services like PHP, MySQL, MariaDB, PostgreSQL, MongoDB, Redis, Memcached, Caddy, and more directly from your terminal. This helps streamline automation workflows and optimize your overall development experience.