Native Linux server (with management scripts)

@Thoron, Are you running the server manually or are you using the the startserver.sh script? If you are running it manually try adding this to the parameters (like in the startserver.sh):


Once I did that I started getting the same errors as these guys.
These shouldn't have any impact if running the Linux dedicated build. "quit" never should make any difference, "batchmode" and "nographics" are only for clients being run as dedicated (also required for Windows dedicated), "dedicated" always only required for clients run as dedicated.

Also, continuing this over there as it's not relevant for the scripts: https://7daystodie.com/forums/showthread.php?34299-A13-Dedicated-Server-Linux-Bugs

 
Alloc, Great work man I'm really loving the scripts after a week or so of use. It's made running a server very streamlined!

I had checked around for a way to auto reboot the server and most implementations are windows based client programs.

I notice there is a ticket you previously created for this kind of feature https://7dtd.illy.bz/ticket/15

I was wondering if this is still being planned on implementation? Ideally it would be nice if it:

- Run script at specified time/interval (interval could be bash)

- Check if users online

- If users online, say countdown to server restart while monitoring if users connected.

- If no users online or prior to that final time there are no users, initiate restart.

 
Saw this thread and just wanted to say thanks for the scripts...been using them for a long time.

iLLNESS, if there is a way to issue a "say" command from the console, we could use crontab to schedule the in-game notifications, then issue the shutdown and then reboot. I've been wanting to implement automated reboots like this but haven't had the time to research...been just doing it manually whenever there is an update. My guess it will be Telnet commands like Alloc uses in 7dtd.sh

 
Last edited by a moderator:
Thanks, glad it's of help for you guys :)

I had checked around for a way to auto reboot the server and most implementations are windows based client programs.
I notice there is a ticket you previously created for this kind of feature https://7dtd.illy.bz/ticket/15

I was wondering if this is still being planned on implementation? Ideally it would be nice if it:

- Run script at specified time/interval (interval could be bash)

- Check if users online

- If users online, say countdown to server restart while monitoring if users connected.

- If no users online or prior to that final time there are no users, initiate restart.

iLLNESS, if there is a way to issue a "say" command from the console, we could use crontab to schedule the in-game notifications, then issue the shutdown and then reboot. I've been wanting to implement automated reboots like this but haven't had the time to research...been just doing it manually whenever there is an update. My guess it will be Telnet commands like Alloc uses in 7dtd.sh
As LHammonds says: It's basically all possible already with bash scripting. Sending messages to the server is easily done with a single call to the scripts, an example can be found in the join-server hook example on the wiki.

Of course this would all have to be tied together to form a solution for announcing the restart (if people are online) with optional countdown and then stop/restart the server.

Not really top on my list though right now ;)

 
I have written a bunch of scripts for 7D2D in Ruby. The Pastebin URLs below point to a couple of these.

http://pastebin.com/eH2qHV1B - A Ruby class to send messages to a 7D2D console connection (telnet)

http://pastebin.com/H613LHtA - A Ruby script that uses the class above

To use these, copy them both into a directory...call the class file something like "sdtdsay-class.rb" and the script whatever you want, like "send-command.rb." Make the "send-command.rb" file executable: "chmod 755 send-command.rb"

Change the script to use your server's settings (IP, port number, password).

Then you can use the script like this:

Code:
./send-command.rb -c listplayers
./send-command.rb -c "admin add someuser 0"
./send-command.rb -c 'say "blotavious is awesome"'
./send-command.rb -c 'say "_GREEN_blotavious_NOCOLOR_ is awesome"'
 
Last edited by a moderator:
Sending messages to the server is easily done with a single call to the scripts, an example can be found in the join-server hook example on the wiki.
I tried the following Bash script:

Code:
#!/bin/bash
. /usr/local/lib/7dtd/common.sh
telnetCommand MehServerName "say hello world I love you"
It will send "hello" to the server and I can see it in-game but I cannot get it to send anything after the 1st word.

Here is the output of the command (ports and names changed to protect the innocent):

