Azelphur's scripts/snippets for Linux Dedi/VDS

This is used for general discussion that is not necessarily server-related.
Post Reply
azelphur
New to forums
New to forums
Posts: 4
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
Joined: Mon Apr 09, 2012 6:21 pm

Azelphur's scripts/snippets for Linux Dedi/VDS

Post by azelphur »

I have a few scripts I've written to help me run my server, I figured I'd put them on github and share them with everyone! :)

Before installing pretty much any of these, you probably want to set crontab to email you. You can do this by running "crontab -e" and adding this line to the top of the file
MAILTO="your@address.com"

Backup MySQL

This script takes incremental backups of MySQL.

Features:
  • Saves backups by date
    Backup as often as you want
    Automatically finds all your databases
    Backs up each table individually for minimal table locking time and small easy to work with backups
    Compresses the backups so they use minimal space
    Uses low priority cpu and io scheduling so that backups operations shouldn't slow down your server
How to install:
1) Run these commands:
  • git clone git://github.com/Azelphur/backup_mysql.git
    cd backup_mysql
    nano backup_mysql.sh
2) Edit the first few lines of backup_mysql.sh (USER, PASS and STORAGE).

3) Run the script manually to ensure everything is working by typing "./backup_mysql.sh" it should tell you about which backups it's performing, and then tell you that the backup is complete.

3) Add the script to your crontab to have it automatically run daily, type "crontab -e" and add "00 00 * * * /path/to/backup_mysql.sh" at the bottom.


srcds-detect-freeze

This script will detect if srcds (So CS:S, TF2, L4D(2), etc) has frozen by sending it A2S_INFO queries and restart it automatically if it is not responding.

Features:
  • Supports multiple game servers
    Custom start and stop commands per server
    Ability to use TwistedCat to let you know when a server has frozen.
    Runs from a cron job, so totally custom server check intervals
Install:
1) Run these commands:
  • git clone git://github.com/Azelphur/srcds-detect-freeze.git
    cd srcds-detect-freeze
    git clone git://github.com/frostschutz/SourceLib.git
    nano srcds-detect-freeze.py
2) Edit the servers information at the top of the file to reflect your servers IP/hostnames and start/stop commands

3) Add the script to your crontab to have it automatically run every 5 minutes, type "crontab -e" and add "*/5 * * * * python /path/to/srcds-detect-freeze.py" at the bottom.


TwistedCat
TwistedCat allows you to easily send notifications to IRC and/or XMPP (Google talk, Android phones) via netcat. This works really well with nemrun, as you can get a notification to your phone when your server is updating. It also works in combination with srcds-detect-freeze to notify you when a server is frozen or SourceMod is broken.

You can get it from https://github.com/Azelphur/TwistedCat there are instructions in the readme at the bottom.

To make nemrun notify you when an update is available, run the updater daemon with something like -notifycmd "echo Server is downloading an update | twistedcat"

Rate limit a webserver
Although this isn't usually an issue, If you host sv_downloadurl or mirror large files on the same server as your game servers you may want to rate limit it so that if a client with a very fast internet connection downloads large files from your webserver, it doesn't lag the game servers. Here is a snippet that will rate limit port 80 to 500mbit/sec.

Code: Select all

dev="eth1"
tc -s qdisc del dev $dev root
iptables -t mangle -v -D OUTPUT 1
tc qdisc add dev $dev root handle 1: htb
tc class add dev $dev parent 1:1 classid 1:5 htb rate 500mbit ceil 500mbit prio 1
tc filter add dev $dev parent 1:0 prio 1 protocol ip handle 5 fw flowid 1:5
iptables -A OUTPUT -t mangle -p tcp --sport 80 -j MARK --set-mark 5
Hope this stuff is useful to some people, feel free to ask me questions on the IRC channel. Enjoy :)
User avatar
Edge100x
Founder
Founder
Posts: 13120
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Re: Azelphur's scripts/snippets for Linux Dedi/VDS

Post by Edge100x »

Thanks for posting these for the community, Azelphur! I should probably move this over to the dedi forum.

For Apache, another effective way to limit speeds, down to the per-vhost and per-file level, is the mod_bw module. In your example with "tc", you could simplify to remove the iptables line by replacing this:

tc filter add dev $dev parent 1:0 prio 1 protocol ip handle 5 fw flowid 1:5

With this:

tc filter add dev $dev parent 1:0 protocol ip u32 match ip sport 80 0xffff flowid 1:5
azelphur
New to forums
New to forums
Posts: 4
Joined: Mon Apr 09, 2012 6:21 pm

Re: Azelphur's scripts/snippets for Linux Dedi/VDS

Post by azelphur »

Edge100x wrote:Thanks for posting these for the community, Azelphur! I should probably move this over to the dedi forum.

For Apache, another effective way to limit speeds, down to the per-vhost and per-file level, is the mod_bw module. In your example with "tc", you could simplify to remove the iptables line by replacing this:

tc filter add dev $dev parent 1:0 prio 1 protocol ip handle 5 fw flowid 1:5

With this:

tc filter add dev $dev parent 1:0 protocol ip u32 match ip sport 80 0xffff flowid 1:5
Yea, mod_bw is good if you use apache, I use nginx myself and it doesn't have any rate limiting modules (and they have no intention of implementing it due to nginx's worker architecture)

Nice improvement to the tc, I'll have to test that out. :)
Post Reply