Advertisement
Guest User

Untitled

a guest
May 30th, 2011
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.21 KB | None | 0 0
  1. #
  2. #!/bin/bash
  3. #
  4.  
  5. #
  6. ### BEGIN INIT INFO
  7. #
  8. # Provides: Minecraft StartScript v1.0
  9. #
  10. # Required-Start: $remote_fs $syslog
  11. #
  12. # Required-Stop: $remote_fs $syslog
  13. #
  14. # Default-Start: 2 3 4 5
  15. #
  16. # Default-Stop: 0 1 6
  17. #
  18. # Short-Description: Starts the minecraft server
  19. #
  20. # Description: Starts the minecraft server specified below. You can also create a cron job to sceduele restarts of your minecraft server (recommended).
  21. #
  22. ### END INIT INFO
  23. #
  24.  
  25. #
  26. ########################
  27. #
  28. #
  29. #
  30. # Minecraft StartScript v1.0
  31. #
  32. # Copyright (C) 2011 by Silthus
  33. #
  34. #
  35. #
  36. #########################################
  37. #
  38.  
  39. #
  40.  
  41. #
  42. ###################
  43. #
  44. # CONFIGURATION #
  45. #
  46. #########################################
  47. #
  48. # NAME: user to start Minecraft from (dont run as root (u wont be able to anyways!))
  49. #
  50. # PATH: directory containing the Minecraft Server File (= working directory) (needs / at the end)
  51. #
  52. # BIN: your server executable, e.g.: minecraft_server.jar
  53. #
  54. # ID: a unique identifier for this screen session (like servers name)
  55. #
  56. # must be different for every server
  57. #
  58. #
  59. #
  60. # To restart your server every 6 hours at midnight, 6, 12 and 6 o clock put this line in your crontab:
  61. #
  62. # # Minute Hour Day of Month Month Day of Week Command
  63. #
  64. # (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)
  65. #
  66. # 0 0,6,12,18 * * * /etc/init.d/minecraft restart
  67. #
  68. #
  69. #
  70.  
  71. #
  72. NAME='minecraft'
  73. #
  74. PATH='/home/minecraft/bin/'
  75. #
  76. BIN='craftbukkit.jar'
  77. #
  78. ID='RaidCraft'
  79. #
  80. PARAMS='-Xms512M -Xmx2048M'
  81. #
  82.  
  83. #
  84.  
  85. #
  86. ############################
  87. #
  88. # ADVANCED CONFIGURATION #
  89. #
  90. #########################################
  91. #
  92.  
  93. #
  94. # in case you have custom application paths, edit here
  95. #
  96. GREP='/bin/grep'
  97. #
  98. SCREEN='/usr/bin/screen'
  99. #
  100. JAVA='/usr/bin/java'
  101. #
  102. SLEEP='/bin/sleep'
  103. #
  104.  
  105. #
  106. # colors: default, red, green, yellow, blue
  107. #
  108. D='\E[0m'
  109. #
  110. R='\E[1;31m'
  111. #
  112. G='\E[1;32m'
  113. #
  114. Y='\E[1;33m'
  115. #
  116. B='\E[1;34m'
  117. #
  118.  
  119. #
  120.  
  121. #
  122. ################################################
  123. #
  124. # do not edit below here #
  125. #
  126. # unless you REALLY know what you are doing !! #
  127. #
  128. ################################################
  129. #
  130.  
  131. #
  132.  
  133. #
  134. echo -e "\E[1;34;40m Minecraft StartScript ${Y}v1.0 ${B}by ${G}Silthus${D}"
  135. #
  136.  
  137. #
  138. # check dependencies
  139. #
  140. if [ ! -x "$GREP" ]; then
  141. #
  142. echo -e "${R}Error: grep not found in ${B}'$GREP$'${D}"
  143. #
  144. echo -e "${Y}Install with your packet manager or edit advanced config!${D}"
  145. #
  146. exit 1
  147. #
  148. fi
  149. #
  150. if [ ! -x "$SCREEN" ]; then
  151. #
  152. echo -e "${R}Error: screen not found in ${B}'$SCREEN'${D}"
  153. #
  154. echo -e "${Y}Install with your packet manager or edit advanced config!${D}"
  155. #
  156. exit 1
  157. #
  158. fi
  159. #
  160. if [ ! -x "$JAVA" ]; then
  161. #
  162. echo -e "${R}Error: java not found in ${B}'$JAVA$'${D}"
  163. #
  164. echo -e "${Y}Install with your packet manager or edit advanced config!${D}"
  165. #
  166. exit 1
  167. #
  168. fi
  169. #
  170. if [ ! -x "$SLEEP" ]; then
  171. #
  172. echo -e "${R}Error: sleep not found in ${B}'$SLEEP$'${D}"
  173. #
  174. echo -e "${Y}Install with your packet manager or edit advanced config!${D}"
  175. #
  176. exit 1
  177. #
  178. fi
  179. #
  180.  
  181. #
  182. # check for root permission
  183. #
  184. if [ $UID = 0 ]; then
  185. #
  186. ROOT=true
  187. #
  188. echo -e "${R}Do not run as ROOT!${D}"
  189. #
  190. exit 1
  191. #
  192. else
  193. #
  194. ROOT=false
  195. #
  196. fi
  197. #
  198.  
  199. #
  200. cd $PATH
  201. #
  202.  
  203. #
  204.  
  205. #
  206. ###############
  207. #
  208. # functions #
  209. #
  210. #########################################
  211. #
  212.  
  213. #
  214. start() {
  215. #
  216. echo -e "${Y}Starting ${B}$ID ${Y}...${D}"
  217. #
  218.  
  219. #
  220. if status; then
  221. #
  222. echo -e "${R}Error: ${B}$ID ${R}is already running!${D}"
  223. #
  224. exit 1
  225. #
  226. fi
  227. #
  228. $SCREEN -AmdS $ID $JAVA $PARAMS -jar $BIN nogui
  229. #
  230. }
  231. #
  232.  
  233. #
  234. stop() {
  235. #
  236. echo -e "${Y}Stopping ${B}$ID ${Y}...${D}"
  237. #
  238.  
  239. #
  240. if ! status; then
  241. #
  242. echo -e "${R}Error: ${B}$ID ${R}is not running!${D}"
  243. #
  244. exit 1
  245. #
  246. fi
  247. #
  248. $SCREEN -S $ID -p 0 -X stuff "`printf "say Going down in 10 seconds! Saving world...\r"`"
  249. #
  250. echo -e "${B}Waiting 10 seconds for the World to save ...${D}"
  251. #
  252. $SLEEP 5
  253. #
  254. $SCREEN -S $ID -p 0 -X stuff "`printf "save-all\r"`"
  255. #
  256. $SLEEP 5
  257. #
  258. $SCREEN -S $ID -p 0 -X stuff "`printf "stop\r"`"
  259. #
  260. echo -e "${G}Shutting down ...${D}"
  261. #
  262. $SLEEP 2
  263. #
  264. }
  265. #
  266.  
  267. #
  268. status() {
  269. #
  270. $SCREEN -ls | $GREP [.]$ID[[:space:]] > /dev/null
  271. #
  272. }
  273. #
  274.  
  275. #
  276. attach() {
  277. #
  278. if ! status; then
  279. #
  280. echo -e "${R}Error: ${B}$ID ${R}is not running!${D}"
  281. #
  282. exit 1
  283. #
  284. fi
  285. #
  286. $SCREEN -S $ID -r
  287. #
  288. }
  289. #
  290.  
  291. #
  292.  
  293. #
  294. # parameter parsing
  295. #
  296. case "$1" in
  297. #
  298. start)
  299. #
  300. start
  301. #
  302. echo -e "${G} ... done.${D}"
  303. #
  304. ;;
  305. #
  306.  
  307. #
  308. stop)
  309. #
  310. stop
  311. #
  312. echo -e "${G} ... done.${D}"
  313. #
  314. ;;
  315. #
  316.  
  317. #
  318. restart)
  319. #
  320. status
  321. #
  322. $SCREEN -S $ID -p 0 -X stuff "`printf "say Restarting in 10 seconds! Saving world...\r"`"
  323. #
  324. echo -e "${B}Waiting 10 seconds for the World to save ...${D}"
  325. #
  326. $SLEEP 5
  327. #
  328. $SCREEN -S $ID -p 0 -X stuff "`printf "save-all\r"`"
  329. #
  330. $SLEEP 5
  331. #
  332. $SCREEN -S $ID -p 0 -X stuff "`printf "stop\r"`"
  333. #
  334. echo -e "${B}Waiting 10 seconds for the RAM to clear ...${D}"
  335. #
  336. $SLEEP 10
  337. #
  338. start
  339. #
  340. ;;
  341. #
  342.  
  343. #
  344. status)
  345. #
  346. if status; then
  347. #
  348. echo -e "${B}$ID ${G}is running ${B}${D}"
  349. #
  350. else
  351. #
  352. echo -e "${B}$ID ${R}is not running!${D}"
  353. #
  354. fi
  355. #
  356. ;;
  357. #
  358.  
  359. #
  360. attach)
  361. #
  362. attach
  363. #
  364. ;;
  365. #
  366.  
  367. #
  368. *)
  369. #
  370. echo -e "${Y}Usage: $0 {${G}start${Y}|${R}stop${Y}|${B}restart${Y}|${B}status${Y}|${B}attach${Y}} ${Y}[ID]${D}"
  371. #
  372. echo -e "${Y}While attached press ${B}ctrl-a crlt-d ${Y}to stop watching without stopping the server!"
  373. #
  374. exit 1
  375. #
  376. ;;
  377. #
  378. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement