How to Start and Stop Multiple Hugo Servers at Once
About Starting Multiple Hugo Servers
This article explains how to start servers for multiple Hugo sites at the same time from a single command prompt.
Here, assume that several Hugo projects exist under the home directory as follows.
~/website/site1
~/website/site2
~/website/site3
To start the Hugo server for each Hugo project, you can start multiple Hugo servers by specifying different port numbers as follows.
$ hugo server -p 50001 -s ~/website/site1
$ hugo server -p 50002 -s ~/website/site2
$ hugo server -p 50003 -s ~/website/site3
However, as described above, one server process occupies one command prompt, so when starting multiple Hugo servers, you need to keep multiple command prompts open.
Start Multiple Hugo Servers from One Prompt
Windows
With the Windows start command, you can run the Hugo command in the background, so you can start multiple Hugo servers without opening additional command prompts.
For example, the following batch file starts three Hugo servers in the background.
start-servers.bat
@echo off
start /b hugo server -p 50001 -s C:/website/site1
start /b hugo server -p 50002 -s C:/website/site2
start /b hugo server -p 50003 -s C:/website/site3
title Hugo Servers
The final line changes the command prompt window title to “Hugo Servers” with the
title Hugo Serverscommand. Setting the window title is recommended because it makes it easier to identify what the window is for just by looking at the taskbar.
To stop all Hugo servers running in the background together, use the taskkill command to terminate all hugo.exe processes.
stop-servers.bat
@echo off
taskkill /f /im hugo.exe
Linux and macOS
On Linux and macOS, you can easily start multiple servers in the background by adding & at the end when running the Hugo command as follows.
start-servers.sh
hugo server -p 50001 -s ~/website/site1 &
hugo server -p 50002 -s ~/website/site2 &
hugo server -p 50003 -s ~/website/site3 &
To stop the Hugo server processes together, you can easily terminate them with the killall command.
stop-servers.sh
killall hugo
Alternatively, instead of a shell script, you can define functions or aliases and use them quickly.
~/.bash_profile
function hugo-start {
hugo server -p 50001 -s ~/website/site1 &
hugo server -p 50002 -s ~/website/site2 &
hugo server -p 50003 -s ~/website/site3 &
}
function hugo-stop {
killall hugo
}