Bukkit服务器我一直用GNU Screen跑,隔两天有时候会不稳定要重启。好麻烦根本就不关心为什么,搞定就行。有bukkit插件可以实现但是咱多没自尊用那个。虽然感觉bash操作Screen也挺邋遢的.. 但是好用!其实不然的话怎么操作后台,nohup倒腾输入流什么的太麻烦了,这种用途还是terminal模拟器好看。
#!/bin/bash #/home/bukkit/restart.sh i=0 while (( $i < 5 )) do if [ "`ps aux|grep -e '^bukkit'|grep SCREEN`" != "" ]; then su bukkit -c 'screen -S bukkit -X stuff 'stop`echo -ne '\015'`'' #`echo -ne '\015'` 等于敲下回车 echo "`date` restart.sh:" 'Stoping bukkit...' ((i+=1)) sleep 5 else ((i+=100)) fi done if (( $i == 100 )); then echo "`date` restart.sh:" 'Bukkit was not running. Starting...' fi if (( $i == 5 )); then kill `ps aux|grep bukkit|awk '{print $2}'` echo "`date` restart.sh:" 'Forcibly killing bukkit...' sleep 1 fi if [ "`ps aux|grep -e '^bukkit'|grep SCREEN`" != "" ]; then echo "`date` restart.sh:" "ERROR: Couldn't stop bukkit. Exiting." exit 1 fi bash /home/bukkit/start.sh exit 0