Code:
*** Connected with 7DTD server.
*** Server version: Alpha 13.6 (b2) Compatibility Version: Alpha 13.6
*** Dedicated server only build

Server IP:   Any
Server port: 69696
Max players: 16
Game mode:   GameModeSurvivalMP
World:       Random Gen
Game name:   MehServerName
Difficulty:  2

Press 'help' to get a list of all commands. Press 'exit' to end session.

2016-01-14T20:24:14 524423.749 INF Executing command 'say hello world I love you' by Telnet from 127.0.0.1:44444
2016-01-14T20:24:14 524423.750 INF GMSG: Server: hello
Am I doing something silly or does it not accept anything more than a single word?

Thanks,

LHammonds

 
Nevermind, I figured it out. Needed multiple-enclosed quotes.

Code:
#!/bin/bash
. /usr/local/lib/7dtd/common.sh
telnetCommand MehServerName 'say "hello world I love you"'
I'd recommend updating the example here with this info with use of more than 1 word.

 
LHammonds Not sure if it will work, but try double quoting the message.

Code:
"say \"Hello, World!\""
 
Last edited by a moderator:
Yeah, sorry, forgot to update those :(

Double quoting as mudfly showed is right. Quoting the command with single quotes as LHammonds did should work too but AFAIR shell variables don't get expanded in those (might be wrong on this one though ;) ).

 
When I around to configuring my server for automated messages via crontab, I'll post what I have done here so others can see (as well as my own forums). I plan to make a how-to article some day on how to setup a 7dtd server and Alloc is integral to that process. Again, can't thank you enough for what you've done.

 
Ok, here is a shutdown script which I tested on Ubuntu Server 14.04 and 16.04 LTS but should work for most other flavors of Linux since it uses Bash.

EDIT: Yes, the same thing can be done with just a few lines of code but I like to standardize my scripts and make them re-usable as well as make it where as little needs to be changed in the script as practical.

Create a file such as sdtd-shutdown.sh and set permissions on it:

Code:
mkdir -p /var/scripts/prod
touch /var/scripts/prod/sdtd-shutdown.sh
chown root:root /var/scripts/prod/sdtd-shutdown.sh
chmod 755 /var/scripts/prod/sdtd-shutdown.sh
Add the following text to the script:

Code:
#!/bin/bash
#############################################
## Name          : sdtd-shutdown.sh
## Version       : 1.0
## Date          : 2016-01-18
## Author        : LHammonds
## Purpose       : Warn players and shutdown game.
## Compatibility : Verified on Ubuntu Server 14.04 thru 16.04 LTS
## Requirements  : Must be run as root.
## Parameters    : #1 = 7dtd server instance name (required)
## Run Frequency : Can run as often as needed.
## Exit Codes    : None
################ CHANGE LOG #################
## DATE       WHO WHAT WAS CHANGED
## ---------- --- ----------------------------
## 2016-01-18 LTH Created script.
#############################################

## Import standard variables and functions. ##
. /usr/local/lib/7dtd/common.sh

LogFile="/var/log/sdtd-shutdown.log"

## Requirement Check: Script must run as root user.
if [ "$(id -u)" != "0" ]; then
 ## FATAL ERROR DETECTED: Document problem and terminate script.
 echo -e "\nERROR: Root user required to run this script.\n"
 echo -e "Type 'sudo su' to temporarily become root user.\n"
 exit
fi

## Check parameter.
if [ "${1}" == "" ]; then
 echo -e "[ERROR] Missing required parameter. Enter the server instance."
 echo -e "Syntax: ${ScriptName} [serverInstance]"
 echo -e "Example 1: ${ScriptName} alpha13"
 echo -e "Example 2: ${ScriptName} hamcraft"
 echo -e "Here is a list of valid instances:"
 7dtd.sh instances list
 exit 1
else
 InstanceName="${1}"
fi

telnetCommand ${InstanceName} "say \"Server shutdown in 1 minute\""
sleep 30
telnetCommand ${InstanceName} "say \"Server shutdown in 30 seconds\""
sleep 20
telnetCommand ${InstanceName} "say \"Server shutdown in 10 seconds\""
sleep 7
telnetCommand ${InstanceName} "say \"Server shutdown in 3 seconds\""
sleep 1
telnetCommand ${InstanceName} "say \"Server shutdown in 2 seconds\""
sleep 1
telnetCommand ${InstanceName} "say \"Server shutdown in 1 second\""
sleep 1
telnetCommand ${InstanceName} "say \"Be right back!\""
sleep 1
telnetCommand ${InstanceName} "shutdown"
echo "`date +%Y-%m-%d_%H:%M:%S` - [iNFO] Shutting down ${InstanceName} instance." | tee -a ${LogFile}
You can then schedule it in the root account (accessible by doing "sudo su" from your admin account) and then type "crontab -e"

Example crontab schedule:

Code:
########################################
# Name: Crontab Schedule for root user
# Author: LHammonds
############# Update Log ###############
# 2016-01-18 - LTH - Created schedule
########################################
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# Crontab SYNTAX:
# minute(0-59) hour(0-23) day-of-month(1-31) month(1-12) day-of-week(0-6) command-to-execute
#
# Adjust the time clock
#
0 1-23 * * * /usr/sbin/ntpdate ntp.ubuntu.com > /dev/null 2>&1
#
# 7dtd: Shutdown 7dtd instances for daily reboot:
#
0 3 * * * /var/scripts/prod/sdtd-shutdown.sh HamCraft > /dev/null 2>&1
0 3 * * * /var/scripts/prod/sdtd-shutdown.sh WalkingDead > /dev/null 2>&1
0 3 * * * /var/scripts/prod/sdtd-shutdown.sh Vanilla > /dev/null 2>&1
2 3 * * * /var/scripts/prod/reboot.sh
Summary of what it is doing:

The schedule is configured to run the script 3 times simultaneously at 3:00am to shutdown 3 instances of servers called "HamCraft", "WalkingDead" and "Vanilla"

The shutdown of the 7dtd instances should take just a little over 1 minute so a server-wide reboot script is scheduled to go off at 3:02am

While connected to one of the servers during this period, players will get a notice that the server will be shutdown in 1 minute. Then get another notice 30 seconds later, etc. and eventually get disconnected automatically when the instance is shutdown.

LHammonds

 
Last edited by a moderator:
Alloc,

I have this crazy idea to try to get 7 days to die linux dedicated server running in docker, I am not sure how much code will have to be written from scratch, or if I will leverage some of your source code to achieve this. I am just starting to explore this idea. I am curious what license you distribute your code under. I checked the repositories you are hosting in Trac and I do not see any license or copyright information. The source I write will be distributed on github, with the docker image hosted at dockerhub.com and released under a permissive license such as MIT, BSD, or Apache. Since I don't have permission to license your work, if I were to use any of it, I am just asking for clarification.

I am also open to the idea of collaborating on this with you, if this is something you may be interested in.

 
Ok, here is a shutdown script which I tested on Ubuntu Server 14.04 LTS but should work for most other flavors of Linux since it uses Bash.
EDIT: Yes, the same thing can be done with just a few lines of code but I like to standardize my scripts and make them re-usable as well as make it where as little needs to be changed in the script as practical.

Create a file such as 7dtd-shutdown.sh and set permissions on it:

Code:
mkdir -p /var/scripts
touch /var/scripts/7dtd-shutdown.sh
chown root:root /var/scripts/7dtd-shutdown.sh
chmod 755 /var/scripts/7dtd-shutdown.sh
Add the following text to the script:

Code:
#!/bin/bash
#############################################
## Name          : 7dtd-shutdown.sh
## Version       : 1.0
## Date          : 2016-01-18
## Author        : LHammonds
## Purpose       : Warn players and shutdown game.
## Compatibility : Verified on Ubuntu Server 14.04 LTS
## Requirements  : Must be run as root.
## Parameters    : #1 = 7dtd server instance name (required)
## Run Frequency : Can run as often as needed.
## Exit Codes    : None
################ CHANGE LOG #################
## DATE       WHO WHAT WAS CHANGED
## ---------- --- ----------------------------
## 2016-01-18 LTH Created script.
#############################################

## Import standard variables and functions. ##
. /usr/local/lib/7dtd/common.sh

LogFile="/var/log/7dtd-shutdown.log"

## Requirement Check: Script must run as root user.
if [ "$(id -u)" != "0" ]; then
 ## FATAL ERROR DETECTED: Document problem and terminate script.
 echo -e "\nERROR: Root user required to run this script.\n"
 echo -e "Type 'sudo su' to temporarily become root user.\n"
 exit
fi

## Check parameter.
if [ "${1}" == "" ]; then
 echo -e "[ERROR] Missing required parameter. Enter the server instance."
 echo -e "Syntax: ${ScriptName} [serverInstance]"
 echo -e "Example 1: ${ScriptName} alpha13"
 echo -e "Example 2: ${ScriptName} hamcraft"
 echo -e "Here is a list of valid instances:"
 7dtd.sh instances list
 exit 1
else
 InstanceName="${1}"
fi

telnetCommand ${InstanceName} "say \"Server shutdown in 1 minute\""
sleep 30
telnetCommand ${InstanceName} "say \"Server shutdown in 30 seconds\""
sleep 20
telnetCommand ${InstanceName} "say \"Server shutdown in 10 seconds\""
sleep 7
telnetCommand ${InstanceName} "say \"Server shutdown in 3 seconds\""
sleep 1
telnetCommand ${InstanceName} "say \"Server shutdown in 2 seconds\""
sleep 1
telnetCommand ${InstanceName} "say \"Server shutdown in 1 second\""
sleep 1
telnetCommand ${InstanceName} "say \"Be right back!\""
sleep 1
telnetCommand ${InstanceName} "shutdown"
echo "`date +%Y-%m-%d_%H:%M:%S` - [iNFO] Shutting down ${InstanceName} instance." | tee -a ${LogFile}
You can then schedule it in the root account (accessible by doing "sudo su" from your admin account) and then type "crontab -e"

Example crontab schedule:

Code:
########################################
# Name: Crontab Schedule for root user
# Author: LHammonds
############# Update Log ###############
# 2016-01-18 - LTH - Created schedule
########################################
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# Crontab SYNTAX:
# minute(0-59) hour(0-23) day-of-month(1-31) month(1-12) day-of-week(0-6) command-to-execute
#
# Adjust the time clock
#
0 1-23 * * * /usr/sbin/ntpdate ntp.ubuntu.com > /dev/null 2>&1
#
# Shutdown 7dtd instances for daily reboot:
#
0 3 * * * /var/scripts/7dtd-shutdown.sh HamCraft > /dev/null 2>&1
0 3 * * * /var/scripts/7dtd-shutdown.sh WalkingDead > /dev/null 2>&1
0 3 * * * /var/scripts/7dtd-shutdown.sh Vanilla > /dev/null 2>&1
2 3 * * * /var/scripts/reboot.sh
Summary of what it is doing:

The schedule is configured to run the script 3 times simultaneously at 3:00am to shutdown 3 instances of servers called "HamCraft", "WalkingDead" and "Vanilla"

The shutdown of the 7dtd instances should take just a little over 1 minute so a server-wide reboot script is scheduled to go off at 3:02am

While connected to one of the servers during this period, players will get a notice that the server will be shutdown in 1 minute. Then get another notice 30 seconds later, etc. and eventually get disconnected automatically when the instance is shutdown.

LHammonds
Nice! Just what I'm looking for.

is your reboot script for the computer? or is it to fire up your instances?

 
Nice! Just what I'm looking for.
is your reboot script for the computer? or is it to fire up your instances?
This particular script just handles shutting down the 7dtd instances that are running.

If you look at the example crontab schedule, you can see the 7dtd-shutdown script is being called 3 times which is shutting down 3 instances that are running. Once the instances are down, you call a server reboot script like the crontab shows (reboot.sh).

If you only maintain a single instance, you could incorporate the server reboot into the 7dtd-shutdown script. Once you know the instance is down, simply reboot the server at the end of the script.

There's a bunch of ways you can handle it. My script was focusing primarily on the shutdown of the 7dtd instance only.

If you want more information on the setup of Ubuntu Server or automation scripts, you can find what I have done on my forum.

LHammonds

 
Ok, here is a shutdown script which I tested on Ubuntu Server 14.04 LTS but should work for most other flavors of Linux since it uses Bash....

LHammonds
Nice job :)

