Introduction
This wiki page will explain how to create a server on a dedicated machine with only a SSH access. It is highly inspired from this post. The server for this tutorial will be a Linux machine and we will only use a SSH access to the machine.
Content
- Creating a new user
- Installing the game
- Starting the server
- with screen
- with an init.d daemon (if you have root)
- with a systemd unit file (if you have root)
Creating a new user
It is always better to run things in a separated account, so we will create one.
adduser <user>
and then log back with SSH as user
or just do a su user
and cd /home/user/
Installing the game
So we will use wget for that, if you don't have it, apt-get install wget
as root will install it on most deb-based distributions.
Then, download the game and unpack it with those commands:
wget -c http://www.smokin-guns.org/downloads/Smokin_Guns_1.1.zip unzip Smokin_Guns_1.1.zip rm Smokin_Guns_1.1.zip mv "Smokin' Guns" sgserver
also, you can do:
cd sgserver mv smokinguns_dedicated.i386 smokinguns_dedicated chmod +x smokinguns_dedicated
As you see, we will run the 32bits binaries. If a problem occurs and you need the 64bits binaries, you may compile them yourself or ask them on the forum. Then you should replace the binaries to the 64bits you got.
Finally, just have a look into the .cfg files into ~/sgserver/smokinguns
in particuliar read server.cfg
.
Starting the server
With screen
Screen is a terminal emulator where you can have some program running even if you aren't logged. It is a really quick solution to start a server. If you don't have it, install screen. To start a server via screen just do type those commands:
screen cd ~/sgserver/ ./smokinguns_dedicated +exec server.cfg +set dedicated "2"
To quit from screen the right way, just do a CTRL-A + D and you can now logout safely. If you want to see it back, just do either:
screen -r
or:
screen -ls screen -r <id>
The id
is the number that identifies the screen session when you displayed them all in the first command.
With an init.d daemon
With this method, the server can now be used like any other daemon, but you need to do some root work for that matter.
So, create a daemon file into /etc/init.d/sgserver.sh
with the following content:
#!/bin/bash ### BEGIN INIT INFO # Provides: sgserver # Required-Start: # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start/stop Smokin'Guns server ### END INIT INFO RULE="su - user -c" BIN="/home/user/sgserver/smokinguns_dedicated +set dedicated 2 +set net_port 27960 +set com_hunkmegs 128 +exec server.cfg >/dev/null 2>&1 &" PROC="smokinguns_dedicated" case "$1" in 'start') $RULE "$BIN" echo "Smokin' Guns server is running..." ;; 'stop') killall $PROC echo "Smokin' Guns server is stopped..." ;; *) echo "Usage: $0 start|stop" ;; esac exit 0
You need then to do:
chmod +x /etc/init.d/sgserver.sh ln -s /etc/init.d/sgserver.sh /usr/local/bin/sgserver
You can now use your server as a daemon like this:
start:
sgserver start
stop:
sgserver stop
With a systemd unit file
It is similar as the previous method, but instead of having a classic BSD-like init system (SysVinit?, Upstart or OpenRC), your linux distribution comes with systemd. One big change is that now, you have the possibility to create a unit file instead of a starting shell script.
For this, you can create a file into /etc/systemd/system/sgserver.service
or /usr/lib/systemd/system/sgserver.service
with this following content:
[Unit] Description=Smokin' Guns dedicated server [Service] User=user # account we created ExecStart=/home/user/sgserver/smokinguns_dedicated +set dedicated 2 +set net_port 27960 +set com_hunkmegs 128 +exec server.cfg Restart=on-abort [Install] WantedBy=multi-user.target
You can now use your server with the commands provided by systemd:
start:
systemctl start sgserver.service
stop:
systemctl stop sgserver.service
If you need more commands, you can have a look at the ArchLinux Wiki page.