我正在尝试修改我编写的这个非常简单的 shell 脚本,以检查屏幕是否已经处于活动状态,如果是,则不要创建它们。例如,如果我使用start
参数调用此脚本两次,将进行四个屏幕会话。我想阻止这种情况。
#! /bin/sh
# /etc/init.d/css-server
#
case "$1" in
start)
echo "Starting Nullus Imprimis war server..."
screen -A -m -d -S css-war-server /home/css-servers/war-server/css/srcds_run -game cstrike +map de_dust2 +maxplayers 16 -autoupdate -port 2555
echo "Nullus Imprimis war server started"
echo "Starting Nullus Imprimis pub server #1..."
screen -A -m -d -S css-pub-server-1 /home/css-servers/pub-server-1/css/srcds_run -game cstrike +map de_dust2 +maxplayers 32 -autoupdate -port 2666
echo "Nullus Imprimis pub server #1 started"
;;
stop)
echo "Stopping Nullus Imprimis war server..."
screen -S css-war-server -X quit
echo "Nullus Imprimis war server stopped"
echo "Stopping Nullus Imprimis pub server #1..."
screen -S css-pub-server-1 -X quit
echo "Nullus Imprimis pub server #1 stopped"
;;
*)
echo "Usage: service css-servers {start|stop}"
exit 1
;;
esac
exit 0
另外,我想让服务器在他们自己的用户名下运行,在这种情况下css-servers
。我怎样才能做到这一点?