Skip to content

Instantly share code, notes, and snippets.

@NekoiNemo
Last active July 14, 2024 18:14
Show Gist options
  • Save NekoiNemo/010f83528750f8bd54fc75c089973f0a to your computer and use it in GitHub Desktop.
Save NekoiNemo/010f83528750f8bd54fc75c089973f0a to your computer and use it in GitHub Desktop.
Peacock under Linux, Docker edition (draft)

Peacock server in Docker (lazy version)

This is the lazy version of the Docker guide (WiP), for people who don't understand what they are doing at all, or simply don't want to read and think, and just want to copy-paste few commands and be done with it

Setup

Install Docker

For ArchLinux-based systems you can find installation instructions on the ArchWiki, for everyone else: official docs.

Short version of Arch instruction:

  1. Install

    sudo pacman -S docker
    sudo systemctl enable --now docker.service
  2. Verify it's working

    docker info
  3. You will see permission errors at the end - add yourself to docker group and then log out and log back in for changes to take effect

    sudo usermod -aG docker YOUR_USERNAME

Get Peacock

Pick a location to store the server data, such as ~/peacock_server (commands below assume that to be the case)

Download latest release from Github (pick the -linux archive). Unzip it and copy contents of the directory inside of the archive into the path you picked before.

Assuming you have curl and unzip installed, you can run the following commands to do the above:

  1. Setup

    PEACOCK_VERSION=$(curl -sS https://api.github.com/repos/thepeacockproject/peacock/releases/latest | sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p')
    PEACOCK_DIR="Peacock-$PEACOCK_VERSION-linux"
    
    mkdir -p ~/peacock_server/tmp
  2. Download latest release

    curl -LO --output-dir ~/peacock_server/tmp "https://github.com/thepeacockproject/Peacock/releases/download/$PEACOCK_VERSION/$PEACOCK_DIR.zip"
  3. Extract it and copy the files into the server dir

    unzip -d ~/peacock_server/tmp ~/peacock_server/tmp/$PEACOCK_DIR.zip
    cp -a ~/peacock_server/tmp/$PEACOCK_DIR/* ~/peacock_server
  4. Save current version for later use

    echo $PEACOCK_VERSION > ~/peacock_server/peacock_version
  5. Cleanup

    rm -rf ~/peacock_server/tmp
    unset PEACOCK_VERSION PEACOCK_DIR

Run the container

Execute command below (change 4747 to something else if you want to use a different port on your machine for the server)

docker run -d \
    --name peacock_server \
    --volume ~/peacock_server:/app \
    --workdir /app \
    --publish "4747:3000" \
    --env PORT=3000 \
    --user $(id -u):$(id -g) \
    "node:$(sed 's/^v\([0-9]*\).*/\1/' ~/peacock_server/.nvmrc || echo lts)-alpine" \
    chunk0.js

Above will start the docker container in the background (so command will exit as soon as it is started, without taking over the terminal), as your user (so you have rights to access its data, such as userdata or plugins), mount the directory with the server into the container, "publish" (as in connect) port 4747 of your computer to port we start server on in the container

Warning

If you run the command above multiple times and encounter an error about name being already taken - run docker rm -f peacock_server to get rid of the old container before running the docker run again.

Check that server started without issues by checking its logs - you should see logs ending with something along the lines of

[14:07:12:412] [Info | boot] Booting Peacock internal services - this may take a moment.
[14:07:12:620] [Debug | scanGroups] Discovered 165 escalation groups.
[14:07:12:863] [Info] Server started.
[14:07:17:646] [Debug | updates] Peacock is up to date.

Configuration

As you have direct access to the contents of Peacock directory, the configuration largely follows the official guide.

It's recommended to stop container before making any modifications, and start it back afterwards

Usage

Check status

You can check the status of running containers with

docker ps -a

which will get the output along the lines of

CONTAINER ID   IMAGE            COMMAND                  CREATED       STATUS         PORTS                                       NAMES
7cfe67b265be   node:20-alpine   "docker-entrypoint.s…"   2 hours ago   Up 3 seconds   0.0.0.0:4747->3000/tcp, :::4747->3000/tcp   peacock_server

With NAMES at the end being the name of the container, STATUS being "Up" if container is running and "Exited" if it is stopped, and PORTS (only shows up if container is running) allowing you to recall which port you should write in Patcher

If you see "Restarting" in the status, over an over, that means something went catastrophically wrong and container can't start. Check the logs.

Starting and stopping

When you have executed docker run above, you have created and started the container. To merely start already exisitng container, use

docker start peacock_server

And to stop:

docker stop peacock_server

Restart policy

As it is configured now, Peacock server will need to be started and stopped manually (for example, before starting the game, and after qutting it).

If you want the server to run always in the background (it takes about ~90MB of RAM and nonexistent CPU cycles amount), you can change its "restart policy" to have it start on system boot automatically:

docker update --restart unless-stopped peacock_server

To only restart in case of a failure:

docker update --restart on-failure peacock_server

And the default behaviour, the way it was set up originally, fully manual lifecycle:

docker update --restart no peacock_server

Updating

First, you can check the current and latest Peacock versions with

echo "Peacock version: $(cat ~/peacock_server/peacock_version), latest: $(curl -sS https://api.github.com/repos/thepeacockproject/peacock/releases/latest | sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p')"

If you want to update - stop and get rid of the current container

docker stop peacock_server
docker rm peacock_server

Then re-run the steps from get peacock and run the container.

Tools

To access CLI tools of Peacock server, you can execute (press Ctrl-C to exit):

docker exec -it peacock_server node chunk0.js tools

Logs

To simply print out logs to the terminal run

docker logs peacock_server

To follow (have them be printed out in real time) logs, execute (press Ctrl-C to exit):

docker logs -tf peacock_server

Using Peacock Patcher in Linux

This assumes you already have the Peacock Server set up.

Setup

  1. Copy PeacockPatcher.exe out of the server folder into the game's directory.

  2. Download the peacock_steam.sh script from next to this guide and also put it into game's directory. Don't forget to set it as executable:

    chmod +x peacock_steam.sh
  3. Change Hitman's launch options in Steam to ./peacock_steam.sh HOST:PORT %command%. Where HOST:PORT is the host and port of your Peacock server isntance. You can skip the HOST: part if it's running on the same machine as the game, and jsut specify the PORT. For example:

    ./peacock_steam.sh 4747 %command%
    ./peacock_steam.sh 192.168.0.10:5000 %command%
    

Usage

This wrapper will start your game and automatically patch its process to use the server address you've specified. Once (you don't get a GUI where you can re-patch it on the fly).

