Created
February 10, 2022 19:25
-
-
Save StarterX4/cf14338605d93d44cf369d4973145737 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# replace "steam" with the user you created, leave it alone if you've actually called your user "steam" | |
S_USER="steam" | |
# Do not change this path | |
PATH=/bin:/usr/bin:/sbin:/usr/sbin | |
# The path to the home folder, only change this if you have a different installation path than in the guide. | |
DIR=/home/steam | |
DAEMON="/bin/docker-compose" | |
############################################# PARAMETERS & SERVER.CFG ############################################### | |
# | |
# SVNUM will come in handy for when you're hosting multiple Servers on the same Dedicated Machine. | |
# Replace "1.3.3.7" with your Dedicated's Server IP. | |
# Replace 2456 with the Port this Valheim Server will be hosted on. | |
##################################################################################################################### | |
SVNUM=1 | |
IP=1.3.3.7 | |
PORT=2456 | |
NAME=Valheim_Server$SVNUM | |
PARAMS="up" | |
DESC="Valheim (Docker) Dedicated Server #$SVNUM on port $PORT" | |
########################################### | |
# # | |
# DON'T TOUCH THESE # | |
# # | |
########################################### | |
case "$1" in | |
start) | |
echo "Starting $DESC: $NAME" | |
if [ -e $DIR ]; then | |
cd $DIR | |
su $S_USER -l -c "screen -d -m -S $NAME $DAEMON $PARAMS" | |
else | |
echo "No such directory: $DIR!" | |
fi | |
;; | |
stop) | |
if su $S_USER -l -c "screen -ls" |grep $NAME; then | |
echo -n "Stopping $DESC: $NAME" | |
kill `su $S_USER -l -c "screen -ls" |grep $NAME |awk -F . '{print $1}'|awk '{print $1}'` | |
echo " ... done." | |
else | |
echo "Couldn't find a running $DESC" | |
fi | |
;; | |
restart) | |
if su $S_USER -l -c "screen -ls" |grep $NAME; then | |
echo -n "Stopping $DESC: $NAME" | |
kill `su $S_USER -l -c "screen -ls" |grep $NAME |awk -F . '{print $1}'|awk '{print $1}'` | |
echo " ... done." | |
else | |
echo "Couldn't find a running $DESC" | |
fi | |
echo -n "Starting $DESC: $NAME" | |
cd $DIR | |
su $S_USER -l -c "screen -d -m -S $NAME $DAEMON $PARAMS" | |
echo " ... done." | |
;; | |
status) | |
# Check whether there's a "srcds" process | |
ps aux | grep -v grep | grep srcds_r > /dev/null | |
CHECK=$? | |
[ $CHECK -eq 0 ] && echo "SRCDS is UP" || echo "SRCDS is DOWN" | |
;; | |
*) | |
echo "Usage: $0 {start|stop|status|restart}" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment