Skip to content

Commit 8ba8a8c

Browse files
author
Tobias Wallin
committed
Merge branch 'develop'
2 parents bd7c3c1 + c22036c commit 8ba8a8c

File tree

3 files changed

+50
-49
lines changed

3 files changed

+50
-49
lines changed

README.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ A simple factorio init script for linux
55
If you find yourself wondering why stuff is not working the way you expect:
66
- Check the logs, I suggest you `tail -f /opt/factorio/factorio-current.log` in a separate session
77
- Enable debugging in the config and/or:
8-
- Try running the same commands as the factorio user
8+
- Try running the same commands as the factorio user (`/opt/factorio-init/factorio invocation` will tell you what the factorio user tries to run at start)
99

1010
```bash
11-
$ cd '/opt/factorio-init'
12-
$ source ./config # Grab the config variables
13-
$ echo $INVOCATION # Does this look correct to you?
14-
$ $INVOCATION #Start the server, watch the log output for any Errors
11+
$ /opt/factorio-init invocation
12+
# Run this as the factorio user, example:
13+
$ sudo -u factorio 'whatever invocation gave you'
14+
# You should see some output in your terminal here, hopefully giving
15+
# you a hint of what is going wrong
1516
```
1617

1718
# Install
@@ -46,16 +47,11 @@ A simple factorio init script for linux
4647

4748
```bash
4849
$ ln -s /opt/factorio-init/factorio /etc/init.d/factorio
49-
```
50-
- Make the script executable:
51-
52-
```bash
50+
# Make the script executable:
5351
$ chmod +x /opt/factorio-init/factorio
54-
```
55-
- Try it out!
56-
57-
```bash
52+
# Try it out:
5853
$ service factorio help
54+
# Do not forget to enable the service at boot if you want that.
5955
```
6056

6157
# Thank You

config.example

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ USERNAME=factorio
1313
USERGROUP=factorio
1414

1515
# The absolute path to the factorio directory
16-
FACTORIO_PATH=/path/to/factorio
17-
# The absolute path to the factorio binary
18-
BINARY=${FACTORIO_PATH}/bin/x64/factorio
19-
# Absolute path to factorios config.ini
20-
FCONF=${FACTORIO_PATH}/config/config.ini
16+
FACTORIO_PATH=/opt/factorio
2117
# Server settings file, see data/server-settings.example.json
2218
SERVER_SETTINGS=${FACTORIO_PATH}/data/server-settings.json
19+
2320
# Port on which you want to run the server
2421
PORT=34197
2522

@@ -64,10 +61,3 @@ UPDATE_TMPDIR=/tmp
6461
# Extras
6562
# Additional binary arguments, these will be sent to the binary when issuing the "start" command
6663
EXTRA_BINARGS="--allow-commands admin-only"
67-
68-
#
69-
# Refrain from changing the variables below, they are used internally by the script and should
70-
# not be altered unless you know what you are doing
71-
#
72-
SAVE_NAME=factorio-init-save
73-
INVOCATION="${BINARY} --config ${FCONF} --port ${PORT} --start-server-load-latest --server-settings ${SERVER_SETTINGS} --autosave-interval ${AUTOSAVE_INTERVAL} --autosave-slots ${AUTOSAVE_SLOTS} --latency-ms ${LATENCY} ${EXTRA_BINARGS}"

factorio

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,20 @@ if [ -z "${HEADLESS}" ]; then
4141
fi
4242

4343
if ! [ $1 == "install" ]; then
44-
if [ -z ${FCONF} ]; then
45-
echo "Missing FCONF, ensure it's defined in your config and try again"
44+
if [ -z ${BINARY} ]; then
45+
# Factorio headless only comes in x64 flavour - if you run anything else, override it in the config
46+
BINARY="${FACTORIO_PATH}/bin/x64/factorio"
47+
fi
48+
49+
if ! [ -e ${BINARY} ]; then
50+
echo "Could not find factorio binary! ${BINARY}"
51+
echo "(if you store your binary some place else, override BINARY='/your/path' in the config)"
4652
exit 1
4753
fi
54+
55+
if [ -z ${FCONF} ]; then
56+
FCONF="${FACTORIO_PATH}/config/config.ini"
57+
fi
4858

4959
if ! [ -e "${SERVER_SETTINGS}" ]; then
5060
echo "Could not find factorio server settings file: ${SERVER_SETTINGS}"
@@ -54,16 +64,21 @@ if ! [ $1 == "install" ]; then
5464