After doing that the patcher will exit and no longer linger after you close the game. As a tradeoff for that, the launcher must be skipped, as it is a separate process from the game, and, when patcher is started this way, it isn't going to wait for the game proper to start - if it's not there when the patcher starts - it will just exit without patching the game.

In case you want to access the launcher and/or connect to IOI's server to verify your puchases - you simply need to clean out the launch options and start the game. Then, after you're done, put the ./peacock_steam.sh HOST:PORT %command%back into launch options.

Additional actions

In case you need to do something else before the game starts or after it exits (such as starting and stopping Peacock server, respectively) - you can open peacock_steam.sh script and these commands to the corresponding sections (see examples in the script).

#! /bin/bash
# This is a wrapper for launching Hitman 3 along with PeacockPatcher in Linux through Steam.
#
# This version uses Patcher's CLI interface to pass your server address to it, patch the game once, ang quit
# without letting letting patcher linger after you exit the game. As patcher would expect to patch the game's process
# immediately upon launching, this also skips the Launcher to boot directly into the game.
#
# If you need to connecto to the official servers to verify your purchases, or access the configuration
# in the launcher - just clean out your launch options in Steam, and start the game that way.
if [ "$#" -lt 2 ]; then
cat <<EOF
For use in Steam. Change Hitman's launch options in Steam to "./peacock_steam.sh HOST:PORT %command%"
Where HOST:PORT is the address of your Peacock server (you can omit "HOST:" if it's running locally), e.g.:
./peacock_steam.sh 4747 %command%
./peacock_steam.sh 192.168.0.10:5000 %command%
EOF
exit 1
fi
if [[ $1 != *:* ]]; then
address="127.0.0.1:$1"
else
address="$1"
fi
cat <<EOF >PeacockPatched.bat
@echo off
start Launcher.exe %* -skip_launcher
start PeacockPatcher.exe --headless --domain "$address"
EOF
#======== Before game starts ========
# Any command executed here must exit for game to get launched!
# Examples:
# docker start peacock_server
# systemctl --user start peacock.service
#======== Start Game ========
steam_cmd=("${@/Launcher.exe/PeacockPatched.bat}")
"${steam_cmd[@]:1}"
rm PeacockPatched.bat
#======== After game exits ========
# Any command executed here will keep the game still running in the eyes of Steam, until it exits
# Examples:
# docker stop peacock_server
# systemctl --user stop peacock.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment