Skip to content

Instantly share code, notes, and snippets.

@Ribesg
Last active December 31, 2015 12:09
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Ribesg/7984114 to your computer and use it in GitHub Desktop.
Save Ribesg/7984114 to your computer and use it in GitHub Desktop.
Here's my server's Starbound related config files and scripts.
alias sb_start="sudo start starbound"
alias sb_stop="sudo stop starbound"
alias sb_restart="sb_stop;sb_start"
alias sb_update="sudo /home/ribesg/sb_update"
alias sb_online="netstat -nt | grep -c 21025"
alias sb_status="sudo status starbound"
#!/bin/bash
###########################
## Default Configuration ##
###########################
# STEAM_USER - The Steam or Starbound unix user, whatever you named it
STEAM_USER="steam"
# STARBOUND_FOLDER - The root starbound folder
# WARNING: THIS SCRIPT ERASE THIS FOLDER - DOUBLE CHECK IT!
STARBOUND_FOLDER="/home/$STEAM_USER/starbound"
# TO_BACKUP_FOLDER - Should contain the folder to backup
# You can use the linuxXX folder or the whole starbound folder, or just the universe folder
TO_BACKUP_FOLDER="/home/$STEAM_USER/starbound/universe"
# DEST_FILE - The destination file for backup
# I use the date in it, but you can do whatever you want
DATE=$(date +%F_%H:%M:%S)
DEST_FILE="/home/$STEAM_USER/backups/universe-$DATE.tar.bzip2"
# STEAM_CMD - Location of the steamcmd.sh script
STEAM_CMD="/home/$STEAM_USER/steamcmd.sh"
# STEAM_LOGIN - Do I need to define what it is
STEAM_LOGIN="YourSteamLogin"
# STEAM_PASSWORD - In the futur we should be able to use anonymous Steam login...
STEAM_PASSWORD="YourSteamPassword"
# SERVER_PASSWORD - The password to apply to the server
# Note: Setting this to empty will apply an empty password, aka no password
SERVER_PASSWORD="YourServerPassword"
#
# Arguments that can be changed by command line
#
# Will be set to true if argument passed is "clean"
CLEAN=false
if [[ "$1" == "clean" || "$2" == "clean" ]]; then
CLEAN=true
echo "Clean set to true"
fi
# Will be set to true if argument passed is "nobackup"
NOBACKUP=false
if [[ "$1" == "nobackup" || "$2" == "nobackup" ]]; then
NOBACKUP=true
echo "Nobackup set to true"
fi
############
## Script ##
############
echo "###############################"
echo "## Updating Starbound Server ##"
echo "###############################"
RESTART=false
# Check server status and shut it down if it's online
echo
echo "1 - Checking server status..."
STATUS=$(sudo initctl status starbound)
echo "Status: $STATUS"
if [[ "$STATUS" =~ ^(.*)start(.*)$ ]]; then
echo "Server is online! Shutting down..."
sudo initctl stop starbound >/dev/null 2>&1
echo "Server shut down!"
RESTART=true
else
echo "Server is offline!"
fi
echo "1 - Done!"
# Backup the whole server, just in case
echo
echo "2 - Make a backup of the $TO_BACKUP_FOLDER folder"
if $NOBACKUP; then
echo "2 - Skipped!"
elif [ ! -d "$TO_BACKUP_FOLDER" ]; then
echo "2 - Not found!"
else
echo "Compressing $(sudo find $TO_BACKUP_FOLDER/* -type f | wc -l) files..."
sudo tar cf - $TO_BACKUP_FOLDER -P | sudo pv -w 80 -s $(sudo du -sb $TO_BACKUP_FOLDER | sudo awk '{print $1}') | sudo bzip2 > $DEST_FILE
sudo chown $STEAM_USER:$STEAM_USER $DEST_FILE
echo "2 - Done!"
fi
# Remove the existing starbound folder
echo
echo "3 - Remove the 'old' starbound folder $STARBOUND_FOLDER"
if $CLEAN; then
echo "Removing..."
sudo rm -rf $STARBOUND_FOLDER
echo "3 - Done!"
else
echo "3 - Skipped!"
fi
# Use SteamCMD to re-download the up-to-date server
echo
echo "4 - Update the server using SteamCMD"
echo "Calling $STEAM_CMD..."
sudo su $STEAM_USER -c "$STEAM_CMD +login $STEAM_LOGIN $STEAM_PASSWORD +force_install_dir $STARBOUND_FOLDER +app_update 211820 validate +quit"
echo "4 - Done!"
# Start the server to generate the config file
echo
echo "5 - Starting server to generate config file"
echo "Starting..."
sudo initctl start starbound >/dev/null 2>&1
echo "Waiting some seconds..."
sleep 1
echo "10..."
sleep 1
echo " 9..."
sleep 1
echo " 8..."
sleep 1
echo " 7..."
sleep 1
echo " 6..."
sleep 1
echo " 5..."
sleep 1
echo " 4..."
sleep 1
echo " 3..."
sleep 1
echo " 2..."
sleep 1
echo " 1..."
sleep 1
echo " 0!"
echo "Shutting down server..."
sudo initctl stop starbound >/dev/null 2>&1
echo "Server shut down!"
# Set password in config
CONFIG_FILE="$STARBOUND_FOLDER/starbound.config"
echo
echo "6 - Setting password in $CONFIG_FILE"
echo "Replacing..."
sudo su $STEAM_USER -c "mv $CONFIG_FILE $CONFIG_FILE.tmp"
sudo su $STEAM_USER -c "cat $CONFIG_FILE.tmp | jq '.serverPasswords = [ \"$SERVER_PASSWORD\" ]' > $CONFIG_FILE"
echo "6 - Done!"
# If the server was on, restart it
if $RESTART; then
echo
echo "7 - The server was online, restart it"
echo "Restarting..."
sudo initctl start starbound >/dev/null 2>&1
echo "7 - Done!"
else
echo
echo "7 - The server was offline, we do not restart it"
fi
echo
echo "######################################"
echo "## Starbound Server update Complete ##"
echo "######################################"
#!upstart
description "Starbound"
# As Steam user
setuid steam
# Start the job
exec '/home/steam/starbound/linux64/starbound_server'
# Start on boot (when Disk + Network OK)
start on filesystem and net-device-up IFACE=lo
# Restart the process if it dies
respawn
# Give up if restart occurs 10 times in 90 seconds
respawn limit 10 90
@Ribesg
Copy link
Author

Ribesg commented Dec 16, 2013

I added ".sh" to all files to force Github to colorize them correctly.

  • .bash_aliases contains some aliases I use as my server's main unix user
  • starbound.conf is an Upstart script that will handle the server's status and ease the start/stop/restart processes
  • sb_update is a script I made to update my Starbound server. It allows:
    • Automatically stops the server if needed
    • Make a backup of a predefined folder (in this case the universe folder), unless you call it with the argument "nobackup"
    • Remove the starbound folder if the argument "clean" is passed (good for clean reinstall)
    • Launch SteamCMD to re-download the game
    • Modify the "assets/default_configuration.config" file to set the server's password
    • Restart the server if it was online when the script was launched

Full list of required commands: date, sudo, initctl (Upstart), find, wc, tar, pv, du, awk, bzip2, chown, rm, su, mv, cat, jq (http://stedolan.github.io/jq/).

Please comment here for additional informations.

@Ribesg
Copy link
Author

Ribesg commented Jan 26, 2014

Updated for v. Furious Koala

@mpern
Copy link

mpern commented May 3, 2014

thanks for the great update script!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment