forked from lloesche/valheim-server-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
valheim-bootstrap
executable file
·120 lines (91 loc) · 3.57 KB
/
valheim-bootstrap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
# valheim-bootstrap is the first of the valheim-* scripts
# that runs and prepares the system based on
# environment variables.
# Include defaults
. /usr/local/etc/valheim/defaults
. /usr/local/etc/valheim/common
# Update server status before anything else
update_server_status bootstrapping
if [ -n "$PRE_BOOTSTRAP_HOOK" ]; then
info "Running pre bootstrap hook: $PRE_BOOTSTRAP_HOOK"
eval "$PRE_BOOTSTRAP_HOOK"
fi
# check if we are supposed to wipe our data directories
if [ "$DEBUG_START_FRESH" = true ]; then
warn "Wiping all data directories (DEBUG_START_FRESH: $DEBUG_START_FRESH)"
rm -rf "$valheim_download_path"
rm -rf "$valheim_install_path"
rm -rf "$vp_download_path"
rm -rf "$vp_install_path"
fi
# check if we are supposed to reinstall ValheimPlus
if [ "$DEBUG_REINSTALL_VALHEIM_PLUS" = true ]; then
warn "Reinstalling ValheimPlus mod (DEBUG_REINSTALL_VALHEIM_PLUS: $DEBUG_REINSTALL_VALHEIM_PLUS)"
rm -rf "$vp_download_path"
rm -rf "$vp_install_path"
fi
# Output image commit version on startup
if [ -f "$git_commit_file" ]; then
commit=$(< "$git_commit_file")
debug "Running commit $commit"
fi
# Create paths
mkdir -p "$valheim_download_path"
mkdir -p "$valheim_install_path"
if [ "$VALHEIM_PLUS" = true ]; then
mkdir -p "$vp_download_path"
mkdir -p "$vp_install_path"
if [ -d "$vp_config_path" ]; then
write_valheim_plus_config
fi
fi
# Write server's adminlist.txt / bannedlist.txt
write_adminlist
write_bannedlist
# Create crontabs
crontab=$(mktemp)
if [ "$BACKUPS" = true ] && [ -n "$BACKUPS_CRON" ] && [ "$BACKUPS_INTERVAL" = "315360000" ]; then
debug "Creating cron to do world backups using schedule $BACKUPS_CRON"
echo "$BACKUPS_CRON [ -f \"$valheim_backup_pidfile\" ] && kill -HUP \$(cat $valheim_backup_pidfile)" >> "$crontab"
fi
if [ -n "$UPDATE_CRON" ] && [ "$UPDATE_INTERVAL" = "315360000" ]; then
debug "Creating cron to check for updates using schedule $UPDATE_CRON"
echo "$UPDATE_CRON [ -f \"$valheim_updater_pidfile\" ] && kill -HUP \$(cat $valheim_updater_pidfile)" >> "$crontab"
fi
if [ -n "$RESTART_CRON" ]; then
debug "Creating cron to restart valheim-server using schedule $RESTART_CRON"
if [ "$RESTART_IF_IDLE" = true ]; then
echo "$RESTART_CRON $cmd_valheim_is_idle && $cmd_supervisorctl restart valheim-server" >> "$crontab"
else
echo "$RESTART_CRON $cmd_supervisorctl restart valheim-server" >> "$crontab"
fi
else
debug "Environment variable RESTART_CRON is empty - no automatic valheim-server restart scheduled"
fi
crontab "$crontab"
rm -f "$crontab"
# Notify users of new data paths
if [ -d "/opt/valheim_dl" ] || [ -f "/opt/valheim/valheim_server.x86_64" ]; then
cat <<EOF
!!! ATTENTION !!!
You have /opt/valheim_dl mounted or old server files in /opt/valheim.
The /opt/valheim_dl volume is no longer required and has been unified under
/opt/valheim
Directories have been moved in the following way:
/opt/valheim/ -> /opt/valheim/server/
/opt/valheim_dl/ -> /opt/valheim/dl/server/
You might want to (re)move existing files or create a fresh volume mount under /opt/valheim to clean things up.
Nothing is going to break though if you don't. It will just consume some extra disk space.
If required we'll download a fresh copy of the server in the new directory structure.
!!! ATTENTION !!!
EOF
fi
if [ -n "$POST_BOOTSTRAP_HOOK" ]; then
info "Running post bootstrap hook: $POST_BOOTSTRAP_HOOK"
eval "$POST_BOOTSTRAP_HOOK"
fi
# Start all services
supervisorctl start valheim-updater
supervisorctl start valheim-backup
exit 0