LHammonds Posted January 18, 2016 Share Posted January 18, 2016 (edited) 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: 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: #!/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: ######################################## # 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 Edited May 9, 2017 by LHammonds (see edit history) Link to comment Share on other sites More sharing options...
mudfly Posted January 23, 2016 Share Posted January 23, 2016 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. Link to comment Share on other sites More sharing options...
iLLNESS Posted January 24, 2016 Share Posted January 24, 2016 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: 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: #!/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: ######################################## # 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? Link to comment Share on other sites More sharing options...
LHammonds Posted January 25, 2016 Share Posted January 25, 2016 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 Link to comment Share on other sites More sharing options...
Alloc Posted January 28, 2016 Author Share Posted January 28, 2016 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 Link to comment Share on other sites More sharing options...
mudfly Posted January 30, 2016 Share Posted January 30, 2016 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 Link to comment Share on other sites More sharing options...
blotavious Posted January 31, 2016 Share Posted January 31, 2016 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': 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! Link to comment Share on other sites More sharing options...
Alloc Posted January 31, 2016 Author Share Posted January 31, 2016 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 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. Link to comment Share on other sites More sharing options...
Devidian Posted February 1, 2016 Share Posted February 1, 2016 Hey Alloc, are there any plans adding different icons for different animals/zombies on the map ? Greetings, Devidian Link to comment Share on other sites More sharing options...
blotavious Posted February 1, 2016 Share Posted February 1, 2016 +1 for BSD, though Apache is good too. Please no GPL nonsense. Link to comment Share on other sites More sharing options...
Alloc Posted February 1, 2016 Author Share Posted February 1, 2016 are there any plans adding different icons for different animals/zombies on the map ? So far no. I'm far from being a designer or anything like that so I have to search for fitting icons (both in terms of content as well as licensing) or it will end up ugly as hell Also: Wrong thread. +1 for BSD, though Apache is good too. Please no GPL nonsense. Heh, just because you wanna use it for your own commercial product, right? ;P j/k, for this stuff GPL just doesn't make any sense to me either. Link to comment Share on other sites More sharing options...
Devidian Posted February 2, 2016 Share Posted February 2, 2016 So far no. I'm far from being a designer or anything like that so I have to search for fitting icons (both in terms of content as well as licensing) or it will end up ugly as hell Also: Wrong thread. Whops, sorry had multiple tabs open Ok well, then i'll try myself editing this when i get some free time. Link to comment Share on other sites More sharing options...
mudfly Posted February 5, 2016 Share Posted February 5, 2016 Heh, just because you wanna use it for your own commercial product, right? ;P j/k, for this stuff GPL just doesn't make any sense to me either. For what it's worth, I was the one originally asking about the license, and I have better things to do then rip off code and make a commercial product. I had this idea because I play 7dtd, I run a 7dtd server for a few friends and myself to play on, and I am learning Docker for work. I love GPL software, but I agree for something like this, a more permissive license is better. I was planning on releasing under a permissive license such as BSD, Apache, or MIT as I stated earlier. At this point, I am not sure how much code of yours I will actually use. I was interested in your map renderer, but this would have to run in a separate container than the game server, and I haven't reviewed your code to see how to make this is possible. I see a few potential challenges with 7dtd in docker. SteamCMD should be easy enough to install at runtime, but the 7dtd server requires you to authenticate to download. Docker is meant to be immutable, and non-interactive, with configuration done through runtime options. I can get around the login by using expect, but it feels like a bit of a hack. Maybe I can convince TFP to allow anonymous installs like many other games. https://developer.valvesoftware.com/wiki/Dedicated_Servers_List Perhaps I am just wasting everyones time Cheers, Mudfly Link to comment Share on other sites More sharing options...
SylenThunder Posted February 5, 2016 Share Posted February 5, 2016 The server used to allow anonymous installs, but they stopped that. Could you just have it call stored data and use that for the authentication like Allocs updateengine script does? Link to comment Share on other sites More sharing options...
Alloc Posted February 6, 2016 Author Share Posted February 6, 2016 For what it's worth, I was the one originally asking about the license, and I have better things to do then rip off code and make a commercial product. I had this idea because I play 7dtd, I run a 7dtd server for a few friends and myself to play on, and I am learning Docker for work. Really no offense meant by my previous comment, as I said I never intended to make it not usable for commercial means. No reason to do so for a few little scripts I love GPL software, but I agree for something like this, a more permissive license is better. I was planning on releasing under a permissive license such as BSD, Apache, or MIT as I stated earlier. Any preference between those? At this point, I am not sure how much code of yours I will actually use. I was interested in your map renderer, but this would have to run in a separate container than the game server, and I haven't reviewed your code to see how to make this is possible. The renderer has nothing to do with the scripts at all, it's just a mod for the server. No idea to what extend that makes any difference for you / docker though Maybe I can convince TFP to allow anonymous installs like many other games. We definitely plan to allow anon access at some point, but that might not happen until we finally have the time to make the dedi build really dedi only (unlike now where it basically is almost exactly like the client build). Could be sooner, could be later ... really no definitive timeframe currently. The server used to allow anonymous installs, but they stopped that. Could you just have it call stored data and use that for the authentication like Allocs updateengine script does? We never had it for anon access ... at least not within at least the past 1.5 years (think even longer ... not sure when I first looked into the Linux dedi stuff) Link to comment Share on other sites More sharing options...
mudfly Posted February 6, 2016 Share Posted February 6, 2016 Really no offense meant by my previous comment, as I said I never intended to make it not usable for commercial means. No reason to do so for a few little scripts No offence was taken, I just wanted to avoid any confusion since Blotavious chimed in on license preferences. Any preference between those? The MIT license is the most straight forward as can be seen here. The Simplified BSD license is also just about as straight forward as MIT as can be seen here. The Apache license covers things like patents, which does not seam applicable in this situation. The GPLv3 is useful if you want people who improve your script to contribute back to your project. You may want to scan through this page that is run by github to help users on their platform pick a license. http://choosealicense.com/licenses/. The renderer has nothing to do with the scripts at all, it's just a mod for the server. No idea to what extend that makes any difference for you / docker though I was hoping that I would be able to run the website that hosts the map in a separate container than the server. This is not my main priority however, so at this time I am only trying to get the 7dtd dedicated server running in docker. I appreciate you taking time to consider my request. Link to comment Share on other sites More sharing options...
Alloc Posted February 8, 2016 Author Share Posted February 8, 2016 We definitely plan to allow anon access at some point, but that might not happen until we finally have the time to make the dedi build really dedi only (unlike now where it basically is almost exactly like the client build). Could be sooner, could be later ... really no definitive timeframe currently. Seems like I got that through sooner than I expected You may want to scan through this page that is run by github to help users on their platform pick a license. http://choosealicense.com/licenses/. Seems like a useful page, thank you 1 Link to comment Share on other sites More sharing options...
blotavious Posted February 8, 2016 Share Posted February 8, 2016 Seems like I got that through sooner than I expected Do I understand correctly that you removed/disabled the client code, so A14 will have a "real" dedicated server? If so that is awesome! I hope the server will run with greatly reduced memory requirements as a result. Link to comment Share on other sites More sharing options...
Alloc Posted February 9, 2016 Author Share Posted February 9, 2016 Do I understand correctly that you removed/disabled the client code, so A14 will have a "real" dedicated server? If so that is awesome! I hope the server will run with greatly reduced memory requirements as a result. Ah, no, sorry for the confusion, was just talking about the anon download Also, the server was running as real dedicated. Code wise there is almost nothing that shouldn't be running on the server, you won't see a big performance improvement on that end. Only generic improvements will affect that. Memory ... maybe a bit but I wouldn't expect more than like maybe a few hundred MB if at all. It's not like the server was loading the full set of textures or anything. Link to comment Share on other sites More sharing options...
blotavious Posted February 9, 2016 Share Posted February 9, 2016 Also, the server was running as real dedicated. Code wise there is almost nothing that shouldn't be running on the server, you won't see a big performance improvement on that end. Only generic improvements will affect that. Memory ... maybe a bit but I wouldn't expect more than like maybe a few hundred MB if at all. It's not like the server was loading the full set of textures or anything. Darn. 4GB addressable RAM for the 32bit Linux client is proving to be constraining. If Unity/Steam would fix whatever the 64bit issue is then I'd be very happy. The 64bit server seems to work fine except such a server won't show up in the browser list...it seems like such a small thing :-| Link to comment Share on other sites More sharing options...
Alloc Posted February 16, 2016 Author Share Posted February 16, 2016 Scripts are Apache 2.0 now, mod will follow later on. Link to comment Share on other sites More sharing options...
mudfly Posted February 18, 2016 Share Posted February 18, 2016 Seems like I got that through sooner than I expected So you got in a feature request, or this is in the works? Being able to install the server using an anonymous account will simplify my docker project, as well as your scripts. Scripts are Apache 2.0 now, mod will follow later on. Nice work! Link to comment Share on other sites More sharing options...
SylenThunder Posted February 18, 2016 Share Posted February 18, 2016 Darn. 4GB addressable RAM for the 32bit Linux client is proving to be constraining. If Unity/Steam would fix whatever the 64bit issue is then I'd be very happy. The 64bit server seems to work fine except such a server won't show up in the browser list...it seems like such a small thing :-| Odd. Mine does. Although sometimes it doesn't, but I think that was my ISP. Link to comment Share on other sites More sharing options...
Alloc Posted February 18, 2016 Author Share Posted February 18, 2016 So you got in a feature request, or this is in the works? Neither nor. It's anon downloadable since two days ago Odd. Mine does. Although sometimes it doesn't, but I think that was my ISP. The 64 bit server shows in the browser? Can you post the log of your server? (First ~1k lines should be enough). Link to comment Share on other sites More sharing options...
SylenThunder Posted February 18, 2016 Share Posted February 18, 2016 Sure thing. It didn't show in the list previously, but sometime after probably 13.5 it has. I restarted the server so you'll have a fresher log. http://pastebin.com/a3EL3qZ9 Here's a shot of the server list. It's the very first one Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now