Thanks for sharing, I'm quite sure a lot of people will find this post helpful.

I have this crazy idea to try to get 7 days to die linux dedicated server running in docker, I am not sure how much code will have to be written from scratch, or if I will leverage some of your source code to achieve this. I am just starting to explore this idea. I am curious what license you distribute your code under. I checked the repositories you are hosting in Trac and I do not see any license or copyright information. The source I write will be distributed on github, with the docker image hosted at dockerhub.com and released under a permissive license such as MIT, BSD, or Apache. Since I don't have permission to license your work, if I were to use any of it, I am just asking for clarification.
I am also open to the idea of collaborating on this with you, if this is something you may be interested in.
Code reuse: No idea, never worked with Docker so far so I don't know how much will be applicable there.

Regarding the license: I haven't set any as I never know what I should choose ;) Feel free to use anything of what I wrote however you want, it's meant to be there for others to enhance it if they want. If you have any explicit suggestion on what license I should put on the stuff (so there's no worries about it not stating any license) feel free to PM me.

Regards,

Chris

 
Alloc,

That is pretty awesome of you to share your code, deciding on a license is hard. The main reason I would feel better with you applying a license, or even just author information is to give you credit for your work.

Based on your attitude I picked a license for you! Of course it is meant to be tounge-in-cheek, but perhaps maybe it is appropriate ;)

http://www.wtfpl.net/

I am still learning docker, and getting something like 7dtd running inside docker is going to be a big challenge. I will keep you posted on my progress.

Cheers!

Mudfly

 
Are other Linux dedicated servers still having issues with RAM usage? The Linux server is way improved compared to the initial release of A13, but the 32-bit version still attempts to over-allocate RAM beyond its 4GB limit. When the over-allocation happens the server crashes of course.

I have worked around this to an extent with a script that monitors the "virtmem" process variable. When the server virtmem exceeds a threshold the script gives the users a 2 minute countdown in chat and then does a controlled stop and start.

You can see "virtmem" in 'top':

Code:
 PID USER      PR  NI    [b]VIRT[/b]    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                               
10558 sdtd      20   0 [b]2918760[/b] 2.220g  23276 R 170.5  9.5  48:23.66 7DaysToDieServer
RAM usage seems to depend on some combination of the number of users, the amount of new map being discovered and perhaps user exits/user joins. My server stays up anywhere between a couple hours and over 24 hours. In A12 my server stayed up for days without issue.

I'd *love* to use the 64-bit version but it won't show up in the server browser. Otherwise it seems to work OK.

Alloc: is the Linux server getting any love in the A14 optimization release? If you want a guinea pig to help profile I certainly volunteer!

 
Based on your attitude I picked a license for you! Of course it is meant to be tounge-in-cheek, but perhaps maybe it is appropriate ;)
http://www.wtfpl.net/
Heh, interesting one :D

More likely gonna go with Apache or BSD though ;)

Alloc: is the Linux server getting any love in the A14 optimization release? If you want a guinea pig to help profile I certainly volunteer!
There's no Linux specific code and thus optimizations (or for that matter for any of the platforms). So whatever is optimized will affect each of the platforms.

 
Hey Alloc,

are there any plans adding different icons for different animals/zombies on the map ?

Greetings,

Devidian

 
Back
Top