This was a response to kiwispike in his thread but it got so long I decided to give it a thread of its own. It's a how to for setting up and running a StarMade server in a RAM drive on a Debian system. You will need a decent chunk of RAM, 8 gigs may suffice for a small server with nothing else running but I recommend your server has at least 16 G available.
Righto, it's been a while since I set this all up so lets see if I can cover everything without missing things.
Firstly! Make a backup of your starmade server folder some where safe before implementing and testing this. It's a process that has the potential to wipe out the server directory if the sync goes wrong somewhere. All care taken, no guarantees given and all that jazz.
I run a Debian server, the SM server is run in a program called screen and you'll also need a program called rsync that handles all the file transfers. Both screen and rsync are available in the repos. On my server the user that runs starmade is also called starmade and the SM server is setup and installed as standard in the users home directory... so /home/starmade/starmade/ through all my scripts. You will either need to setup a starmade user and install the server as I have done or modify the scripts to suit your settings.
In Debian there is a file location /dev/shm/ This is the tempfs mount point and is mounted in/on your RAM.
By default it should have access to 50% of your available system RAM. You can check this with
^That's my current readout with starmade running.
If you want more then 50% of RAM allocated you'll need to edit /etc/fstab, I won't go into the details here but there's lots online on how to achieve that. /dev/shm being RAM is volatile so any power loss or restarts and everything in it is wiped out. What we need to do is setup the SM server so the start script copies the SM server folder from it's default location /home/starmade/starmade to /dev/shm/starmade and then runs the server from there. Then we need to make sure we get regular snapshots from the RAM drive back to the default location just in case of unexpected reboot. To achieve this I have 3 script files in /home/starmade/bin/
RAM_start.sh, RAM_Stop.sh and RAM_save.sh
There is also a cron job running for the save script.
I almost forgot, I have a custom start script in the server folder called start.sh. It is a direct copy of StarMade-dedicated-server-linux.sh with the java settings modified as desired. The reason I have done this, when the server is updated the default StarMade-dedicated-server-linux.sh is reset to non-executable meaning your server won't start. You will need to create the start.sh file and set it to executable as well.
(Be warned, my scripting skills are pretty rough. If anyone wants to chip in with advice on how to improve them I'm all ears. )
This has taken a lot longer then anticipated and it's now quite late for me. I hope I haven't made any critical errors. Next I get a chance I'll add information on how to setup the server as a process using systemd so that the server starts/stops/restarts on it's own.
Righto, it's been a while since I set this all up so lets see if I can cover everything without missing things.
Firstly! Make a backup of your starmade server folder some where safe before implementing and testing this. It's a process that has the potential to wipe out the server directory if the sync goes wrong somewhere. All care taken, no guarantees given and all that jazz.
I run a Debian server, the SM server is run in a program called screen and you'll also need a program called rsync that handles all the file transfers. Both screen and rsync are available in the repos. On my server the user that runs starmade is also called starmade and the SM server is setup and installed as standard in the users home directory... so /home/starmade/starmade/ through all my scripts. You will either need to setup a starmade user and install the server as I have done or modify the scripts to suit your settings.
In Debian there is a file location /dev/shm/ This is the tempfs mount point and is mounted in/on your RAM.
By default it should have access to 50% of your available system RAM. You can check this with
Code:
df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 16G 4.1G 12G 26% /dev/shm
If you want more then 50% of RAM allocated you'll need to edit /etc/fstab, I won't go into the details here but there's lots online on how to achieve that. /dev/shm being RAM is volatile so any power loss or restarts and everything in it is wiped out. What we need to do is setup the SM server so the start script copies the SM server folder from it's default location /home/starmade/starmade to /dev/shm/starmade and then runs the server from there. Then we need to make sure we get regular snapshots from the RAM drive back to the default location just in case of unexpected reboot. To achieve this I have 3 script files in /home/starmade/bin/
RAM_start.sh, RAM_Stop.sh and RAM_save.sh
There is also a cron job running for the save script.
I almost forgot, I have a custom start script in the server folder called start.sh. It is a direct copy of StarMade-dedicated-server-linux.sh with the java settings modified as desired. The reason I have done this, when the server is updated the default StarMade-dedicated-server-linux.sh is reset to non-executable meaning your server won't start. You will need to create the start.sh file and set it to executable as well.
Code:
cd /home/starmade/starmade/
cp StarMade-dedicated-server-linux.sh start.sh && chmod u+x start.sh
I have commented out the MOTD script and the backup script I run every start. They are not essential for the process. If you want to run them as well I'll add those scripts at the end.
Code:
#!/bin/bash
## PERMAMENT = the default location of the SM server folder.
##STARTSCREEN function = starts the SM server inside a screen session called starmade_screen.
VOLATILE=/dev/shm/starmade/
PERMANENT=/home/starmade/starmade/
STARTSCREEN() {
/usr/bin/screen -DmS starmade_screen "$VOLATILE"start.sh
}
## Run message of the day.
#if ! pgrep -x MOTD.sh > /dev/null
# then
# /home/starmade/bin/MOTD.sh &
#fi
## Run Backup
#/home/starmade/bin/backup_starmade_server.sh 2>&1 > /home/starmade/backup_log.txt
##Checks to see if a screen session called starmade_screen is running and abort if true, we don't want to start it twice.
if screen -list | grep -q starmade_screen
then echo StarMade screen running. Aborting!
##Checks if the /dev/shm/starmade (VOLATILE) folder exists, if true it resyncs the default to the volatile.
##ie For after a manual stop of the server and a settings change then restart.
else
if [ -d "$VOLATILE" ];
then
rsync -r -t -v "$PERMANENT" "$VOLATILE"
STARTSCREEN
##If no folder is found in /dev/shm then create the folder and sync, then start the screen session.
else
mkdir -p "$VOLATILE";
rsync -r -t -v "$PERMANENT" "$VOLATILE"
STARTSCREEN
fi
fi
Code:
#!/bin/bash
VOLATILE=/dev/shm/starmade/
PERMANENT=/home/starmade/starmade/
## Send the shutdown 1 command to the SM server running in screen. Wait until the screen is closed and then sync Volatile to Permanent.
/usr/bin/screen -p 0 -S starmade -X eval 'stuff "/shutdown 1"\\015'
until ! screen -list | grep -q starmade_screen > /dev/null
do
sleep 5
done
rsync -r -t -v "$VOLATILE" "$PERMANENT"
##If MOTD script is running kill it also.
if pgrep -x MOTD.sh > /dev/null
then
pkill -x MOTD.sh
fi
The RAM_save.sh script is run through cron. Edit the starmade users cron with 'crontab -e' and add this entry. It will run the RAM_save.sh script every 3 minutes.
The actual RAM_save.sh script.
Code:
*/3 * * * * /home/starmade/bin/RAM_save.sh 2>&1 > /home/starmade/RAM_save_log.txt
Code:
#!/bin/bash
VOLATILE=/dev/shm/starmade/
PERMANENT=/home/starmade/starmade/
## If the VOLATILE file is present and the SM screen session is running then run rsync to save.
if [ -d "$VOLATILE" ] && screen -list | grep -q starmade_screen
then
rsync -r -t -v "$VOLATILE" --delete "$PERMANENT"
echo Backup run "$(date '+%y-%m-%d-%H%M')"
else
echo Backup aborted. Starmade not running.
echo "$(date '+%y-%m-%d-%H%M')"
fi
The good thing about running your SM server in screen is it's easy to send messages and commands to the screen session. Put this MOTD.sh in /home/starmade/bin/ along with the RAM scripts and uncomment the relevant MOTD section in the RAM_start.sh script to have this script run when your server starts.
Code:
#!/bin/bash
##This script repeats indefinitely and every 600 seconds sends a command to the server. You can substitute any command you like.
while true
do
/usr/bin/screen -x -S starmade_screen -X stuff "/server_message_broadcast plain 'Everything is Awesome!'^M"
sleep 600
/usr/bin/screen -x -S starmade_screen -X stuff "/server_message_broadcast plain 'It's cool to be part of the team!'^M"
sleep 600
/usr/bin/screen -x -S starmade_screen -X stuff "/server_message_broadcast info '+12 Mining Faction Space'^M/server_message_broadcast info '+6 Mining Claimed Space'^M/server_message_broadcast info '+3 Mining Unclaimed Space'^M"
sleep 600
done
Again I commented out the backup section in the RAM_start.sh. Uncomment if you want to use this script. You will also need to create the initial backup directories. The script makes 3 backups and needs 4 files. You can create all those files with a single command like
If you want to restore a backup, make sure the server is shutdown and that you are in /home/starmade, then do something like this
^This will restore the SECOND last backup.
Code:
mkdir -p /home/starmade/backups/{starmade,starmade1,starmade2,starmade_tmp}
Code:
rsync -avzh backups/starmade1/ --delete starmade/
Code:
#!/bin/sh
## For a better understanding of this script see http://www.mikerubel.org/computers/rsync_snapshots/
BACKUPS=/home/starmade/backups
mv $BACKUPS/starmade2 $BACKUPS/starmade_tmp
mv $BACKUPS/starmade1 $BACKUPS/starmade2
mv $BACKUPS/starmade $BACKUPS/starmade1
mv $BACKUPS/starmade_tmp $BACKUPS/starmade
rsync -rvt --del --link-dest=$BACKUPS/starmade1 /home/starmade/starmade/ $BACKUPS/starmade
echo Backup run "$(date '+%y-%m-%d-%H%M')"
This has taken a lot longer then anticipated and it's now quite late for me. I hope I haven't made any critical errors. Next I get a chance I'll add information on how to setup the server as a process using systemd so that the server starts/stops/restarts on it's own.