Skip to content

Instantly share code, notes, and snippets.

@davidkirwan
Created September 29, 2021 01:09
Show Gist options
  • Save davidkirwan/317f8a74d13d7f37842f51c5e456b86c to your computer and use it in GitHub Desktop.
Save davidkirwan/317f8a74d13d7f37842f51c5e456b86c to your computer and use it in GitHub Desktop.
Factorio Server Container Manager
#!/usr/bin/env bash
# - [1] From here: https://www.tutorialworks.com/podman-rootless-volumes/
# - [2] https://github.com/factoriotools/factorio-docker
# To run this without root, we apparently need to do the following: [1]
# `podman unshare chown 845:845 /home/dkirwan/factorio`
# Then run the container with `--user 845`, to match what the container expects: see [2]
# And add the `:Z` to the volume to mark it as a private share
factorio_start () {
echo "Starting the factorio server"
podman run --user 845 \
-d \
-p 34197:34197/udp \
-p 27015:27015/tcp \
-v /home/dkirwan/factorio:/factorio:Z \
--name factorio \
--restart=always \
factoriotools/factorio
if [ $? -eq 0 ]
then
echo "done."
else
echo "Looks like the container already exists, trying to start it"
podman start factorio
if [ $? -eq 0 ]
then
echo "done."
else
echo "Error: " >&2
fi
fi
}
factorio_stop () {
echo "Stopping the factorio server"
podman stop factorio
}
factorio_update () {
echo "Running factorio update"
factorio_stop
podman rm factorio
podman pull factoriotools/factorio
}
if [ "$1" == "start" ]; then factorio_start; fi
if [ "$1" == "stop" ]; then factorio_stop; fi
if [ "$1" == "update" ]; then factorio_update; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment