搜索
查看: 3965|回复: 3

linux下自动启动脚本

[复制链接]
发表于 2009-8-4 11:02:44 | 显示全部楼层 |阅读模式 来自 日本
从网上找到的,不错的!

原文在这:
http://www.centos.org/modules/ne ... der=ASC&start=0



#!/bin/sh
#
# chkconfig: 3 20 80
# description: Start the Counter-Strike Source server.
#
#
# AUTHORS :
#
# Julien Escario ( pandemik@asylog.net )
# &
# Cedric Rochat ( crochat@younics.org )
# modified by: Pistolero
# ===========================================
#
# Edit the DIR-Var to fit your system (just contains the path to the dir that contains hlds_run)
# Edit the PARAMS-Var to fit your needs
# - standard is startup as LAN-server
#
# When this is done, copy the file to /etc/rc.d/init.d (or whereever your system stores the
# scripts for starting the services
# Now you can link the script to your runlevel-dir, here's an example for runlevel 3:
# ln -s /etc/rc.d/init.d/hlds /etc/rc.d/rc3.d/S90hlds
# ln -s /etc/rc.d/init.d/hlds /etc/rc.d/rc3.d/K50hlds
#
# Or use it manualy like:
# /etc/rc.d/init.d/hlds start
# /etc/rc.d/init.d/hlds stop
#
# How to see the server-console:
#
# Just type in: screen -r cstrike
# More info about screen can be found by typing "man screen" or using this nice link
# http://server.counter-strike.net/help/linuxscreen.html
#
# If you don't want to start the server as root you have to change this:
# add the var CS_USER and uncomment it
# change the lines at the "start-block"
#
# You must be logged in as this user to re-attach the screen!
#
# DOC by jwm (jwm@counter-strike.de)


# Edit and uncomment it to run the server as non-root
# CS_USER="jwm"
#
# DON'T FORGET TO CHANGE THE PATH TO YOUR NEEDS!
DIR=/home/admin/hlds
#
# LAN-server:
# PARAMS="-game cstrike -nomaster -insecure +sv_lan 1 +maxplayers 16 +map de_dust"
#
# Internet-server:
PARAMS="-game cstrike +map de_dust +maxplayers 8 &"

clear
PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=$DIR/srcds_run
NAME=cstrike
DESC="CounterStrike source dedicated server"

case "$1" in
start)
if [ -e $DIR ];
then
echo "Starting $DESC: $NAME"
cd $DIR
# Change the lines for running as non-root!
# su $CS_USER -c "screen -d -m -S $NAME $DAEMON $PARAMS"
screen -d -m -S $NAME $DAEMON $PARAMS
else echo "No such directory: $DIR!"
fi
;;

stop)
if [[ `screen -ls |grep $NAME` ]]
then
echo -n "Stopping $DESC: $NAME"
kill `screen -ls |grep $NAME |awk -F . '{print $1}'|awk '{print $1}'`
echo " ... done."
else
echo "Coulnd't find a running $DESC"
fi
;;

restart)
if [[ `screen -ls |grep $NAME` ]]
then
echo -n "Stopping $DESC: $NAME"
kill `screen -ls |grep $NAME |awk -F . '{print $1}'|awk '{print $1}'`
echo " ... done."
else
echo "Coulnd't find a running $DESC"
fi

echo -n "Starting $DESC: $NAME"
cd $DIR
screen -d -m -S $NAME $DAEMON $PARAMS
echo " ... done."
;;

status)
# Check whether there's a "hlds" process
# if "checkproc" is installed, you can use this:
# checkproc $DIR/hlds_run && echo "CS-Server RUNNING" || echo "CS-Server NOT RUNNING"
# (thx to commander)
ps aux | grep -v grep | grep srcds_r > /dev/null
CHECK=$?
[ $CHECK -eq 0 ] && echo "HLDS is UP" || echo "HLDS is DOWN"
;;

*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac

exit 0
发表于 2009-8-4 15:06:44 | 显示全部楼层 来自 中国–江西–南昌
不错不错,和我的差不多
回复

使用道具 举报

发表于 2009-8-4 21:18:33 | 显示全部楼层 来自 中国–重庆–重庆–渝中区
呵呵   好东西
回复

使用道具 举报

发表于 2010-2-6 13:56:07 | 显示全部楼层 来自 中国–河北–石家庄
这东西怎么用?能详细说说吗?我刚开始用linux,还不会呢。
回复

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

快速回复 返回顶部 返回列表