5565
if ! [ -e ${FCONF} ]; then
5666
echo "Could not find factorio config file: ${FCONF}"
57-
echo "If this is the first time you run this script; You might need to generate the config.ini"
58-
echo "(also make sure the save exist or the command will fail)"
59-
echo "by running: sudo -u $USERNAME ${BINARY} --start-server ${SAVE_NAME}"
67+
echo "If this is the first time you run this script you need to generate the config.ini by starting the server manually."
68+
echo "(also make sure you have a save to run or the server will not start)"
69+
echo
70+
echo "Create save: sudo -u ${USERNAME} ${BINARY} --create ${FACTORIO_PATH}/saves/my_savegame"
71+
echo "Start server: sudo -u ${USERNAME} ${BINARY} --start-server-load-latest"
72+
echo
73+
echo "(If you rather store the config.ini in another location, set FCONF='/your/path' in this scripts config file)"
6074
exit 1
6175
fi
6276
if [ -z "${WRITE_DIR}" ]; then
6377
# figure out the write-data path (where factorio looks for saves and mods)
6478
# Note - this is a hefty little operation, possible cause of head ache down the road
6579
# as it relies on the factorio write dir to live ../../ up from the binary if __PATH__executable__
6680
# is used in the config file.. for now, that's the default so cross your fingers it will not change ;)
81+
debug "Determining WRITE_DIR based on ${FCONF}, IF you edited write-data from the default, this probably fails"
6782
WRITE_DIR=$(dirname "$(echo `grep "^write-data=" "$FCONF"` |cut -d'=' -f2 |sed -e 's#__PATH__executable__#'$(dirname "$BINARY")/..'#g')")
6883
fi
6984
debug "write path: $WRITE_DIR"
@@ -74,6 +89,9 @@ if ! [ $1 == "install" ]; then
7489
FIFO="${WRITE_DIR}/server.fifo"
7590
fi
7691

92+
# Finally, set up the invocation
93+
INVOCATION="${BINARY} --config ${FCONF} --port ${PORT} --start-server-load-latest --server-settings ${SERVER_SETTINGS} --autosave-interval ${AUTOSAVE_INTERVAL} --autosave-slots ${AUTOSAVE_SLOTS} --latency-ms ${LATENCY} ${RCON} ${EXTRA_BINARGS}"
94+
7795
fi
7896

7997
usage(){
@@ -85,11 +103,12 @@ usage(){
85103
echo -e " restart \t\t Restarts the server"
86104
echo -e " status \t\t Displays server status"
87105
echo -e " cmd command/message \t Send command/chat"
88-
echo -e " new-game \t\t Stops the server and creates a new game"
106+
echo -e " new-game name\t\t Stops the server and creates a new game with the specified name"
89107
echo -e " save-game name \t Stops the server and saves game to specified save"
90108
echo -e " load-save name \t Stops the server and loads the specified save"
91109
echo -e " install tarball \t Installs the server with specified tarball"
92110
echo -e " update [--dry-run] \t Updates the server"
111+
echo -e " invocation \t\t Outputs the invocation for debugging purpose"
93112
}
94113

95114
ME=`whoami`
@@ -264,21 +283,7 @@ install(){
264283
exit 1
265284
fi
266285

267-
if test_deps; then
268-
if ! as_user "$BINARY --create ${SAVE_NAME}"; then
269-
echo "Installation complete..."
270-
echo
271-
echo "but failed to create initial save game."
272-
echo "Ensure you use: load-save [save-name] before starting the server for the first time."
273-
else
274-
echo "Install successfull!"
275-
fi
276-
else
277-
echo "Installation complete..."
278-
echo
279-
echo "but $BINARY is missing required dependencies."
280-
echo "Install the missing deps and ensure you use: load-save [save-name] before starting the server for the first time."
281-
fi
286+
echo "Installation complete, edit the config and start your server"
282287
}
283288

284289
get_bin_version(){
@@ -459,6 +464,12 @@ case "$1" in
459464
send_cmd "${@:2}"
460465
;;
461466
new-game)
467+
if [ -z $2 ]; then
468+
echo "You must specify a save name for your new game"
469+
exit 1
470+
fi
471+
savename="${WRITE_DIR}/saves/$2"
472+
462473
# Stop Service
463474
if is_running; then
464475
send_cmd "Generating new save, please stand by"
@@ -468,11 +479,11 @@ case "$1" in
468479
fi
469480
fi
470481

471-
if ! as_user "$BINARY --create ${WRITE_DIR}/saves/${SAVE_NAME}"; then
482+
if ! as_user "$BINARY --create ${savename}"; then
472483
echo "Failed to create new game"
473484
exit 1
474485
else
475-
echo "New game created"
486+
echo "New game created: ${savename}.zip"
476487
fi
477488
;;
478489

@@ -488,7 +499,8 @@ case "$1" in
488499
fi
489500
fi
490501

491-
if ! as_user "cp ${WRITE_DIR}/saves/${SAVE_NAME}.zip ${savename}"; then
502+
lastsave=$(find "${WRITE_DIR}/saves" -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" ")
503+
if ! as_user "cp ${lastsave} ${savename}"; then
492504
echo "Error! Failed to save game"
493505
exit 1
494506
fi
@@ -520,6 +532,9 @@ case "$1" in
520532
update)
521533
update "$2"
522534
;;
535+
inv|invocation)
536+
echo ${INVOCATION}
537+
;;
523538
help|--help|-h)
524539
usage
525540
;;

0 commit comments

Comments
 (0)