├── .github
└── workflows
│ ├── shellcheck.yml
│ └── startup.yml
├── backup.sh
├── license
├── readme.md
├── reset.sh
├── restart.sh
├── restore.sh
├── server.functions
├── server.properties
├── server.settings
├── setup.sh
├── start.sh
├── stop.sh
├── update.sh
├── vent.sh
└── worker.sh
/.github/workflows/shellcheck.yml:
--------------------------------------------------------------------------------
1 | name: shellcheck
2 |
3 | on:
4 | push:
5 | branches: [main, develop]
6 | pull_request:
7 | branches: [main, develop]
8 |
9 | workflow_dispatch:
10 |
11 | jobs:
12 | run-shellcheck:
13 | runs-on: ubuntu-latest
14 | steps:
15 | - uses: actions/checkout@v2
16 | - name: Run ShellCheck
17 | uses: ludeeus/action-shellcheck@master
18 | with:
19 | severity: error
20 |
--------------------------------------------------------------------------------
/.github/workflows/startup.yml:
--------------------------------------------------------------------------------
1 | name: startup
2 |
3 | on:
4 | push:
5 | branches: [main, develop]
6 | pull_request:
7 | branches: [main, develop]
8 |
9 | workflow_dispatch:
10 |
11 | jobs:
12 | build:
13 | runs-on: ubuntu-latest
14 |
15 | steps:
16 | - uses: actions/checkout@v3
17 | - uses: actions/setup-java@v3
18 | with:
19 | distribution: 'zulu'
20 | java-version: '21'
21 |
22 | - name: setup colors
23 | run: TERM="xterm"
24 |
25 | - name: setup server
26 | run: chmod +x setup.sh && ./setup.sh --name minecraft --proceed true --version 1.21.5 --port 25565 --eula true --remove true --start false
27 |
28 | - name: startup server
29 | run: cd minecraft && chmod +x start.sh && ./start.sh --verbose
30 |
--------------------------------------------------------------------------------
/backup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # minecraft server backup script
3 |
4 | # for the sake of integrity of your backups,
5 | # I would strongly recommend not to mess with this file.
6 | # if you really know what you are doing feel free to go ahead ;^)
7 |
8 | # read server files
9 | source server.settings
10 | source server.functions
11 |
12 | # parse backup category
13 | ParseCategory "$@"
14 |
15 | # shift args
16 | shift
17 |
18 | # parse arguments
19 | ParseArgs "$@"
20 | ArgHelp
21 |
22 | # safety checks
23 | RootSafety
24 | ScriptSafety
25 |
26 | # debug
27 | Debug "executing $0 script"
28 |
29 | # change to server directory
30 | ChangeServerDirectory
31 |
32 | # check if server is running
33 | CheckScreen
34 |
35 | # test all categories
36 | BackupDirectoryIntegrity
37 |
38 | # main backup function
39 | function RunBackup {
40 | Debug "executing backup-${1} script"
41 | # check if disk space is too low
42 | if (((${worldSizeBytes} + ${diskSpaceError}) > ${diskSpaceBytes})); then
43 | OutputDiskSpaceError "${1}" "${2}" "${3}"
44 | exit 1
45 | fi
46 | # check is getting low
47 | if (((${worldSizeBytes} + ${diskSpaceWarning}) > ${diskSpaceBytes})); then
48 | OutputDiskSpaceWarning "${1}"
49 | fi
50 | # check if backup already exists
51 | if ! [[ -s "${backupDirectory}/${1}/${serverName}-${2}.tar.gz" ]]; then
52 | # save the world
53 | Screen "save-all"
54 | AwaitString "Saved the game" "10"
55 | # disable auto save
56 | Screen "save-off"
57 | AwaitString "Automatic saving is now disabled" "5"
58 | # start timer
59 | before=$(date +%s%3N)
60 | # copy world
61 | nice -n 19 cp -r "world" "tmp-${1}"
62 | if [ $? != 0 ]; then
63 | OutputBackupCopyError "${1}" "${2}" "${3}"
64 | rm -r "tmp-${1}"
65 | exit 1
66 | fi
67 | # enable auto save
68 | Screen "save-on"
69 | AwaitString "Automatic saving is now enabled" "5"
70 | # compress world
71 | nice -n 19 tar -czf "world-${1}.tar.gz" "tmp-${1}"
72 | if [ $? != 0 ]; then
73 | OutputBackupTarError "${1}" "${2}" "${3}"
74 | rm -r "world-${1}.tar.gz" "tmp-${1}"
75 | exit 1
76 | fi
77 | # mv backup and remove tmp
78 | nice -n 19 mv "${serverDirectory}/world-${1}.tar.gz" "${backupDirectory}/${1}/${serverName}-${2}.tar.gz"
79 | nice -n 19 rm -r "tmp-${1}"
80 | # stop timer
81 | after=$(date +%s%3N)
82 | else
83 | OutputBackupAlreadyExists "${1}" "${2}" "${3}"
84 | exit 1
85 | fi
86 | if [[ -s "${backupDirectory}/${1}/${serverName}-${2}.tar.gz" ]]; then
87 | # remove old backup if it exists
88 | if [[ -s "${backupDirectory}/${1}/${serverName}-${3}.tar.gz" ]]; then
89 | nice -n 19 rm "${backupDirectory}/${1}/${serverName}-${3}.tar.gz"
90 | fi
91 | # calculate time spent and compression
92 | timeSpent=$((${after} - ${before}))
93 | compressedBackupSize=$(du -sh ${backupDirectory}/${1}/${serverName}-${2}.tar.gz | cut -f1)
94 | compressedBackupSizeBytes=$(du -sb ${backupDirectory}/${1}/${serverName}-${2}.tar.gz | cut -f1)
95 | # check if backup size is to small for a real backup
96 | if ((${compressedBackupSizeBytes} < (${worldSizeBytes} / 100 * ${backupSizeError}))); then
97 | OutputBackupSizeError "${1}" "${2}" "${3}"
98 | exit 1
99 | fi
100 | # check if backup size is suspiciously small
101 | if ((${compressedBackupSizeBytes} < (${worldSizeBytes} / 100 * ${backupSizeWarning}))); then
102 | OutputBackupSizeWarning "${1}" "${2}" "${3}"
103 | fi
104 | # read settings and output success
105 | source server.settings
106 | OutputBackupSuccess "${1}" "${2}" "${3}"
107 | else
108 | OutputBackupGenericError "${1}" "${2}" "${3}"
109 | fi
110 | Debug "executed backup-${1} script"
111 | }
112 |
113 | # hourly backup
114 | if [ ${isHourly} == true ]; then
115 | if [ ${doHourly} == true ]; then
116 | # run backup
117 | RunBackup "hourly" "${newHourly}" "${oldHourly}"
118 | else
119 | Log "info" "backup-hourly is disabled" "${backupLog}"
120 | Print "info" "backup-hourly is disabled"
121 | fi
122 | fi
123 |
124 | # daily backup
125 | if [ ${isDaily} == true ]; then
126 | if [ ${doDaily} == true ]; then
127 | # run backup
128 | RunBackup "daily" "${newDaily}" "${oldDaily}"
129 | else
130 | Log "info" "backup-daily is disabled" "${backupLog}"
131 | Print "info" "backup-daily is disabled"
132 | fi
133 | fi
134 |
135 | # weekly backup
136 | if [ ${isWeekly} == true ]; then
137 | if [ ${doWeekly} == true ]; then
138 | # run backup
139 | RunBackup "weekly" "${newWeekly}" "${oldWeekly}"
140 | else
141 | Log "info" "backup-weekly is disabled" "${backupLog}"
142 | Print "info" "backup-weekly is disabled"
143 | fi
144 | fi
145 |
146 | # monthly backup
147 | if [ ${isMonthly} == true ]; then
148 | if [ ${doMonthly} == true ]; then
149 | # run backup
150 | RunBackup "monthly" "${newMonthly}" "${oldMonthly}"
151 | else
152 | Log "info" "backup-monthly is disabled" "${backupLog}"
153 | Print "info" "backup-monthly is disabled"
154 | fi
155 | fi
156 |
157 | # debug
158 | Debug "executed $0 script"
159 |
160 | # exit with code 0
161 | exit 0
162 |
--------------------------------------------------------------------------------
/license:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # minecraft-server
2 |
3 | Scripts for a Minecraft Server on Linux Debian using screen.
4 |
5 | This tutorial contains important steps if you would like to host a minecraft server from the command line.
6 |
7 | ## software
8 |
9 | In order for the Server to run we will need to install some packages: (please note: some of them could be installed already)
10 | This command installs all packages you will need to run your server.
11 |
12 | ```
13 | sudo apt install openjdk-17-jre-headless iputils-ping net-tools mailutils coreutils dnsutils sendmail screen grep nano wget less cron man sed pv
14 | ```
15 |
16 | ## setup
17 |
18 | Then, you can download and execute the setup script.
19 |
20 | Download and make Executable
21 |
22 | ```
23 | wget -O setup.sh https://raw.githubusercontent.com/simylein/minecraft-server/main/setup.sh && chmod +x setup.sh
24 | ```
25 |
26 | This will start the script in interactive mode and you must answer questions
27 |
28 | ```
29 | ./setup.sh
30 | ```
31 |
32 | If you like a straight one-liner which is non-interactive you may use the setup arguments like this
33 |
34 | ```
35 | ./setup.sh --name minecraft --proceed true --version 1.21.5 --port 25565 --eula true --remove true --start true
36 | ```
37 |
38 | ## serverstart
39 |
40 | Start your Server for the first time: `./start.sh`
41 |
42 | ## screen
43 |
44 | Screen is an amazing command line tool that creates a "virtual" terminal inside your terminal.
45 |
46 | You can view all your active screens by typing: `screen -list`
47 |
48 | If you want to resume a certain screen session just type: `screen -r ${servername}`
49 |
50 | If you would like to scroll inside a screen session press Ctrl+A and Esc (enter copy mode).
51 | For returning back to normal press Esc.
52 |
53 | To exit the screen terminal press Ctrl+A and Ctrl+D
54 |
55 | ## server commands
56 |
57 | Your minecraft server can understand certain commands.
58 | I will explain some of them to you.
59 |
60 | `whitelist add ${playername}` adding someone to your whitelist so he/she can join your server.
61 | `whitelist remove ${playername}` remove someone to your whitelist so he/she can no longer join your server.
62 | `op ${playername}` make someone admin on your server so he/she can execute commands.
63 | `deop ${playername}` remove admin permissions for a player so he/she can no longer execute commands.
64 | `ban ${playername}` ban someone from your server so he/she can no longer join your server.
65 | `pardon ${playername}` pardon someone from your server so he/she can join your server.
66 | `tp ${playername} ${x} ${y} ${z}` teleporting a player to cords.
67 | `tp ${playername} ${playername}` teleporting a player to another player.
68 |
69 | Important: If you do these commands ingame you will need to put a `/` before each command.
70 | In the screen terminal you don't need a `/` before your command.
71 |
72 | ## server.settings
73 |
74 | This is your file that holds the variables you have chosen with the setup script.
75 | If you know what your are doing feel free to edit it to suit your needs.
76 |
77 | ```
78 | nano server.settings
79 | ```
80 |
81 | Important settings are:
82 |
83 | `public=` (ip of a wan server which will be pinged to ensure network availability)
84 | `private=` (ip of a lan server which will be pinged to ensure network availability)
85 |
86 | `doHourly=` (enables hourly backups)
87 | `doDaily=` (enables daily backups)
88 | `doWeekly=` (enables weekly backups)
89 | `doMonthly=` (enables monthly backups)
90 |
91 | `diskSpaceError=` (value in bytes for free disk space at which the backup script stops working)
92 | `diskSpaceWarning=` (value in bytes for free disk space at which the backup script throws warnings)
93 |
94 | ## server.properties
95 |
96 | If you would like to customize your server further have a look at your server.properties file.
97 |
98 | ```
99 | nano server.properties
100 | ```
101 |
102 | Important settings are:
103 |
104 | `max-players=` (limits the maximum amount of players on the server at the same time)
105 | [Warning large numbers may impact performance]
106 |
107 | `difficulty=` (defines ingame difficulty) [peaceful, easy, normal, hard]
108 | `gamemode=` (default survival. Defines your game mode. For creative server replace with creative)
109 | [survival/creative/adventure/spectator]
110 |
111 | `view-distance=` (defines number of ingame chunks to be rendered)
112 | [Warning large numbers may impact performance]
113 | `simulation-distance=` (defines number of ingame chunks in which entities are computed)
114 | [Warning large numbers may impact performance]
115 |
116 | `motd=` (this will be displayed in the menu below your server - chose what you like)
117 | `pvp=` (ability for player to do damage to each another) [true/false]
118 |
119 | `server-port=` (default by 25565. Only important if you are dealing with multiple server)
120 | [if you run multiple servers each server wants to have its own port]
121 |
122 | `white-list=` (turns on the whitelist) [I would strongly recommend to set this to true]
123 | `spawn-protection=` (the number of block at the worldspawn only operators can touch)
124 |
125 | `enable-command-block=` (enables command blocks to tinker with) [true/false]
126 |
127 | ## scripts
128 |
129 | There are lots of script in your ${serverdirectory}. Normally, the executable ones are green and can be executed with:
130 |
131 | ```
132 | ./${scriptname}.sh ${arguments}
133 | ```
134 |
135 | Example: `./start.sh --quiet`
136 | Example: `./stop.sh --now`
137 |
138 | Arguments: `-h --help, -f --force, -n --now -q --quiet -v --verbose`
139 |
140 | The script name stands for the action the script will do.
141 |
142 | start.sh (starts your server)
143 | stop.sh (stops your server)
144 | restart.sh (restarts your server)
145 | update.sh (updates your server version)
146 | restore.sh (restores the backup of your choice)
147 | reset.sh (resets server world)
148 | vent.sh (self-destructs your server along its backups)
149 |
150 | ## crontab
151 |
152 | If you would like to automate some of those task on your server you can create a crontab.
153 |
154 | ```
155 | crontab -e
156 | ```
157 |
158 | A new file will open (If you got one already the existing one will open)
159 | Side note: the setup script will already put these lines in your crontab if you chose to do so.
160 | In this file, you can automate things as follows:
161 |
162 | First star: Minutes [0 - 59]
163 | Second star: Hours [0 - 23]
164 | Third star: Day of Month [0 - 31]
165 | Forth star: Month [0 - 12]
166 | Fifth star: Day of Week [0 - 6]
167 |
168 | Generic Example: (In order to work, please replace the variables with your own ones)
169 |
170 | ```
171 | # minecraft ${servername} your description of command here
172 | * * * * * cd ${serverdirectory} && ./${script}.sh
173 | ```
174 |
175 | Close and save your crontab. (Press Ctrl X and Y)
176 |
177 | ## logfiles
178 |
179 | Your server will write two growing logfiles [screen.log and backup.log] (located in your ${serverdirectory})
180 | screen.log contains everything that get's written inside your screen terminal while backup.log logs all action of the backup script.
181 |
182 | to view them:
183 |
184 | ```
185 | less screen.log
186 | less backup.log
187 | ```
188 |
189 | ## ending
190 |
191 | I hope you learned something and that those scripts I provide may help you and your minecraft server experience.
192 | Have fun and enjoy the Game ;^)
193 |
194 | Best regards,
195 | Simylein
196 |
--------------------------------------------------------------------------------
/reset.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # minecraft server reset script
3 |
4 | # read server files
5 | source server.settings
6 | source server.functions
7 |
8 | # parse arguments
9 | ParseArgs "$@"
10 | ArgHelp
11 |
12 | # safety checks
13 | RootSafety
14 | ScriptSafety
15 |
16 | # debug
17 | Debug "executing $0 script"
18 |
19 | # change to server directory
20 | ChangeServerDirectory
21 |
22 | # check for existance of executable
23 | CheckExecutable
24 |
25 | # look if server is running
26 | CheckScreen
27 |
28 | # prints countdown to screen
29 | Countdown "resetting"
30 |
31 | # server stop
32 | Stop
33 |
34 | # awaits server stop
35 | AwaitStop
36 |
37 | # force quit server if not stopped
38 | ForceQuit
39 |
40 | # output confirmed stop
41 | Log "ok" "server successfully stopped" "${screenLog}"
42 | Print "ok" "server successfully stopped"
43 |
44 | # create backup
45 | CachedBackup "reset"
46 |
47 | # remove log and world
48 | Print "info" "removing world directory..."
49 | nice -n 19 rm -r world
50 | mkdir world
51 |
52 | # restart the server
53 | echo "action" "restarting server..."
54 | ./start.sh --force "$@"
55 |
56 | # log to debug if true
57 | Debug "executed $0 script"
58 |
59 | # exit with code 0
60 | exit 0
61 |
--------------------------------------------------------------------------------
/restart.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # minecraft server restart script
3 |
4 | # read server files
5 | source server.settings
6 | source server.functions
7 |
8 | # parse arguments
9 | ParseArgs "$@"
10 | ArgHelp
11 |
12 | # safety checks
13 | RootSafety
14 | ScriptSafety
15 |
16 | # debug
17 | Debug "executing $0 script"
18 |
19 | # change to server directory
20 | ChangeServerDirectory
21 |
22 | # check for existance of executable
23 | CheckExecutable
24 |
25 | # look if server is running
26 | CheckScreen
27 |
28 | # prints countdown to screen
29 | Countdown "restarting"
30 |
31 | # server stop
32 | Stop
33 |
34 | # awaits server stop
35 | AwaitStop
36 |
37 | # force quit server if not stopped
38 | ForceQuit
39 |
40 | # output confirmed stop
41 | Log "ok" "server successfully stopped" "${screenLog}"
42 | Print "ok" "server successfully stopped"
43 |
44 | # restart the server
45 | Print "action" "restarting server..."
46 | ./start.sh --force "$@"
47 |
48 | # log to debug if true
49 | Debug "executed $0 script"
50 |
51 | # exit with code 0
52 | exit 0
53 |
--------------------------------------------------------------------------------
/restore.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # minecraft server restore script
3 |
4 | # read server files
5 | source server.settings
6 | source server.functions
7 |
8 | # parse arguments
9 | ParseArgs "$@"
10 | ArgHelp
11 |
12 | # safety checks
13 | RootSafety
14 | ScriptSafety
15 |
16 | # debug
17 | Debug "executing $0 script"
18 |
19 | # change to server directory
20 | ChangeServerDirectory
21 |
22 | # check for existance of executable
23 | CheckExecutable
24 |
25 | # look if server is running
26 | CheckScreen
27 |
28 | # prints countdown to screen
29 | Countdown "restoring a backup"
30 |
31 | # server stop
32 | Stop
33 |
34 | # awaits server stop
35 | AwaitStop
36 |
37 | # force quit server if not stopped
38 | ForceQuit
39 |
40 | # output confirmed stop
41 | Log "ok" "server successfully stopped" "${screenLog}"
42 | Print "ok" "server successfully stopped"
43 |
44 | # create backup
45 | CachedBackup "restore"
46 |
47 | # create arrays with backupdirectorys
48 | Print "info" "scanning backup directory..."
49 | cd ${backupDirectory}
50 | backups=($(ls))
51 | cd hourly
52 | backupsHourly=($(ls))
53 | cd ${backupDirectory}
54 | cd daily
55 | backupsDaily=($(ls))
56 | cd ${backupDirectory}
57 | cd weekly
58 | backupsWeekly=($(ls))
59 | cd ${backupDirectory}
60 | cd monthly
61 | backupsMonthly=($(ls))
62 | cd ${backupDirectory}
63 | cd cached
64 | backupsCached=($(ls))
65 | cd ${backupDirectory}
66 |
67 | # ask for daily or hourly backup to restore
68 | PS3="$(date +"%H:%M:%S") prompt: would you like to restore a ${backups[0]}, ${backups[1]}, ${backups[2]}, ${backups[3]}, ${backups[4]} backup? "
69 | select cachedDailyHourlyWeeklyMonthly in "${backups[@]}"; do
70 | Print "info" "you chose: ${cachedDailyHourlyWeeklyMonthly}"
71 | break
72 | done
73 |
74 | # select specific backup out of daily, hourly, monthly, weekly or a special backup
75 | if [[ "${cachedDailyHourlyWeeklyMonthly}" == "${backups[0]}" ]]; then
76 | # ask for cached backup
77 | PS3="$(date +"%H:%M:%S") prompt: which ${backups[4]} backup would you like to restore?"
78 | select backup in "${backupsCached[@]}"; do
79 | Print "info" "you chose: ${backup}"
80 | break
81 | done
82 | elif [[ "${cachedDailyHourlyWeeklyMonthly}" == "${backups[1]}" ]]; then
83 | # ask for daily backup
84 | PS3="$(date +"%H:%M:%S") prompt: which ${backups[0]} backup would you like to restore? "
85 | select backup in "${backupsDaily[@]}"; do
86 | Print "info" "you chose: ${backup}"
87 | break
88 | done
89 | elif [[ "${cachedDailyHourlyWeeklyMonthly}" == "${backups[2]}" ]]; then
90 | # ask for hourly backup
91 | PS3="$(date +"%H:%M:%S") prompt: which ${backups[1]} backup would you like to restore? "
92 | select backup in "${backupsHourly[@]}"; do
93 | Print "info" "you chose: ${backup}"
94 | break
95 | done
96 | elif [[ "${cachedDailyHourlyWeeklyMonthly}" == "${backups[3]}" ]]; then
97 | # ask for monthly backup
98 | PS3="$(date +"%H:%M:%S") prompt: which ${backups[2]} backup would you like to restore? "
99 | select backup in "${backupsMonthly[@]}"; do
100 | Print "info" "you chose: ${backup}"
101 | break
102 | done
103 | elif [[ "${cachedDailyHourlyWeeklyMonthly}" == "${backups[4]}" ]]; then
104 | # ask for weekly backup
105 | PS3="$(date +"%H:%M:%S") prompt: which ${backups[3]} backup would you like to restore? "
106 | select backup in "${backupsWeekly[@]}"; do
107 | Print "info" "you chose: ${backup}"
108 | break
109 | done
110 | fi
111 |
112 | # ask for permission to proceed
113 | Print "info" "i will now delete the current world-directory and replace it with your chosen backup"
114 | Print "info" "you have chosen: ${backupDirectory}/${cachedDailyHourlyWeeklyMonthly}/${backup} as a backup to restore"
115 | read -p "$(date +"%H:%M:%S") prompt: continue? (y/n): "
116 |
117 | # if user replys yes perform restore
118 | regex="^(Y|y|N|n)$"
119 | while [[ ! ${REPLY} =~ ${regex} ]]; do
120 | read -p "$(date +"%H:%M:%S") prompt: please press y or n: " REPLY
121 | done
122 | if [[ ${REPLY} =~ ^[Yy]$ ]]; then
123 | cd "${serverDirectory}"
124 | Print "action" "restoring backup..."
125 | nice -n 19 mv "${serverDirectory}/world" "${serverDirectory}/old-world"
126 | nice -n 19 cp "${backupDirectory}/${cachedDailyHourlyWeeklyMonthly}/${backup}" "${serverDirectory}"
127 | nice -n 19 mv "${backup}" "world.tar.gz"
128 | nice -n 19 tar -xf "world.tar.gz"
129 | nice -n 19 mv "tmp" "world"
130 | nice -n 19 rm "world.tar.gz"
131 | if [ -d "world" ]; then
132 | Log "the backup ${backupDirectory}/${cachedDailyHourlyWeeklyMonthly}/${backup} has been restored" "${screenLog}"
133 | Print "ok" "restore successful"
134 | Print "action" "restarting server with restored backup..."
135 | nice -n 19 rm -r "${serverDirectory}/old-world"
136 | else
137 | Log "error" "something went wrong - could not restore backup" "${screenLog}"
138 | Log "action" "reverting changes..." "${screenLog}"
139 | Print "error" "something went wrong - could not restore backup"
140 | Print "action" "reverting changes..."
141 | nice -n 19 mv "${serverDirectory}/old-world" "${serverDirectory}/world"
142 | fi
143 | ./start.sh "$@"
144 | # if user replys no cancel and restart server
145 | else
146 | cd ${serverDirectory}
147 | Print "warn" "backup restore has been canceled"
148 | Print "info" "resuming to current live world"
149 | Print "action" "restarting server..."
150 | Log "info" "backup restore has been canceled" "${screenLog}"
151 | Log "info" "resuming to current live world" "${screenLog}"
152 | ./start.sh --force "$@"
153 | fi
154 |
155 | # log to debug if true
156 | Debug "executed $0 script"
157 |
158 | # exit with code 0
159 | exit 0
160 |
--------------------------------------------------------------------------------
/server.functions:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # minecraft server functions
3 |
4 | # this file stores all the functions for the server.
5 | # please note that those function are global and impact every script.
6 |
7 | # please notice that editing these functions can be devastating
8 | # if you know what you are doing, feel free to tinker with them ;^)
9 |
10 | # prints all input to log at given log level
11 | function Log {
12 | if [[ $1 == "ok" ]]; then
13 | echo "$(date +"%Y-%m-%d %H:%M:%S") ok: ${2}" >>"${3}"
14 | fi
15 | if [[ $1 == "info" ]]; then
16 | echo "$(date +"%Y-%m-%d %H:%M:%S") info: ${2}" >>"${3}"
17 | fi
18 | if [[ $1 == "warn" ]]; then
19 | echo "$(date +"%Y-%m-%d %H:%M:%S") warn: ${2}" >>"${3}"
20 | fi
21 | if [[ $1 == "error" ]]; then
22 | echo "$(date +"%Y-%m-%d %H:%M:%S") error: ${2}" >>"${3}"
23 | fi
24 | if [[ $1 == "fatal" ]]; then
25 | echo "$(date +"%Y-%m-%d %H:%M:%S") fatal: ${2}" >>"${3}"
26 | fi
27 | if [[ $1 == "action" ]]; then
28 | echo "$(date +"%Y-%m-%d %H:%M:%S") action: ${2}" >>"${3}"
29 | fi
30 | }
31 |
32 | # prints all input to terminal at given log level
33 | function Print {
34 | if [[ ${1} == "ok" ]] && [[ ${quiet} == false ]]; then
35 | echo "$(date +"%H:%M:%S") ${green}ok${noColor}: ${2}"
36 | fi
37 | if [[ ${1} == "info" ]] && [[ ${quiet} == false ]]; then
38 | echo "$(date +"%H:%M:%S") ${cyan}info${noColor}: ${2}"
39 | fi
40 | if [[ ${1} == "warn" ]]; then
41 | echo "$(date +"%H:%M:%S") ${yellow}warn${noColor}: ${2}"
42 | fi
43 | if [[ ${1} == "error" ]]; then
44 | echo "$(date +"%H:%M:%S") ${red}error${noColor}: ${2}"
45 | fi
46 | if [[ ${1} == "fatal" ]]; then
47 | echo "$(date +"%H:%M:%S") ${red}fatal${noColor}: ${2}"
48 | fi
49 | if [[ ${1} == "action" ]] && [[ ${quiet} == false ]]; then
50 | echo "$(date +"%H:%M:%S") ${blue}action${noColor}: ${2}"
51 | fi
52 | if [[ $1 == "debug" ]] && [[ ${quiet} == false ]]; then
53 | echo "$(date +"%H:%M:%S") debug: ${2}"
54 | fi
55 | }
56 |
57 | # checks if debug mode is on
58 | function Debug {
59 | if [[ ${enableDebug} == true ]]; then
60 | echo "$(date +"%Y-%m-%d %H:%M:%S") ${1}" >>"${debugLog}"
61 | fi
62 | if [[ ${verbose} == true ]]; then
63 | Print "debug" "${1}"
64 | fi
65 | }
66 |
67 | # prints all input to screen
68 | function Screen {
69 | if screen -list | grep -q "\.${serverName}"; then
70 | screen -Rd "${serverName}" -X stuff "${1}$(printf '\r')"
71 | fi
72 | }
73 |
74 | # function for parsing all arguments for a script
75 | function ParseArgs {
76 | force=false
77 | help=false
78 | now=false
79 | quiet=false
80 | verbose=false
81 | while [[ $# -gt 0 ]]; do
82 | case "${1}" in
83 | -f)
84 | force=true
85 | ;;
86 | -h)
87 | help=true
88 | ;;
89 | -n)
90 | now=true
91 | ;;
92 | -q)
93 | quiet=true
94 | ;;
95 | -v)
96 | verbose=true
97 | ;;
98 | --force)
99 | force=true
100 | ;;
101 | --help)
102 | help=true
103 | ;;
104 | --now)
105 | now=true
106 | ;;
107 | --quiet)
108 | quiet=true
109 | ;;
110 | --verbose)
111 | verbose=true
112 | ;;
113 | *)
114 | Print "warn" "bad argument: ${1}"
115 | Print "info" "for help use --help"
116 | ;;
117 | esac
118 | shift
119 | done
120 | }
121 |
122 | function ParseCategory {
123 | # standart values
124 | isHourly=false
125 | isDaily=false
126 | isWeekly=false
127 | isMonthly=false
128 | # test and set backup category
129 | if [[ $1 == "--hourly" ]]; then
130 | isHourly=true
131 | elif [[ $1 == "--daily" ]]; then
132 | isDaily=true
133 | elif [[ $1 == "--weekly" ]]; then
134 | isWeekly=true
135 | elif [[ $1 == "--monthly" ]]; then
136 | isMonthly=true
137 | else
138 | Print "error" "\"$1\" is not a backup category"
139 | Print "info" "use --hourly, --daily, --weekly, --monthly"
140 | exit 1
141 | fi
142 | }
143 |
144 | # prints help and then exits
145 | function ArgHelp {
146 | if [[ ${help} == true ]]; then
147 | Print "info" "available arguments:"
148 | Print "info" "argument explanation"
149 | Print "info" "-f --force (ignores script safety checks)"
150 | Print "info" "-h --help (prints this help page)"
151 | Print "info" "-n --now (executes an action without countdown)"
152 | Print "info" "-q --quiet (silences all output except warnings and errors)"
153 | Print "info" "-v --verbose (prints more verbose and extra debug information)"
154 | exit 0
155 | fi
156 | }
157 |
158 | # performs countdown
159 | function Countdown {
160 | if ! [[ ${now} == true ]]; then
161 | counter=60
162 | while [ ${counter} -gt 0 ]; do
163 | if [[ "${counter}" =~ ^(60|40|20|10|5|4|3|2)$ ]]; then
164 | Print "info" "server is ${1} in ${counter} seconds"
165 | TellrawScript "server is ${1} in ${counter} seconds"
166 | fi
167 | if [[ "${counter}" == 1 ]]; then
168 | Print "info" "server is ${1} in ${counter} second"
169 | TellrawScript "server is ${1} in ${counter} second"
170 | fi
171 | counter=$((counter - 1))
172 | sleep 1s
173 | done
174 | fi
175 | }
176 |
177 | # root safety check
178 | function RootSafety {
179 | if [ $(id -u) = 0 ]; then
180 | Print "fatal" "please do not run me as root as this is dangerous :("
181 | exit 1
182 | fi
183 | }
184 |
185 | # checks if a script is already running
186 | function ScriptSafety {
187 | if [[ ${force} == false ]]; then
188 | declare -a scriptsLock=("reset.sh" "restart.sh" "restore.sh" "start.sh" "stop.sh" "update.sh" "vent.sh")
189 | scriptsLockLength=${#scriptsLock[@]}
190 | for ((i = 0; i < ${scriptsLockLength}; i++)); do
191 | for pid in $(pidof -x ${scriptsLock[i]}); do
192 | if [ $pid != $$ ]; then
193 | Print "warn" "script ${scriptsLock[i]} is already running"
194 | Print "info" "use --force option to ignore this safety check"
195 | exit 1
196 | fi
197 | done
198 | done
199 | fi
200 | }
201 |
202 | # checks and coordinates hourly daily weekly and monthly backup
203 | # TODO: write function which prevents backups from happening simultaneous
204 | function BackupSafety {
205 | Print "info" "this function is still in development"
206 | Print "info" "it does not execute anything at the moment"
207 | }
208 |
209 | # check for existence of screen terminal
210 | function CheckScreen {
211 | if ! screen -list | grep -q "\.${serverName}"; then
212 | Log "warn" "server is not currently running" "${screenLog}"
213 | Print "warn" "server is not currently running"
214 | exit 1
215 | fi
216 | }
217 |
218 | # check for existence of screen terminal
219 | function LookForScreen {
220 | if screen -list | grep -q "\.${serverName}"; then
221 | Log "warn" "server is already running" "${screenLog}"
222 | Print "warn" "server is already running - type screen -r ${serverName} to open server terminal"
223 | exit 1
224 | fi
225 | }
226 |
227 | # check for executable
228 | function CheckExecutable {
229 | if ! ls ${executableServerFile}* 1>/dev/null 2>&1; then
230 | Log "fatal" "no executable found" "${screenLog}"
231 | Print "fatal" "no executable found"
232 | exit 1
233 | fi
234 | }
235 |
236 | # prints input to screen with script format
237 | function TellrawScript {
238 | if [[ $# -eq 1 ]]; then
239 | Screen "tellraw @a [\"\",{\"text\":\"[Script] \",\"color\":\"blue\"},{\"text\":\"${1}\"}]"
240 | else
241 | Screen "tellraw @a [\"\",{\"text\":\"[Script] \",\"color\":\"blue\"},{\"text\":\"${1}\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"${2}\"}]}}}]"
242 | fi
243 | }
244 |
245 | # prints input to screen with backup format and color
246 | function TellrawBackup {
247 | if [[ $# -eq 2 ]]; then
248 | Screen "tellraw @a [\"\",{\"text\":\"[Backup] \",\"color\":\"blue\"},{\"text\":\"${1}\",\"color\":\"${2}\"}]"
249 | else
250 | Screen "tellraw @a [\"\",{\"text\":\"[Backup] \",\"color\":\"blue\"},{\"text\":\"${1}\",\"color\":\"${2}\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"${3}\"}]}}}]"
251 | fi
252 | }
253 |
254 | # prints input to screen at given player
255 | function TellrawPlayer {
256 | if [[ $# -eq 2 ]]; then
257 | Screen "tellraw ${1} [\"\",{\"text\":\"[Script] \",\"color\":\"blue\"},{\"text\":\"${2}\"}]"
258 | else
259 | Screen "tellraw ${1} [\"\",{\"text\":\"[Script] \",\"color\":\"blue\"},{\"text\":\"${2} \"},{\"text\":\"${3}\",\"color\":\"${4}\"}]"
260 | fi
261 | }
262 |
263 | # prints welcome to screen at every player
264 | function TellrawWelcome {
265 | if [[ $# -eq 2 ]]; then
266 | Screen "tellraw @a [\"\",{\"text\":\"[Welcome] \",\"color\":\"blue\"},{\"text\":\"${1}\"}],{\"text\":\"${2}\",\"color\":\"green\"}]"
267 | else
268 | Screen "tellraw @a [\"\",{\"text\":\"[Welcome] \",\"color\":\"blue\"},{\"text\":\"${1} \"},{\"text\":\"${2}\",\"color\":\"green\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"${3}\"}]}}}]"
269 | fi
270 | }
271 |
272 | # checks private network availability
273 | function CheckPrivate {
274 | privateChecks=0
275 | while [ ${privateChecks} -lt 8 ]; do
276 | if ping -c 1 "${private}" &>/dev/null; then
277 | Log "ok" "interface is online" "${screenLog}"
278 | Print "ok" "interface is online"
279 | break
280 | else
281 | Log "warn" "interface is offline" "${screenLog}"
282 | Print "warn" "interface is offline"
283 | fi
284 | if [ ${privateChecks} -eq 7 ]; then
285 | Log "error" "interface timed out" "${screenLog}"
286 | Print "error" "interface timed out"
287 | fi
288 | sleep 1s
289 | privateChecks=$((privateChecks + 1))
290 | done
291 | }
292 |
293 | # checks public network availability
294 | function CheckPublic {
295 | publicChecks=0
296 | while [ ${publicChecks} -lt 8 ]; do
297 | if ping -c 1 "${public}" &>/dev/null; then
298 | Log "ok" "nameserver is online" "${screenLog}"
299 | Print "ok" "nameserver is online"
300 | break
301 | else
302 | Log "warn" "nameserver is offline" "${screenLog}"
303 | Print "warn" "nameserver is offline"
304 | fi
305 | if [ ${publicChecks} -eq 7 ]; then
306 | Log "error" "nameserver timed out" "${screenLog}"
307 | Print "error" "nameserver timed out"
308 | fi
309 | sleep 1s
310 | publicChecks=$((publicChecks + 1))
311 | done
312 | }
313 |
314 | # performs server start
315 | function Start {
316 | Print "action" "starting server..."
317 | screen -dmSL "${serverName}" -Logfile "${screenLog}" java -server "${javaArgs}" -jar "${executableServerFile}" -nogui
318 | screen -r "${serverName}" -X colon "logfile flush 1^M"
319 | }
320 |
321 | # awaits server start
322 | function AwaitStart {
323 | startChecks=0
324 | while [ ${startChecks} -lt 10 ]; do
325 | if screen -list | grep -q "\.${serverName}"; then
326 | break
327 | fi
328 | startChecks=$((startChecks + 1))
329 | sleep 1s
330 | done
331 | }
332 |
333 | # performs server stop
334 | function Stop {
335 | Print "action" "stopping server..."
336 | TellrawScript "stopping server..."
337 | sleep 1s
338 | Screen "stop"
339 | }
340 |
341 | # awaits server stop
342 | function AwaitStop {
343 | stopChecks=0
344 | while [ ${stopChecks} -lt 20 ]; do
345 | if ! screen -list | grep -q "\.${serverName}"; then
346 | break
347 | fi
348 | stopChecks=$((stopChecks + 1))
349 | sleep 1s
350 | done
351 | }
352 |
353 | # awaits given string in screen
354 | function AwaitString {
355 | stringChecks=0
356 | while [ ${stringChecks} -lt ${2} ]; do
357 | if tail -1 "${screenLog}" | grep -q "${1}"; then
358 | break
359 | fi
360 | stringChecks=$((stringChecks + 1))
361 | sleep 1s
362 | done
363 | }
364 |
365 | # conditional force quit
366 | function ForceQuit {
367 | if screen -list | grep -q "${serverName}"; then
368 | Log "warn" "${serverName} server still hasn't closed after 30 seconds, closing screen manually..." "${screenLog}"
369 | Print "warn" "${serverName} server still hasn't closed after 30 seconds, closing screen manually..."
370 | screen -S "${serverName}" -X quit
371 | fi
372 | }
373 |
374 | # prints game over as pixel art on terminal
375 | function GameOver {
376 | echo "${red} ______ _____ ${noColor}"
377 | echo "${red} / _____) / ___ \ ${noColor}"
378 | echo "${red} | / ___ ____ ____ ____ | | | |_ _ ____ ____ ${noColor}"
379 | echo "${red} | | (___)/ _ | \ / _ ) | | | | | | / _ )/ ___) ${noColor}"
380 | echo "${red} | \____/( ( | | | | ( (/ / | |___| |\ V ( (/ /| | ${noColor}"
381 | echo "${red} \_____/ \_||_|_|_|_|\____) \_____/ \_/ \____)_| ${noColor}"
382 | echo "${red} ${noColor}"
383 | }
384 |
385 | # declare all scripts in an array
386 | declare -a scripts=("start.sh" "restore.sh" "reset.sh" "restart.sh" "stop.sh" "backup.sh" "update.sh" "worker.sh" "vent.sh")
387 | # get length of script array
388 | scriptsLength=${#scripts[@]}
389 |
390 | # function for removing scripts from serverdirectory
391 | function RemoveScripts {
392 | # remove scripts from serverdirectory
393 | # loop through all entries in the array
394 | Print "info" "removing scripts..."
395 | for ((i = 0; i < ${scriptsLength}; i++)); do
396 | Debug "removing script ${scripts[${i}]}"
397 | rm "${scripts[${i}]}"
398 | done
399 | }
400 |
401 | # function for downloading scripts from github
402 | function DownloadScripts {
403 | # downloading scripts from github
404 | # loop through all entries in the array
405 | Print "info" "downloading scripts..."
406 | for ((i = 0; i < ${scriptsLength}; i++)); do
407 | Debug "downloading script ${scripts[${i}]} from branch ${branch} on github..."
408 | wget -q -O "${scripts[${i}]}" "https://raw.githubusercontent.com/simylein/minecraft-server/${branch}/${scripts[${i}]}"
409 | done
410 | }
411 |
412 | # function for making scripts executable
413 | function ExecutableScripts {
414 | # make selected scripts executable
415 | # loop through all entries in the array
416 | Print "info" "making scripts executable..."
417 | for ((i = 0; i < ${scriptsLength}; i++)); do
418 | Debug "setting script ${scripts[${i}]} executable"
419 | chmod +x ${scripts[${i}]}
420 | done
421 | }
422 |
423 | # change to server directory with error checking
424 | function ChangeServerDirectory {
425 | if [ -d "${serverDirectory}" ]; then
426 | cd ${serverDirectory}
427 | else
428 | Log "fatal" "server-directory is missing - path: ${serverDirectory}" "${screenLog}"
429 | Print "fatal" "server-directory is missing - path: ${serverDirectory}"
430 | exit 1
431 | fi
432 | }
433 |
434 | # change to backup directory with error checking
435 | function ChangeBackupDirectory {
436 | if [ -d "${backupDirectory}" ]; then
437 | cd ${backupDirectory}
438 | else
439 | Log "fatal" "backup-directory is missing - path: ${backupDirectory}" "${screenLog}"
440 | Print "fatal" "backup-directory is missing - path: ${backupDirectory}"
441 | exit 1
442 | fi
443 | }
444 |
445 | # prints success messages to terminal screen and backup log
446 | function OutputBackupSuccess {
447 | Log "ok" "added ${backupDirectory}/${1}/${serverName}-${2}.tar.gz" "${backupLog}"
448 | Log "ok" "removed ${backupDirectory}/${1}/${serverName}-${3}.tar.gz" "${backupLog}"
449 | Log "info" "current world size: ${worldSizeHuman}, current backup size: ${backupSizeHuman}, current disk space: ${diskSpaceHuman}" "${backupLog}"
450 | Log "info" "time spent on backup process: ${timeSpent} milliseconds, compression ratio: ${compressedBackupSize}/${worldSizeHuman}" "${backupLog}"
451 |
452 | Print "ok" "added ${backupDirectory}/${1}/${serverName}-${2}.tar.gz"
453 | Print "ok" "removed ${backupDirectory}/${1}/${serverName}-${3}.tar.gz"
454 | Print "info" "current world size: ${worldSizeHuman}, current backup size: ${backupSizeHuman}, current disk space: ${diskSpaceHuman}"
455 | Print "info" "time spent on backup process: ${timeSpent} milliseconds, compression ratio: ${compressedBackupSize}/${worldSizeHuman}"
456 |
457 | Debug "backup script reports backup success while performing backup-${1}"
458 |
459 | TellrawBackup "ok: successfully created new backup" "green" "created file: ${serverName}-${2}.tar.gz, removed file: ${serverName}-${3}.tar.gz, current world size: ${worldSizeHuman}, current backup size: ${backupSizeHuman}, current disk space: ${diskSpaceHuman}, time spent: ${timeSpent} ms, compression: ${compressedBackupSize}/${worldSizeHuman}"
460 | }
461 |
462 | # prints disk space warning to terminal screen and backup log
463 | function OutputDiskSpaceWarning {
464 | Log "warn" "free disk-space is getting rare - make some room for backups" "${backupLog}"
465 | Log "info" "available disk space ${diskSpaceHuman} - warning at: ${diskSpaceWarning} bytes, limit at: ${diskSpaceError} bytes" "${backupLog}"
466 |
467 | Print "warn" "free disk-space is getting rare - make some room for backups"
468 | Print "info" "available disk space ${diskSpaceHuman} - warning at: ${diskSpaceWarning} bytes, limit at: ${diskSpaceError} bytes"
469 |
470 | Debug "backup script reports low disk-space while performing backup-${1}"
471 |
472 | TellrawBackup "warn: free disk space is getting rare - please tell your server admin" "yellow" "current world size: ${worldSizeHuman}, current backup size: ${backupSizeHuman}, current disk space: ${diskSpaceHuman}, warning: free disk space is getting rare"
473 | }
474 |
475 | # prints backup size warning to terminal screen and backup log
476 | function OutputBackupSizeWarning {
477 | Log "warn" "the created ${1}-backup is only ${compressedBackupSize} - this may point to a corrupted backup" "${backupLog}"
478 | Log "info" "you may change the control variables in the server.settings file - warning at: ${backupSizeWarning} percent, error at: ${backupSizeError} percent"
479 |
480 | Print "warn" "the created ${1}-backup is only ${compressedBackupSize} - this may point to a corrupted backup"
481 | Print "info" "you may change the control variables in the server.settings file - warning at: ${backupSizeWarning} percent, error at: ${backupSizeError} percent"
482 |
483 | Debug "backup script reports potentially corrupted backup at ${backupDirectory}/${1}/${serverName}-${2}"
484 |
485 | TellrawBackup "warn: the created backup is unusally small - please tell your server admin" "yellow" "current world size: ${worldSizeHuman}, created backup size: ${compressedBackupSize}, warning: backup unusally small - this may point to corruption"
486 | }
487 |
488 | # prints disk space error to terminal screen and backup log
489 | function OutputDiskSpaceError {
490 | Log "error" "not enough disk-space to perform backup-${1}" "${backupLog}"
491 | Log "info" "available disk space ${diskSpaceHuman} - warning at: ${diskSpaceWarning} bytes, limit at: ${diskSpaceError} bytes" "${backupLog}"
492 |
493 | Print "error" "not enough disk-space to perform backup-${1}"
494 | Print "info" "available disk space ${diskSpaceHuman} - warning at: ${diskSpaceWarning} bytes, limit at: ${diskSpaceError} bytes"
495 |
496 | Debug "backup script reports not enough disk-space while performing backup-${1}"
497 |
498 | TellrawBackup "fatal: not enough disk space - please immediately tell your server admin" "red" "could not create file: ${serverName}-${2}.tar.gz, could not remove file: ${serverName}-${3}.tar.gz, reason: not enough disk-space"
499 | }
500 |
501 | # prints backup size error to terminal screen and backup log
502 | function OutputBackupSizeError {
503 | Log "error" "the created ${1}-backup is only ${compressedBackupSize} - this will point to a corrupted backup" "${backupLog}"
504 | Log "info" "you may change the control variables in the server.settings file - warning at: ${backupSizeWarning} percent, error at: ${backupSizeError} percent"
505 |
506 | Print "error" "the created ${1}-backup is only ${compressedBackupSize} - this will point to a corrupted backup"
507 | Print "info" "you may change the control variables in the server.settings file - warning at: ${backupSizeWarning} percent, error at: ${backupSizeError} percent"
508 |
509 | Debug "backup script reports dangerous corrupted backup at ${backupDirectory}/${1}/${serverName}-${2}"
510 |
511 | TellrawBackup "error: the created backup is too small - please tell your server admin" "red" "current world size: ${worldSizeHuman}, created backup size: ${compressedBackupSize}, reason: backup too small - this points to corruption"
512 | }
513 |
514 | # prints backup already exists messages to terminal screen and backup log
515 | function OutputBackupAlreadyExists {
516 | Log "error" "could not create new ${1}-backup - backup already exists" "${backupLog}"
517 | Log "info" "the file ${backupDirectory}/${1}/${serverName}-${2} already exists"
518 |
519 | Print "error" "could not create new ${1}-backup - backup already exists"
520 | Print "info" "the file ${backupDirectory}/${1}/${serverName}-${2} already exists"
521 |
522 | Debug "backup script reports backup already exists while performing backup-${1}"
523 |
524 | TellrawBackup "error: backup already exists - please tell your server admin" "red" "could not create file: ${serverName}-${2}.tar.gz, could not remove file: ${serverName}-${3}.tar.gz, reason: backup already exists"
525 | }
526 |
527 | # prints tar backup error messages to terminal screen and backup log
528 | function OutputBackupTarError {
529 | Log "error" "tar reports errors during compression of world directory" "${backupLog}"
530 |
531 | Print "error" "tar reports errors during compression of world directory"
532 |
533 | Debug "backup script reports tar error while performing backup-${1}"
534 |
535 | TellrawBackup "fatal: could not create new backup - please immediately tell your server admin" "red" "could not create file: ${serverName}-${2}.tar.gz, could not remove file: ${serverName}-${3}.tar.gz, reason: tar reports errors during compression of world directory"
536 | }
537 |
538 | # prints copy backup error messages to terminal screen and backup log
539 | function OutputBackupCopyError {
540 | Log "error" "copy reports errors during copying of world directory" "${backupLog}"
541 |
542 | Print "error" "copy reports errors during copying of world directory"
543 |
544 | Debug "backup script reports copy error while performing backup-${1}"
545 |
546 | TellrawBackup "fatal: could not create new backup - please immediately tell your server admin" "red" "could not create file: ${serverName}-${2}.tar.gz, could not remove file: ${serverName}-${3}.tar.gz, reason: copy reports errors during copying of world directory"
547 | }
548 |
549 | # prints generic backup error messages to terminal screen and backup log
550 | function OutputBackupGenericError {
551 | Log "error" "could not backup world" "${backupLog}"
552 |
553 | Print "error" "could not backup world"
554 |
555 | Debug "backup script reports generic backup error while performing backup-${1}"
556 |
557 | TellrawBackup "fatal: could not create new backup - please immediately tell your server admin" "red" "could not create file: ${serverName}-${2}.tar.gz, could not remove file: ${serverName}-${3}.tar.gz, reason: generic error - missing directories, empty file-paths or empty files"
558 | }
559 |
560 | # function for testing if all categories for backups exists if not create them also check for root backups directory
561 | function BackupDirectoryIntegrity {
562 | cd ${serverDirectory}
563 | # check for root backup directory and create if missing
564 | if ! ls ${backupDirectory} &>/dev/null; then
565 | Log "error" "the root-backupdirectory is missing - your backups are likely gone :(" "${backupLog}"
566 | Log "info" "creating a new root-backupdirectory with name backups at ${serverDirectory}" "${backupLog}"
567 | Print "error" "the root-backupdirectory is missing - your backups are likely gone :("
568 | Print "info" "creating a new root-backupdirectory with name backups at ${serverDirectory}"
569 | Screen "tellraw @a [\"\",{\"text\":\"[Backup] \",\"color\":\"blue\"},{\"text\":\"error: the root-backupdirectory is missing - your backups are likely gone :(\",\"color\":\"red\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"reason: backup directory integrity check reports that the root backup directory is missing - the root backup directory has been recreated\"}]}}}]"
570 | mkdir backups
571 | fi
572 | declare -a backupCategories=("cached" "hourly" "daily" "weekly" "monthly")
573 | arrayLenght=${#backupCategories[@]}
574 | for ((i = 0; i < ${arrayLenght}; i++)); do
575 | # check for backup category directories and create if missing
576 | if ! ls ${backupDirectory}/${backupCategories[${i}]} &>/dev/null; then
577 | Log "warn" "the backup-directory ${backupCategories[${i}]} is missing" "${backupLog}"
578 | Log "info" "creating ${backupDirectory}/${backupCategories[${i}]}" "${backupLog}"
579 | Print "warn" "the backup-directory ${backupCategories[${i}]} is missing"
580 | Print "info" "creating ${backupDirectory}/${backupCategories[${i}]}"
581 | Screen "tellraw @a [\"\",{\"text\":\"[Backup] \",\"color\":\"blue\"},{\"text\":\"warn: the ${backupCategories[${i}]} backup category is missing - your ${backupCategories[${i}]} backups are likely gone :/\",\"color\":\"yellow\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"reason: backup directory integrity check reports that the ${backupCategories[${i}]} backup directory is missing - the ${backupCategories[${i}]} backup directory has been recreated\"}]}}}]"
582 | cd ${backupDirectory}
583 | mkdir ${backupCategories[${i}]}
584 | cd ${serverDirectory}
585 | fi
586 | done
587 | }
588 |
589 | # function for creating a cached backup with name as input
590 | function CachedBackup {
591 | # remove all older cached backups
592 | if [[ -s "${backupDirectory}/cached/${1}-"* ]]; then
593 | rm "${backupDirectory}/cached/${1}-"*
594 | fi
595 | # user info about backup to create
596 | Print "action" "creating cached ${1} backup..."
597 | # create backup with given name
598 | nice -n 19 cp -r "world" "tmp-${1}"
599 | nice -n 19 tar -czf "world.tar.gz" "tmp-${1}"
600 | nice -n 19 mv "${serverDirectory}/world.tar.gz" "${backupDirectory}/cached/${1}-${newDaily}-${newHourly}.tar.gz"
601 | nice -n 19 rm -r "tmp-${1}"
602 | # check if safety backup exists
603 | if [[ -s "${backupDirectory}/cached/${1}-${newDaily}-${newHourly}.tar.gz" ]]; then
604 | Log "ok" "created ${backupDirectory}/cached/${1}-${newDaily}-${newHourly}.tar.gz as a ${1} backup" "${backupLog}"
605 |
606 | Print "ok" "${1} backup successful"
607 |
608 | TellrawBackup "ok: backup successful" "green" "created ${backupDirectory}/cached/${1}-${newDaily}-${newHourly}.tar.gz"
609 | else
610 | Log "warn" "${1} backup failed" "${backupLog}"
611 |
612 | Print "warn" "${1} backup failed"
613 |
614 | TellrawBackup "warn: backup failed" "yellow" "failed to create ${backupDirectory}/cached/${1}-${newDaily}-${newHourly}.tar.gz"
615 | fi
616 | }
617 |
618 | # check for help string
619 | function Help {
620 | if tail -1 "${screenLog}" | grep -q "help"; then
621 | player=$(tail -1 screen.log | grep -oP '.*?(?=help)' | cut -d ' ' -f 4- | sed 's/.$//' | rev | sed 's/.$//' | rev | sed 's/.$//')
622 | Log "info" "the player ${player} requested help - server will print help info and admin contact" "${screenLog}"
623 | TellrawPlayer "${player}" "info: available commands: (seperated by comma)"
624 | TellrawPlayer "${player}" "info: list tasks, list backups"
625 | TellrawPlayer "${player}" "info: perform backup, perform restart"
626 | TellrawPlayer "${player}" "info: perform update, perform reset"
627 | TellrawPlayer "${player}" "info: admin contact info: ${adminContact}"
628 | fi
629 | }
630 |
631 | # check for list tasks string
632 | function ListTasks {
633 | if tail -1 "${screenLog}" | grep -q "list tasks"; then
634 | player=$(tail -1 screen.log | grep -oP '.*?(?=list tasks)' | cut -d ' ' -f 4- | sed 's/.$//' | rev | sed 's/.$//' | rev | sed 's/.$//')
635 | if cat "ops.json" | grep -q "${player}"; then
636 | Log "info" "the player ${player} requested list of all tasks and has permission - server will list all tasks" "${screenLog}"
637 | TellrawPlayer "${player}" "info: you successfully requested all available tasks of the server"
638 | # run list tasks
639 | if [[ ${enablePerformBackup} == true ]]; then
640 | TellrawPlayer "${player}" "perform backup is" "enabled" "green"
641 | elif [[ "${enablePerformBackup}" == false ]]; then
642 | TellrawPlayer "${player}" "perform backup is" "disabled" "red"
643 | else
644 | TellrawPlayer "${player}" "perform backup is" "undefined" "grey"
645 | fi
646 | if [[ ${enablePerformRestart} == true ]]; then
647 | TellrawPlayer "${player}" "perform restart is" "enabled" "green"
648 | elif [[ "${enablePerformRestart}" == false ]]; then
649 | TellrawPlayer "${player}" "perform restart is" "disabled" "red"
650 | else
651 | TellrawPlayer "${player}" "perform restart is" "undefined" "grey"
652 | fi
653 | if [[ ${enablePerformUpdate} == true ]]; then
654 | TellrawPlayer "${player}" "perform update is" "enabled" "green"
655 | elif [[ ${enablePerformUpdate} == false ]]; then
656 | TellrawPlayer "${player}" "perform update is" "disabled" "red"
657 | else
658 | TellrawPlayer "${player}" "perform update is" "undefined" "grey"
659 | fi
660 | if [[ ${enablePerformReset} == true ]]; then
661 | TellrawPlayer "${player}" "perform reset is" "enabled" "green"
662 | elif [[ ${enablePerformReset} == false ]]; then
663 | TellrawPlayer "${player}" "perform reset is" "disabled" "red"
664 | else
665 | TellrawPlayer "${player}" "perform reset is" "undefined" "grey"
666 | fi
667 | TellrawPlayer "${player}" "config is located in file server.settings"
668 | else
669 | Log "warn" "the player ${player} requested a list of tasks and does not have permission to do so" "${screenLog}"
670 | TellrawPlayer "${player}" "warn: you do not have permissions to list all available tasks of the server"
671 | fi
672 | fi
673 | }
674 |
675 | # check for list backups string
676 | function ListBackups {
677 | if tail -1 "${screenLog}" | grep -q "list backups"; then
678 | player=$(tail -1 screen.log | grep -oP '.*?(?=list backups)' | cut -d ' ' -f 4- | sed 's/.$//' | rev | sed 's/.$//' | rev | sed 's/.$//')
679 | if cat "ops.json" | grep -q "${player}"; then
680 | Log "info" "the player ${player} requested list of all backups and has permission - server will list all backups" "${screenLog}"
681 | TellrawPlayer "${player}" "info: you successfully requested all available backups of the server"
682 | # run list backups
683 | if [[ ${doHourly} == true ]]; then
684 | TellrawPlayer "${player}" "hourly backup is" "enabled" "green"
685 | elif [[ "${doHourly}" == false ]]; then
686 | TellrawPlayer "${player}" "hourly backup is" "disabled" "red"
687 | else
688 | TellrawPlayer "${player}" "hourly backup is" "undefined" "grey"
689 | fi
690 | if [[ ${doDaily} == true ]]; then
691 | TellrawPlayer "${player}" "daily backup is" "enabled" "green"
692 | elif [[ "${doDaily}" == false ]]; then
693 | TellrawPlayer "${player}" "daily backup is" "disabled" "red"
694 | else
695 | TellrawPlayer "${player}" "daily backup is" "undefined" "grey"
696 | fi
697 | if [[ ${doWeekly} == true ]]; then
698 | TellrawPlayer "${player}" "weekly backup is" "enabled" "green"
699 | elif [[ ${doWeekly} == false ]]; then
700 | TellrawPlayer "${player}" "weekly backup is" "disabled" "red"
701 | else
702 | TellrawPlayer "${player}" "weekly backup is" "undefined" "grey"
703 | fi
704 | if [[ ${doMonthly} == true ]]; then
705 | TellrawPlayer "${player}" "monthly backup is" "enabled" "green"
706 | elif [[ ${doMonthly} == false ]]; then
707 | TellrawPlayer "${player}" "monthly backup is" "disabled" "red"
708 | else
709 | TellrawPlayer "${player}" "monthly backup is" "undefined" "grey"
710 | fi
711 | TellrawPlayer "${player}" "config is located in file server.settings"
712 | else
713 | Log "warn" "the player ${player} requested a list of backups and does not have permission to do so" "${screenLog}"
714 | TellrawPlayer "${player}" "warn: you do not have permissions to list all available backups of the server"
715 | fi
716 | fi
717 | }
718 |
719 | # check for perform backup string
720 | function PerformBackup {
721 | if tail -1 "${screenLog}" | grep -q "perform backup"; then
722 | player=$(tail -1 screen.log | grep -oP '.*?(?=perform backup)' | cut -d ' ' -f 4- | sed 's/.$//' | rev | sed 's/.$//' | rev | sed 's/.$//')
723 | if cat "ops.json" | grep -q "${player}"; then
724 | Log "info" "the player ${player} requested a safety backup and has permission - server will perform safety backup" "${backupLog}"
725 | TellrawPlayer "${player}" "info: you successfully requested a safety backup of the server"
726 | # run safety backup
727 | CachedBackup "safety"
728 | else
729 | Log "warn" "the player ${player} requested a safety backup and does not have permission to do so" "${backupLog}"
730 | TellrawPlayer "${player}" "warn: you do not have permissions to safety backup the server"
731 | fi
732 | fi
733 | }
734 |
735 | # check for perform restart strings
736 | function PerformRestart {
737 | # check for perform restart now string
738 | if tail -1 "${screenLog}" | grep -q "perform restart now"; then
739 | player=$(tail -1 screen.log | grep -oP '.*?(?=perform restart now)' | cut -d ' ' -f 4- | sed 's/.$//' | rev | sed 's/.$//' | rev | sed 's/.$//')
740 | if cat "ops.json" | grep -q "${player}"; then
741 | Log "info" "the player ${player} requested a restart and has permission - server will restart" "${screenLog}"
742 | TellrawPlayer "${player}" "info: you successfully requested a restart of the server"
743 | ./restart.sh --quiet --now
744 | exit 0
745 | else
746 | Log "warn" "the player ${player} requested a restart and does not have permission to do so" "${screenLog}"
747 | TellrawPlayer "${player}" "warn: you do not have permissions to restart the server"
748 | fi
749 | fi
750 | # check for perform restart string
751 | if tail -1 "${screenLog}" | grep -q "perform restart"; then
752 | player=$(tail -1 screen.log | grep -oP '.*?(?=perform restart)' | cut -d ' ' -f 4- | sed 's/.$//' | rev | sed 's/.$//' | rev | sed 's/.$//')
753 | if cat "ops.json" | grep -q "${player}"; then
754 | Log "info" "the player ${player} requested a restart and has permission - server will restart" "${screenLog}"
755 | TellrawPlayer "${player}" "info: you successfully requested a restart of the server"
756 | ./restart.sh --quiet
757 | exit 0
758 | else
759 | Log "warn" "the player ${player} requested a restart and does not have permission to do so" "${screenLog}"
760 | TellrawPlayer "${player}" "warn: you do not have permissions to restart the server"
761 | fi
762 | fi
763 | }
764 |
765 | # check for perform update strings
766 | function PerformUpdate {
767 | # check for perform update now string
768 | if tail -1 "${screenLog}" | grep -q "perform update now"; then
769 | player=$(tail -1 screen.log | grep -oP '.*?(?=perform update now)' | cut -d ' ' -f 4- | sed 's/.$//' | rev | sed 's/.$//' | rev | sed 's/.$//')
770 | if cat "ops.json" | grep -q "${player}"; then
771 | Log "info" "the player ${player} requested an update and has permission - server will update" "${screenLog}"
772 | TellrawPlayer "${player}" "you successfully requested an update of the server"
773 | ./update.sh --quiet --now
774 | exit 0
775 | else
776 | Log "warn" "the player ${player} requested an update and does not have permission to do so" "${screenLog}"
777 | TellrawPlayer "${player}" "you do not have permissions to update the server"
778 | fi
779 | fi
780 | # check for perform update string
781 | if tail -1 "${screenLog}" | grep -q "perform update"; then
782 | player=$(tail -1 screen.log | grep -oP '.*?(?=perform update)' | cut -d ' ' -f 4- | sed 's/.$//' | rev | sed 's/.$//' | rev | sed 's/.$//')
783 | if cat "ops.json" | grep -q "${player}"; then
784 | Log "info" "the player ${player} requested an update and has permission - server will update" "${screenLog}"
785 | TellrawPlayer "${player}" "you successfully requested an update of the server"
786 | ./update.sh --quiet
787 | exit 0
788 | else
789 | Log "warn" "the player ${player} requested an update and does not have permission to do so" "${screenLog}"
790 | TellrawPlayer "${player}" "you do not have permissions to update the server"
791 | fi
792 | fi
793 | }
794 |
795 | # check for perform reset strings
796 | function PerformReset {
797 | # check for perform reset now string
798 | if tail -1 "${screenLog}" | grep -q "perform reset now"; then
799 | player=$(tail -1 screen.log | grep -oP '.*?(?=perform reset now)' | cut -d ' ' -f 4- | sed 's/.$//' | rev | sed 's/.$//' | rev | sed 's/.$//')
800 | if cat "ops.json" | grep -q "${player}"; then
801 | Log "info" "the player ${player} requested a reset and has permission - server will reset" "${screenLog}"
802 | TellrawPlayer "${player}" "info: you successfully requested a reset of the server"
803 | ./reset.sh --quiet --now
804 | exit 0
805 | else
806 | Log "warn" "the player ${player} requested a reset and does not have permission to do so" "${screenLog}"
807 | TellrawPlayer "${player}" "warn: you do not have permissions to reset the server"
808 | fi
809 | fi
810 | # check for perform reset string
811 | if tail -1 "${screenLog}" | grep -q "perform reset"; then
812 | player=$(tail -1 screen.log | grep -oP '.*?(?=perform reset)' | cut -d ' ' -f 4- | sed 's/.$//' | rev | sed 's/.$//' | rev | sed 's/.$//')
813 | if cat "ops.json" | grep -q "${player}"; then
814 | Log "info" "the player ${player} requested a reset and has permission - server will reset" "${screenLog}"
815 | TellrawPlayer "${player}" "info: you successfully requested a reset of the server"
816 | ./reset.sh --quiet
817 | exit 0
818 | else
819 | Log "warn" "the player ${player} requested a reset and does not have permission to do so" "${screenLog}"
820 | TellrawPlayer "${player}" "warn: you do not have permissions to reset the server"
821 | fi
822 | fi
823 | }
824 |
--------------------------------------------------------------------------------
/server.properties:
--------------------------------------------------------------------------------
1 | #Minecraft server properties
2 | #(timestamp of first initializing)
3 | enable-jmx-monitoring=false
4 | rcon.port=25575
5 | gamemode=survival
6 | enable-command-block=false
7 | enable-query=false
8 | level-name=world
9 | motd=A Minecraft Server
10 | query.port=25565
11 | pvp=true
12 | difficulty=easy
13 | network-compression-threshold=256
14 | require-resource-pack=false
15 | max-tick-time=60000
16 | use-native-transport=true
17 | max-players=20
18 | online-mode=true
19 | enable-status=true
20 | allow-flight=false
21 | broadcast-rcon-to-ops=true
22 | view-distance=10
23 | server-ip=
24 | resource-pack-prompt=
25 | allow-nether=true
26 | server-port=25565
27 | enable-rcon=false
28 | sync-chunk-writes=true
29 | op-permission-level=4
30 | prevent-proxy-connections=false
31 | resource-pack=
32 | entity-broadcast-range-percentage=100
33 | simulation-distance=10
34 | rcon.password=
35 | player-idle-timeout=0
36 | force-gamemode=false
37 | rate-limit=0
38 | hardcore=false
39 | white-list=false
40 | broadcast-console-to-ops=true
41 | spawn-npcs=true
42 | spawn-animals=true
43 | snooper-enabled=true
44 | function-permission-level=2
45 | text-filtering-config=
46 | spawn-monsters=true
47 | enforce-whitelist=false
48 | resource-pack-sha1=
49 | spawn-protection=16
50 | max-world-size=29999984
51 |
--------------------------------------------------------------------------------
/server.settings:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # minecraft server settings
3 |
4 | # this file stores all the variables for the server.
5 | # if you know what you are doing, feel free to tinker with them ;^)
6 |
7 | # github branch from whom scripts will fetch
8 | branch="replaceBranch"
9 |
10 | # your contact info for players
11 | adminContact="your admin did not edit the server settings file /:"
12 |
13 | # welcome messages if a player joins
14 | welcome=("welcome on my server" "a warm welcome to" "greetings" "hello to" "welcome aboard" "make yourself at home" "have a nice time" "enjoy yourself")
15 |
16 | # arguments for java server
17 | javaArgs="-Xmx2048M"
18 |
19 | # server resource paths
20 | serverName="replaceServerName"
21 | homeDirectory="replaceHomeDirectory"
22 | serverDirectory="replaceServerDirectory"
23 | backupDirectory="replaceBackupDirectory"
24 | executableServerFile="replaceExecutableServerFile"
25 |
26 | # network public and private addresses
27 | public="1.1.1.1"
28 | private="192.168.1.1"
29 |
30 | # logfile names
31 | screenLog="screen.log"
32 | backupLog="backup.log"
33 | debugLog="debug.log"
34 |
35 | # backup config
36 | doHourly=true
37 | doDaily=true
38 | doWeekly=false
39 | doMonthly=false
40 |
41 | # values in bytes for disk space control
42 | diskSpaceError=2097152
43 | diskSpaceWarning=8208608
44 |
45 | # values in percent for backup size control
46 | backupSizeError=20
47 | backupSizeWarning=40
48 |
49 | # backup file formats
50 | newHourly=$(date +"%H:00")
51 | newDaily=$(date +"%Y-%m-%d")
52 | newWeekly=$(date +"week-%U")
53 | newMonthly=$(date +"%B" | awk '{print tolower($0)}')
54 | oldHourly=$(date -d "-23 hours" +"%H:00")
55 | oldDaily=$(date -d "-17 days" +"%Y-%m-%d")
56 | oldWeekly=$(date -d "-11 weeks" +"week-%U")
57 | oldMonthly=$(date -d "-5 months" +"%B" | awk '{print tolower($0)}')
58 |
59 | # world and backup sizes in bytes and human readable
60 | worldSizeBytes=$(du -sb world | cut -f1)
61 | backupSizeBytes=$(du -sb backups | cut -f1)
62 | diskSpaceBytes=$(df -B 1 / | tail -1 | awk '{print $4}')
63 | worldSizeHuman=$(du -sh world | cut -f1)
64 | backupSizeHuman=$(du -sh backups | cut -f1)
65 | diskSpaceHuman=$(df -h / | tail -1 | awk '{print $4}')
66 |
67 | # enable admin tasks from ingame chat
68 | enablePerformBackup=true
69 | enablePerformRestart=true
70 | enablePerformUpdate=false
71 | enablePerformReset=false
72 |
73 | # enables or disable some advanced options
74 | enableDebug=false
75 | changeToConsole=false
76 | enableWelcomeMessage=true
77 | enableBackupsWatchdog=true
78 | enableAutoStartOnCrash=false
79 |
80 | # terminal output colours
81 | black="$(tput setaf 0)"
82 | red="$(tput setaf 1)"
83 | green="$(tput setaf 2)"
84 | yellow="$(tput setaf 3)"
85 | blue="$(tput setaf 4)"
86 | magenta="$(tput setaf 5)"
87 | cyan="$(tput setaf 6)"
88 | white="$(tput setaf 7)"
89 | noColor="$(tput sgr0)"
90 |
--------------------------------------------------------------------------------
/setup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # script for setting up a minecraft server on linux debian
3 |
4 | # this script has been tested on debian and runs only if all packages are installed
5 | # however you are welcome to try it on any other distribution you like ;^)
6 |
7 | # set color environment
8 | TERM="xterm"
9 |
10 | # branch selection from for github
11 | branch="main"
12 |
13 | # command line colours
14 | black="$(tput setaf 0)"
15 | red="$(tput setaf 1)"
16 | green="$(tput setaf 2)"
17 | yellow="$(tput setaf 3)"
18 | blue="$(tput setaf 4)"
19 | magenta="$(tput setaf 5)"
20 | cyan="$(tput setaf 6)"
21 | white="$(tput setaf 7)"
22 | noColor="$(tput sgr0)"
23 |
24 | # prints all input to terminal at given log level
25 | function Print {
26 | if [[ ${1} == "ok" ]]; then
27 | echo "$(date +"%H:%M:%S") ${green}ok${noColor}: ${2}"
28 | fi
29 | if [[ ${1} == "info" ]]; then
30 | echo "$(date +"%H:%M:%S") ${cyan}info${noColor}: ${2}"
31 | fi
32 | if [[ ${1} == "warn" ]]; then
33 | echo "$(date +"%H:%M:%S") ${yellow}warn${noColor}: ${2}"
34 | fi
35 | if [[ ${1} == "error" ]]; then
36 | echo "$(date +"%H:%M:%S") ${red}error${noColor}: ${2}"
37 | fi
38 | if [[ ${1} == "fatal" ]]; then
39 | echo "$(date +"%H:%M:%S") ${red}fatal${noColor}: ${2}"
40 | fi
41 | if [[ ${1} == "action" ]]; then
42 | echo "$(date +"%H:%M:%S") ${blue}action${noColor}: ${2}"
43 | fi
44 | }
45 |
46 | # function for parsing all arguments of script
47 | function ParseArgs {
48 | nameArg=false
49 | proceedArg=false
50 | versionArg=false
51 | eulaArg=false
52 | portArg=false
53 | removeArg=false
54 | startArg=false
55 | help=false
56 | while [[ $# -gt 0 ]]; do
57 | case "${1}" in
58 | --name)
59 | nameArg=true
60 | shift
61 | nameVal="${1}"
62 | ;;
63 | --proceed)
64 | proceedArg=true
65 | shift
66 | proceedVal="${1}"
67 | ;;
68 | --version)
69 | versionArg=true
70 | shift
71 | versionVal="${1}"
72 | ;;
73 | --eula)
74 | eulaArg=true
75 | shift
76 | eulaVal="${1}"
77 | ;;
78 | --port)
79 | portArg=true
80 | shift
81 | portVal="${1}"
82 | ;;
83 | --remove)
84 | removeArg=true
85 | shift
86 | removeVal="${1}"
87 | ;;
88 | --start)
89 | startArg=true
90 | shift
91 | startVal="${1}"
92 | ;;
93 | --help)
94 | help=true
95 | ;;
96 | *)
97 | Print "warn" "bad argument: ${1}"
98 | Print "info" "for help use --help"
99 | ;;
100 | esac
101 | shift
102 | done
103 | }
104 |
105 | # prints arguments help
106 | function ArgHelp {
107 | if [[ ${help} == true ]]; then
108 | Print "info" "available arguments:"
109 | Print "info" "argument example type explanation"
110 | Print "info" "--name minecraft string (your server name)"
111 | Print "info" "--proceed true boolean (proceed without user input)"
112 | Print "info" "--version 1.18.2 string (minecraft server version)"
113 | Print "info" "--eula true boolean (accept eula from mojang)"
114 | Print "info" "--port 25565 number (server port to run on)"
115 | Print "info" "--remove true boolean (remove script after execution)"
116 | Print "info" "--start true boolean (start server after execution)"
117 | exit 0
118 | fi
119 | }
120 |
121 | # function for storing variables in server.settings
122 | function StoreSettings {
123 | sed -i "s|${1}|${2}|g" server.settings
124 | }
125 |
126 | # function for storing settings in server.properties
127 | function StoreProperties {
128 | sed -i "s|${1}|${2}|g" server.properties
129 | }
130 |
131 | # store to crontab function
132 | function StoreCrontab {
133 | crontab -l | {
134 | cat
135 | echo "${1}"
136 | } | crontab -
137 | }
138 |
139 | # check for Linux
140 | function CheckLinux {
141 | if [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
142 | # inform user about Linux
143 | Print "ok" "you are running Linux as your operating system - your server will likely run!"
144 | # get free memory on linux
145 | memory="$(free -b | tail -2 | head -1 | awk '{print $4}')"
146 | # check memory
147 | if ((${memory} < 2560000000)); then
148 | Print "warn" "your system has less than 2.56 GB of memory - this may impact server performance!"
149 | fi
150 | # get number of threads on Linux
151 | threads=$(nproc)
152 | # check threads
153 | if ((${threads} < 4)); then
154 | Print "warn" "your system has less than 4 threads - this may impact server performance!"
155 | fi
156 | supported=true
157 | else
158 | supported=false
159 | fi
160 | }
161 |
162 | # check for macOS
163 | function CheckMacOS {
164 | if [ "$(uname)" == "Darwin" ]; then
165 | # inform user about macOS
166 | Print "warn" "you are running macOS as your operating system - your server may not run!"
167 | # get free memory on macOS
168 | memory=$(($(vm_stat | head -2 | tail -1 | awk '{print $3}' | sed 's/.$//') + $(vm_stat | head -4 | tail -1 | awk '{print $3}' | sed 's/.$//') * 4096))
169 | # check memory
170 | if ((${memory} < 2560000000)); then
171 | Print "warn" "your system has less than 2.56 GB of memory - this may impact server performance!"
172 | fi
173 | # get number of threads on macOS
174 | threads=$(nproc)
175 | # check threads
176 | if ((${threads} < 4)); then
177 | Print "warn" "your system has less than 4 threads - this may impact server performance!"
178 | fi
179 | supported=true
180 | else
181 | supported=false
182 | fi
183 | }
184 |
185 | # check for Windows
186 | function CheckWindows {
187 | if [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then
188 | # inform user about Windows
189 | Print "fatal" "you are running Windows as your operating system - your server will not run!"
190 | supported=false
191 | exit 1
192 | fi
193 | }
194 |
195 | # check for unsupported OS
196 | function CheckUnsupported {
197 | if [ supported == false ]; then
198 | # inform user about unsupported operating system
199 | Print "fatal" "you are running an unsupported operating system - your server will not run!"
200 | exit 1
201 | fi
202 | }
203 |
204 | # function for downloading server file from mojang api with error checking
205 | function FetchServerFile {
206 | Print "info" "downloading minecraft-server.${version}.jar..."
207 | wget -q -O "minecraft-server.${version}.jar" "https://launcher.mojang.com/v1/objects/${1}/server.jar"
208 | executableServerFile="${serverDirectory}/minecraft-server.${version}.jar"
209 | if [[ -s "minecraft-server.${version}.jar" ]]; then
210 | Print "ok" "download successful"
211 | else
212 | Print "fatal" "downloaded server-file minecraft-server.${version}.jar is empty or not available"
213 | fi
214 | }
215 |
216 | # root safety check
217 | function RootSafety {
218 | if [ $(id -u) = 0 ]; then
219 | Print "fatal" "please do not run me as root :( - this is dangerous!"
220 | exit 1
221 | fi
222 | }
223 |
224 | # checks if a script is already running
225 | function ScriptSafety {
226 | if [[ ${force} == false ]]; then
227 | if pidof -x "setup.sh" &>/dev/null; then
228 | Print "warn" "script setup.sh is already running"
229 | exit 1
230 | fi
231 | fi
232 | }
233 |
234 | # safety
235 | RootSafety
236 | ScriptSafety
237 |
238 | # os detection
239 | CheckLinux
240 | CheckMacOS
241 | CheckWindows
242 | CheckUnsupported
243 |
244 | # arguments
245 | ParseArgs "$@"
246 | ArgHelp
247 |
248 | # user info about script
249 | Print "action" "i will setup a minecraft server for you ;^)"
250 |
251 | # initial question
252 | if [[ ${nameArg} == false ]]; then
253 | read -re -i "minecraft" -p "$(date +"%H:%M:%S") prompt: how should I call your server? your name: " serverName
254 | elif [[ ${nameArg} == true ]]; then
255 | serverName="${nameVal}"
256 | fi
257 | regex="^[a-zA-Z0-9]+$"
258 | verify=false
259 | while [[ ${verify} == false ]]; do
260 | if [[ ! "${serverName}" =~ ${regex} ]]; then
261 | read -p "$(date +"%H:%M:%S") prompt: please enter a name which only contains letters and numbers: " serverName
262 | else
263 | regexCheck=true
264 | fi
265 | if [ -d "${serverName}" ]; then
266 | read -p "$(date +"%H:%M:%S") prompt: directory ${serverName} already exists - please enter another directory: " serverName
267 | else
268 | existsCheck=true
269 | fi
270 | if [[ ${regexCheck} == true ]] && [[ ${existsCheck} == true ]]; then
271 | verify=true
272 | else
273 | verify=false
274 | fi
275 | done
276 |
277 | # user info
278 | Print "info" "your server will be called ${green}${serverName}${noColor}"
279 |
280 | # store home-directory
281 | homeDirectory=$(pwd)
282 |
283 | # ask for permission to proceed
284 | Print "info" "i will download start, stop, restart, backup and many more scripts from github"
285 | if [[ ${proceedArg} == false ]]; then
286 | read -p "$(date +"%H:%M:%S") prompt: proceed? (y/n): " answer
287 | elif [[ ${proceedArg} == true ]]; then
288 | if [[ ${proceedVal} == true ]]; then
289 | answer=y
290 | elif [[ ${proceedVal} == false ]]; then
291 | answer=n
292 | fi
293 | fi
294 | regex="^(Y|y|N|n)$"
295 | while [[ ! ${answer} =~ ${regex} ]]; do
296 | read -p "$(date +"%H:%M:%S") prompt: please press y or n: " answer
297 | done
298 | if [[ $answer =~ ^[Yy]$ ]]; then
299 | Print "ok" "starting setup..."
300 | else
301 | Print "error" "exiting..."
302 | exit 1
303 | fi
304 |
305 | # set up server directory
306 | Print "info" "setting up a server-directory..."
307 | mkdir "${serverName}"
308 | cd "${serverName}"
309 |
310 | # user info about download
311 | Print "info" "downloading scripts from github..."
312 |
313 | # downloading scripts from github
314 | declare -a scriptsDownload=("server.settings" "server.properties" "server.functions" "start.sh" "restore.sh" "reset.sh" "restart.sh" "stop.sh" "backup.sh" "update.sh" "worker.sh" "vent.sh")
315 | arrayLength=${#scriptsDownload[@]}
316 | for ((i = 0; i < ${arrayLength}; i++)); do
317 | wget -q -O "${scriptsDownload[${i}]}" "https://raw.githubusercontent.com/simylein/minecraft-server/${branch}/${scriptsDownload[${i}]}"
318 | done
319 |
320 | # user info about download
321 | Print "ok" "download successful"
322 |
323 | # make selected scripts executable
324 | declare -a scriptsExecutable=("start.sh" "restore.sh" "reset.sh" "restart.sh" "stop.sh" "backup.sh" "update.sh" "worker.sh" "vent.sh")
325 | arrayLength=${#scriptsExecutable[@]}
326 | for ((i = 0; i < ${arrayLength}; i++)); do
327 | chmod +x "${scriptsExecutable[${i}]}"
328 | done
329 |
330 | # store server-directory
331 | serverDirectory=$(pwd)
332 |
333 | # download java executable from mojang
334 | if [[ ${versionArg} == false ]]; then
335 | PS3="$(date +"%H:%M:%S") prompt: which server version would you like to install? "
336 | versions=("1.21.5" "1.20.5" "1.19.4" "1.18.2")
337 | select version in "${versions[@]}"; do
338 | case ${version} in
339 | "1.21.5")
340 | FetchServerFile "e6ec2f64e6080b9b5d9b471b291c33cc7f509733"
341 | break
342 | ;;
343 | "1.20.5")
344 | FetchServerFile "79493072f65e17243fd36a699c9a96b4381feb91"
345 | break
346 | ;;
347 | "1.19.4")
348 | FetchServerFile "8f3112a1049751cc472ec13e397eade5336ca7ae"
349 | break
350 | ;;
351 | "1.18.2")
352 | FetchServerFile "c8f83c5655308435b3dcf03c06d9fe8740a77469"
353 | break
354 | ;;
355 | *)
356 | echo "please choose an option from the list: "
357 | ;;
358 | esac
359 | done
360 | elif [[ ${versionArg} == true ]]; then
361 | version="${versionVal}"
362 | case ${version} in
363 | "1.21.5")
364 | FetchServerFile "e6ec2f64e6080b9b5d9b471b291c33cc7f509733"
365 | ;;
366 | "1.20.5")
367 | FetchServerFile "79493072f65e17243fd36a699c9a96b4381feb91"
368 | ;;
369 | "1.19.4")
370 | FetchServerFile "8f3112a1049751cc472ec13e397eade5336ca7ae"
371 | ;;
372 | "1.18.2")
373 | FetchServerFile "c8f83c5655308435b3dcf03c06d9fe8740a77469"
374 | ;;
375 | *)
376 | echo "please choose an option from the list: "
377 | ;;
378 | esac
379 | fi
380 |
381 | # user information about execute at start
382 | Print "info" "your server will execute ${executableServerFile} at start"
383 |
384 | # set up backup-directory with child directories
385 | Print "info" "setting up a backup-directory..."
386 | mkdir world
387 | mkdir backups
388 | cd backups
389 | declare -a backupChildren=("hourly" "daily" "weekly" "monthly" "cached")
390 | arrayLength=${#backupChildren[@]}
391 | for ((i = 0; i < ${arrayLength}; i++)); do
392 | mkdir "${backupChildren[${i}]}"
393 | done
394 | backupDirectory=$(pwd)
395 | cd ${serverDirectory}
396 |
397 | # eula question
398 | Print "info" "would you like to accept the end user license agreement from mojang?"
399 | if [[ ${eulaArg} == false ]]; then
400 | read -p "$(date +"%H:%M:%S") prompt: (y/n): " answer
401 | elif [[ ${eulaArg} == true ]]; then
402 | if [[ ${eulaVal} == true ]]; then
403 | answer=y
404 | elif [[ ${eulaVal} == false ]]; then
405 | answer=n
406 | fi
407 | fi
408 | regex="^(Y|y|N|n)$"
409 | while [[ ! ${answer} =~ ${regex} ]]; do
410 | read -p "$(date +"%H:%M:%S") prompt: please press y or n: " answer
411 | done
412 | if [[ ${answer} =~ ^[Yy]$ ]]; then
413 | Print "ok" "accepting eula..."
414 | echo "eula=true" >>eula.txt
415 | else
416 | Print "error" "declining eula..."
417 | echo "eula=false" >>eula.txt
418 | fi
419 |
420 | # determine server port
421 | if [[ ${portArg} == true ]]; then
422 | StoreProperties "server-port=25565" "server-port=${portVal}"
423 | fi
424 |
425 | # store to settings
426 | Print "info" "storing variables in server.settings..."
427 | StoreSettings "replaceBranch" "${branch}"
428 | StoreSettings "replaceServerName" "${serverName}"
429 | StoreSettings "replaceHomeDirectory" "${homeDirectory}"
430 | StoreSettings "replaceServerDirectory" "${serverDirectory}"
431 | StoreSettings "replaceBackupDirectory" "${backupDirectory}"
432 | StoreSettings "replaceExecutableServerFile" "${executableServerFile}"
433 |
434 | # store to properties
435 | Print "info" "storing variables in server.properties..."
436 | StoreProperties "white-list=false" "white-list=true"
437 | StoreProperties "enforce-whitelist=false" "enforce-whitelist=true"
438 | StoreProperties "op-permission-level=4" "op-permission-level=3"
439 | StoreProperties "difficulty=easy" "difficulty=normal"
440 | StoreProperties "max-players=20" "max-players=8"
441 | StoreProperties "view-distance=10" "view-distance=16"
442 | StoreProperties "simulation-distance=10" "simulation-distance=8"
443 | StoreProperties "sync-chunk-writes=true" "sync-chunk-writes=false"
444 | StoreProperties "motd=A Minecraft Server" "motd=Hello World, I am your new Minecraft Server ;^)"
445 |
446 | # store to crontab
447 | Print "info" "storing config to crontab..."
448 | date=$(date +"%Y-%m-%d %H:%M:%S")
449 | StoreCrontab "# minecraft ${serverName} server automatisation - executed setup.sh at $(date +"%Y-%m-%d %H:%M:%S")"
450 | StoreCrontab ""
451 | StoreCrontab "#MAILTO=youremail@example.com"
452 | StoreCrontab "TERM=xterm"
453 | StoreCrontab ""
454 | StoreCrontab "# minecraft ${serverName} server backup hourly at **:00"
455 | StoreCrontab "0 * * * * cd ${serverDirectory} && ./backup.sh --hourly --quiet"
456 | StoreCrontab "# minecraft ${serverName} server backup daily at **:00"
457 | StoreCrontab "0 0 * * * cd ${serverDirectory} && ./backup.sh --daily --quiet"
458 | StoreCrontab "# minecraft ${serverName} server backup weekly at **:00"
459 | StoreCrontab "0 0 * * 0 cd ${serverDirectory} && ./backup.sh --weekly --quiet"
460 | StoreCrontab "# minecraft ${serverName} server backup monthly at **:00"
461 | StoreCrontab "0 0 1 * * cd ${serverDirectory} && ./backup.sh --monthly --quiet"
462 | StoreCrontab "# minecraft ${serverName} server startup at boot"
463 | StoreCrontab "@reboot cd ${serverDirectory} && ./start.sh --quiet --force"
464 | StoreCrontab ""
465 | StoreCrontab ""
466 |
467 | # finish message
468 | Print "ok" "setup is complete!"
469 |
470 | # ask user for removal of setup script
471 | if [[ ${removeArg} == false ]]; then
472 | read -p "$(date +"%H:%M:%S") prompt: would you like to remove the setup script? (y/n): " answer
473 | elif [[ ${removeArg} == true ]]; then
474 | if [[ ${removeVal} == true ]]; then
475 | answer=y
476 | elif [[ ${removeVal} == false ]]; then
477 | answer=n
478 | fi
479 | fi
480 | regex="^(Y|y|N|n)$"
481 | while [[ ! ${answer} =~ ${regex} ]]; do
482 | read -p "$(date +"%H:%M:%S") prompt: please press y or n: " answer
483 | done
484 | if [[ ${answer} =~ ^[Yy]$ ]]; then
485 | cd "${homeDirectory}"
486 | rm setup.sh
487 | cd "${serverDirectory}"
488 | fi
489 |
490 | # ask user to start server now
491 | if [[ ${startArg} == false ]]; then
492 | read -p "$(date +"%H:%M:%S") prompt: would you like to start your server now? (y/n): " answer
493 | elif [[ ${startArg} == true ]]; then
494 | if [[ ${startVal} == true ]]; then
495 | answer=y
496 | elif [[ ${startVal} == false ]]; then
497 | answer=n
498 | fi
499 | fi
500 |
501 | regex="^(Y|y|N|n)$"
502 | while [[ ! ${answer} =~ ${regex} ]]; do
503 | read -p "$(date +"%H:%M:%S") prompt: please press y or n: " answer
504 | done
505 | if [[ ${answer} =~ ^[Yy]$ ]]; then
506 | Print "action" "starting up server..."
507 | ./start.sh
508 | else
509 | Print "ok" "script has finished!"
510 | fi
511 |
512 | # exit with code 0
513 | exit 0
514 |
--------------------------------------------------------------------------------
/start.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # minecraft server start script
3 |
4 | # read server files
5 | source server.settings
6 | source server.functions
7 |
8 | # parse arguments
9 | ParseArgs "$@"
10 | ArgHelp
11 |
12 | # safety checks
13 | RootSafety
14 | ScriptSafety
15 |
16 | # debug
17 | Debug "executing $0 script"
18 |
19 | # change to server directory
20 | ChangeServerDirectory
21 |
22 | # check for existence of executable
23 | CheckExecutable
24 |
25 | # look if server is running
26 | LookForScreen
27 |
28 | # check if private network is online
29 | CheckPrivate
30 |
31 | # check if public network is online
32 | CheckPublic
33 |
34 | # user information
35 | Print "info" "starting minecraft server. to view window type screen -r ${serverName}."
36 | Print "info" "to minimise the window and let the server run in the background, press ctrl+a then ctrl+d"
37 |
38 | # main start command
39 | Start
40 |
41 | # check if screen is available
42 | AwaitStart
43 |
44 | # if no screen output error
45 | if ! screen -list | grep -q "${serverName}"; then
46 | Log "fatal" "something went wrong - server failed to start!" "${screenLog}"
47 | Print "fatal" "something went wrong - server failed to start!"
48 | Print "info" "crash dump - last 10 lines of ${screenLog}"
49 | tail -10 "${screenLog}"
50 | exit 1
51 | fi
52 |
53 | # successful start sequence
54 | Log "ok" "server is on startup..." "${screenLog}"
55 | Print "ok" "server is on startup..."
56 |
57 | # check if screen log contains start confirmation
58 | count="0"
59 | counter="0"
60 | startupChecks="0"
61 | while [ ${startupChecks} -lt 120 ]; do
62 | if tail "${screenLog}" | grep -q "Time elapsed:"; then
63 | Log "ok" "server startup successful - up and running" "${screenLog}"
64 | Print "ok" "server startup successful - up and running"
65 | break
66 | fi
67 | if tail -20 "${screenLog}" | grep -q "FAILED TO BIND TO PORT"; then
68 | Log "error" "server port is already in use - please change to another port" "${screenLog}"
69 | Print "error" "server port is already in use - please change to another port"
70 | exit 1
71 | fi
72 | if tail -20 "${screenLog}" | grep -q "Address already in use"; then
73 | Log "error" "server address is already in use - please change to another port" "${screenLog}"
74 | Print "error" "server address is already in use - please change to another port"
75 | exit 1
76 | fi
77 | if tail -20 "${screenLog}" | grep -q "session.lock: already locked"; then
78 | Log "error" "session is locked - is the world in use by another instance?" "${screenLog}"
79 | Print "error" "session is locked - is the world in use by another instance?"
80 | exit 1
81 | fi
82 | if ! screen -list | grep -q "${serverName}"; then
83 | Log "fatal" "something went wrong - server appears to have crashed!" "${screenLog}"
84 | Print "fatal" "something went wrong - server appears to have crashed!"
85 | Print "info" "crash dump - last 10 lines of ${screenLog}"
86 | tail -10 "${screenLog}"
87 | exit 1
88 | fi
89 | if tail "${screenLog}" | grep -q "Preparing spawn area"; then
90 | counter=$((counter + 1))
91 | fi
92 | if tail "${screenLog}" | grep -q "Environment"; then
93 | if [ ${count} -eq 0 ]; then
94 | Print "info" "server is loading the environment..."
95 | fi
96 | count=$((count + 1))
97 | fi
98 | if tail "${screenLog}" | grep -q "Reloading ResourceManager"; then
99 | count=$((count + 1))
100 | fi
101 | if tail "${screenLog}" | grep -q "Starting minecraft server"; then
102 | count=$((count + 1))
103 | fi
104 | if [ ${counter} -ge 10 ]; then
105 | Print "info" "server is preparing spawn area..."
106 | counter="0"
107 | fi
108 | if [ ${count} -eq 0 ] && [ ${startupChecks} -eq 20 ]; then
109 | Log "warn" "the server could be crashed" "${screenLog}"
110 | Print "warn" "the server could be crashed"
111 | exit 1
112 | fi
113 | startupChecks=$((startupChecks + 1))
114 | sleep 1s
115 | done
116 |
117 | # check if screen log does not contain startup confirmation
118 | if ! tail "${screenLog}" | grep -q "Time elapsed:"; then
119 | Log "warn" "server startup unsuccessful" "${screenLog}"
120 | Print "warn" "server startup unsuccessful"
121 | Print "info" "crash dump - last 10 lines of ${screenLog}"
122 | tail -10 "${screenLog}"
123 | fi
124 |
125 | # enable worker script
126 | nice -n 19 ./worker.sh &
127 |
128 | if [[ "${enableBackupsWatchdog}" == true ]]; then
129 | Print "info" "activating backups watchdog..."
130 | fi
131 | if [[ "${enableWelcomeMessage}" == true ]]; then
132 | Print "info" "activating welcome messages..."
133 | fi
134 | if [[ "${enableAutoStartOnCrash}" == true ]]; then
135 | Print "info" "activating auto start on crash..."
136 | fi
137 | if [[ "${changeToConsole}" == true ]]; then
138 | Print "info" "changing to server console..."
139 | screen -r "${serverName}"
140 | fi
141 |
142 | Print "info" "if you would like to change to server console - type screen -r ${serverName}"
143 |
144 | Debug "executed $0 script"
145 |
146 | exit 0
147 |
--------------------------------------------------------------------------------
/stop.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # minecraft server stop script
3 |
4 | # read server files
5 | source server.settings
6 | source server.functions
7 |
8 | # parse arguments
9 | ParseArgs "$@"
10 | ArgHelp
11 |
12 | # safety checks
13 | RootSafety
14 | ScriptSafety
15 |
16 | # debug
17 | Debug "executing $0 script"
18 |
19 | # change to server directory
20 | ChangeServerDirectory
21 |
22 | # check for existance of executable
23 | CheckExecutable
24 |
25 | # look if server is running
26 | CheckScreen
27 |
28 | # prints countdown to screen
29 | Countdown "stopping"
30 |
31 | # server stop
32 | Stop
33 |
34 | # awaits server stop
35 | AwaitStop
36 |
37 | # force quit server if not stopped
38 | ForceQuit
39 |
40 | # output confirmed stop
41 | Log "ok" "server successfully stopped" "${screenLog}"
42 | Print "ok" "server successfully stopped"
43 |
44 | # log to debug if true
45 | Debug "executed $0 script"
46 |
47 | # exit with code 0
48 | exit 0
49 |
--------------------------------------------------------------------------------
/update.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # minecraft server update script
3 |
4 | # read server files
5 | source server.settings
6 | source server.functions
7 |
8 | # parse arguments
9 | ParseArgs "$@"
10 | ArgHelp
11 |
12 | # safety checks
13 | RootSafety
14 | ScriptSafety
15 |
16 | # debug
17 | Debug "executing $0 script"
18 |
19 | # change to server directory
20 | ChangeServerDirectory
21 |
22 | # check for existence of executable
23 | CheckExecutable
24 |
25 | # look if server is running
26 | CheckScreen
27 |
28 | # prints countdown to screen
29 | Countdown "updating"
30 |
31 | # server stop
32 | Stop
33 |
34 | # awaits server stop
35 | AwaitStop
36 |
37 | # force quit server if not stopped
38 | ForceQuit
39 |
40 | # output confirmed stop
41 | Log "ok" "server successfully stopped" "${screenLog}"
42 | Print "ok" "server successfully stopped"
43 |
44 | # create backup
45 | CachedBackup "update"
46 |
47 | # update from url
48 | url="https://launcher.mojang.com/v1/objects/e6ec2f64e6080b9b5d9b471b291c33cc7f509733/server.jar"
49 | version="1.21.5"
50 |
51 | # Test internet connectivity and update on success
52 | wget --spider --quiet "${url}"
53 | if [ "$?" != 0 ]; then
54 | Log "warn" "unable to connect to mojang api skipping update..." "${screenLog}"
55 | Print "warn" "unable to connect to mojang api skipping update..."
56 | else
57 | Log "action" "downloading newest server version..." "${screenLog}"
58 | Print "action" "downloading newest server version..."
59 | # check if already on newest version
60 | if [[ "${executableServerFile}" = *"minecraft-server.${version}.jar" ]]; then
61 | Log "info" "you are running the newest server version - skipping update" "${screenLog}"
62 | Print "info" "you are running the newest server version - skipping update"
63 | else
64 | wget -q -O "minecraft-server.${version}.jar" "${url}"
65 | # update server-file variable in server.settings
66 | newExecutableServerFile="${serverDirectory}/minecraft-server.${version}.jar"
67 | # if new server-file exists remove old server-file
68 | if [ -s "${newExecutableServerFile}" ]; then
69 | Log "ok" "download successful" "${screenLog}"
70 | Print "ok" "download successful"
71 | Log "info" "updating server.settings for startup with new server version ${version}" "${screenLog}"
72 | Print "info" "updating server.settings for startup with new server version ${version}"
73 | sed -i "s|${executableServerFile}|${newExecutableServerFile}|g" "server.settings"
74 | # remove old server-file if it exists
75 | if [ -s "${executableServerFile}" ]; then
76 | rm "${executableServerFile}"
77 | fi
78 | else
79 | Print "warn" "could not remove old server-file ${executableServerFile} because new server-file ${newExecutableServerFile} is missing"
80 | Print "info" "server will startup with old server-file ${executableServerFile}"
81 | fi
82 | fi
83 | fi
84 |
85 | # remove scripts from server-directory
86 | RemoveScripts
87 |
88 | # downloading scripts from github
89 | DownloadScripts
90 |
91 | # make selected scripts executable
92 | ExecutableScripts
93 |
94 | # restart the server
95 | Print "action" "restarting server..."
96 | ./start.sh --force "$@"
97 |
98 | # log to debug if true
99 | Debug "executed $0 script"
100 |
101 | # exit with code 0
102 | exit 0
103 |
--------------------------------------------------------------------------------
/vent.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # minecraft server selft-destruct script
3 |
4 | # WARNING do not execute unless you want to delete your server
5 |
6 | # read server files
7 | source server.settings
8 | source server.functions
9 |
10 | # parse arguments
11 | ParseArgs "$@"
12 | ArgHelp
13 |
14 | # safety checks
15 | RootSafety
16 | ScriptSafety
17 |
18 | # debug
19 | Debug "executing $0 script"
20 |
21 | # change to server directory
22 | ChangeServerDirectory
23 |
24 | # check for existance of executable
25 | CheckExecutable
26 |
27 | # look if server is running
28 | CheckScreen
29 |
30 | # user safety function for confirmation
31 | Print "warn" "are you sure you want to vent your server?"
32 | read -p "$(date +"%H:%M:%S") prompt: if so, please type confirm venting: "
33 | if [[ ${REPLY} == "confirm venting" ]]; then
34 | Print "info" "you confirmed venting - server will self-destruct now"
35 | else
36 | Print "error" "wrong venting token - you may try again"
37 | exit 1
38 | fi
39 |
40 | # prints countdown to screen
41 | Countdown "self-destructing"
42 |
43 | # game over
44 | Screen "tellraw @a [\"\",{\"text\":\"[Script] \",\"color\":\"blue\"},{\"text\":\"GAME OVER\",\"color\":\"red\"}]"
45 |
46 | # server stop
47 | Stop
48 |
49 | # awaits server stop
50 | AwaitStop
51 |
52 | # force quit server if not stopped
53 | ForceQuit
54 |
55 | cd "${homeDirectory}"
56 | # remove crontab
57 | crontab -r
58 | # remove serverdirectory
59 | Print "action" "deleting server..."
60 | rm -r "${serverName}"
61 | # check if vent was successful
62 | if ! [ -d "${serverDirectory}" ]; then
63 | # game over terminal screen
64 | GameOver
65 | else
66 | # error if serverdirectory still exists
67 | Print "error" "venting failed!"
68 | exit 1
69 | fi
70 |
71 | # debug
72 | Debug "executed $0 script"
73 |
74 | # exit with code 0
75 | exit 0
76 |
--------------------------------------------------------------------------------
/worker.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # minecraft server worker script
3 |
4 | # read server files
5 | source server.settings
6 | source server.functions
7 |
8 | # parse arguments
9 | ParseArgs "$@"
10 | ArgHelp
11 |
12 | # safety checks
13 | RootSafety
14 | ScriptSafety
15 |
16 | # debug
17 | Debug "executing $0"
18 |
19 | # change to server directory
20 | ChangeServerDirectory
21 |
22 | # check if server is running
23 | CheckScreen
24 |
25 | # run various functions every second until server exits
26 | counter=0
27 | while true; do
28 | if ! [[ -d ${serverDirectory} ]]; then
29 | exit 0
30 | fi
31 |
32 | if ! screen -list | grep -q "\.${serverName}"; then
33 | Debug "executed $0 script"
34 | exit 0
35 | fi
36 |
37 | lineBuffer=$(tail -1 "${screenLog}")
38 | if [[ ! ${lineBuffer} == ${lastLineBuffer} ]]; then
39 | if [[ ${enableWelcomeMessage} == true ]]; then
40 | size=${#welcome[@]}
41 | index=$((${RANDOM} % ${size}))
42 | timeStamp=$(date +"%H:%M:%S")
43 | if tail -1 screen.log | grep -q "joined the game"; then
44 | welcomeMessage=${welcome[$index]}
45 | player=$(tail -1 screen.log | grep -oP '.*?(?=joined the game)' | cut -d ' ' -f 4- | sed 's/.$//')
46 | TellrawWelcome "${welcomeMessage}" "${player}" "player ${player} joined at ${timeStamp}"
47 | fi
48 | fi
49 |
50 | Help
51 | ListTasks
52 | ListBackups
53 | if [[ ${enablePerformBackup} == true ]]; then
54 | PerformBackup
55 | fi
56 | if [[ ${enablePerformRestart} == true ]]; then
57 | PerformRestart
58 | fi
59 | if [[ ${enablePerformUpdate} == true ]]; then
60 | PerformUpdate
61 | fi
62 | if [[ ${enablePerformReset} == true ]]; then
63 | PerformReset
64 | fi
65 | fi
66 |
67 | if [[ ${enableBackupsWatchdog} == true ]]; then
68 | if [[ ${counter} -eq 120 ]]; then
69 | source server.settings
70 | timeStamp=$(date +"%H:%M:%S")
71 | lastTimeStamp=$(date -d -"2 minute" +"%H:%M:%S")
72 | if [[ ${worldSizeBytes} -lt $((${lastWorldSizeBytes} - 65536)) ]]; then
73 | Log "warn" "your world-size is getting smaller - this may result in a corrupted world" "${backupLog}"
74 | Log "info" "world-size at ${lastTimeStamp} was ${lastWorldSizeBytes} bytes, world-size at ${timeStamp} is ${worldSizeBytes} bytes" "${backupLog}"
75 | TellrawScript "warn: your world-size is getting smaller - this may result in a corrupted world" "world-size at ${lastTimeStamp} was ${lastWorldSizeBytes} bytes, world-size at ${timeStamp} is ${worldSizeBytes} bytes"
76 | fi
77 | if [[ ${backupSizeBytes} -lt $((${lastBackupSizeBytes} - 65536)) ]]; then
78 | Log "warn" "your backup-size is getting smaller - this may result in corrupted backups" "${backupLog}"
79 | Log "info" "backup-size at ${lastTimeStamp} was ${lastBackupSizeBytes} bytes, backup-size at ${timeStamp} is ${backupSizeBytes} bytes" "${backupLog}"
80 | TellrawScript "warn: your backup-size is getting smaller - this may result in corrupted backups" "backup-size at ${lastTimeStamp} was ${lastBackupSizeBytes} bytes, backup-size at ${timeStamp} is ${backupSizeBytes} bytes"
81 | fi
82 | lastWorldSizeBytes=${worldSizeBytes}
83 | lastBackupSizeBytes=${backupSizeBytes}
84 | counter=0
85 | fi
86 | fi
87 |
88 | lastLineBuffer="${lineBuffer}"
89 | counter=$((counter + 1))
90 | sleep 1s
91 | done
92 |
--------------------------------------------------------------------------------