Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.27 KB | None | 0 0
  1. #!/bin/sh
  2. #made by Kevin Lefevre
  3.  
  4. #propriétés du cluster
  5. HOSTNAME="evl2400469.eu.verio.net:7180"
  6. CLUSTER_NAME=SFR
  7. LOGIN=admin
  8. PASS=admin
  9.  
  10. ES_HOME="/opt/elasticsearch-1.2.0/"
  11. LOG_HOME="/opt/logstash/"
  12. #/opt/logstash/bin/logstash agent -f /etc/logstash/conf.d/logstash.conf
  13. LOG_CONF="/etc/logstash/conf.d/logstash.conf"
  14.  
  15. #Version de Cloudera Manager:
  16. #Cloudera Manager 5.0
  17. CV="v6"
  18. #Cloudera Manager 4.8
  19. #CV="v5"
  20.  
  21. #liste des services (dans l'ordre de démarrage)
  22. #LIST="ZOOKEEPER HDFS SOLR SPARK HBASE KS_INDEXER YARN HIVE IMPALA OOZIE SQOOP HUE"
  23. LIST=$@
  24.  
  25. ALL=0
  26.  
  27. #Specific Cloudera 5.0: Spark
  28. ZOOKEEPER=0
  29. HDFS=0
  30. SOLR=0
  31. SPARK=0
  32. HBASE=0
  33. KS_INDEXER=0
  34. #MAPREDUCE=0
  35. YARN=0
  36. OOZIE=0
  37. SQOOP=0
  38. #FLUME=0
  39. HIVE=0
  40. IMPALA=0
  41. HUE=0
  42.  
  43. START=0
  44. STOP=0
  45.  
  46. PARAM=""
  47.  
  48. function start_elasticsearch()
  49. {
  50. if [ -f es.pid ]; then
  51. ES_PID=$(read es.pid)
  52. echo "Elasticsearch already started with PID: $ES_PID"
  53. else
  54. nohup $ES_HOME/bin/elasticsearch &
  55. ES_PID=$!
  56. echo $ES_PID >> es.pid
  57. echo "Starting Elasticsearch with PID: $ES_PID"
  58. fi
  59. }
  60.  
  61. function stop_elasticsearch()
  62. {
  63. if [ -f es.pid ]; then
  64. while read ES_PID; do
  65. echo "Stopping Elasticsearch with PID: $ES_PID"
  66. kill -9 $ES_PID || echo "could not kill Elasticsearch"
  67. done < es.pid
  68. rm -rf es.pid
  69. else
  70. echo "Elasticsearch is not started"
  71. fi
  72. }
  73.  
  74. function start_logstash()
  75. {
  76. if [ -f ls.pid ]; then
  77. LS_PID=$(read ls.pid)
  78. echo "Logstash agent already started with PID: $LS_PID"
  79. else
  80. nohup $LOG_HOME/bin/logstash agent -f $LOG_CONF &
  81. LS_PID=$!
  82. echo $LS_PID >> ls.pid
  83. echo "Starting Logstash agent with PID: $LS_PID"
  84. fi
  85. }
  86.  
  87. function stop_logstash()
  88. {
  89. if [ -f ls.pid ]; then
  90. while read LS_PID; do
  91. echo "Stopping Logstash agent with PID: $LS_PID"
  92. kill -9 $LS_PID || "could not kill Logstash agent."
  93. done < ls.pid
  94. else
  95. echo "Logstash agent is not started"
  96. fi
  97. }
  98.  
  99. function check_args()
  100. {
  101. for service in $LIST; do
  102. case "$service" in
  103. "all")
  104. ALL=1
  105. ;;
  106. "elk")
  107. if [ $STOP -eq 1 ]; then
  108. stop_elasticsearch
  109. stop_logstash
  110. fi
  111. if [ $START -eq 1 ]; then
  112. start_elasticsearch
  113. start_logstash
  114. fi
  115. ;;
  116. "zookeeper")
  117. ZOOKEEPER=1
  118. if [ $STOP -eq 1 ]; then
  119. HUE=1
  120. SOLR=1
  121. HDFS=1
  122. YARN=1
  123. HIVE=1
  124. OOZIE=1
  125. fi
  126. ;;
  127. "hdfs")
  128. HDFS=1
  129. if [ $STOP -eq 1 ]; then
  130. IMPALA=1
  131. SPARK=1
  132. SOLR=1
  133. HBASE=1
  134. YARN=1
  135. fi
  136. if [ $START -eq 1 ]; then
  137. ZOOKEEPER=1
  138. fi
  139. ;;
  140. "solr")
  141. SOLR=1
  142. if [ $STOP -eq 1 ]; then
  143. HUE=1
  144. KS_INDEXER=1
  145. fi
  146. if [ $START -eq 1 ]; then
  147. HDFS=1
  148. ZOOKEEPER=1
  149. KS_INDEXER=1
  150. fi
  151. ;;
  152. "spark")
  153. SPARK=1
  154. if [ $START -eq 1 ]; then
  155. HDFS=1
  156. ZOOKEEPER=1
  157. fi
  158. ;;
  159. "yarn")
  160. YARN=1
  161. if [ $START -eq 1 ]; then
  162. HDFS=1
  163. ZOOKEEPER=1
  164. fi
  165. ;;
  166. # "mapreduce")
  167. # MAPREDUCE=1
  168. # if [ $START -eq 1 ]; then
  169. # HDFS=1
  170. # ZOOKEEPER=1
  171. # fi
  172. # ;;
  173. "ks_indexer")
  174. KS_INDEXER=1
  175. if [ $START -eq 1 ]; then
  176. SOLR=1
  177. HBASE=1
  178. HDFS=1
  179. ZOOKEEPER=1
  180. fi
  181. ;;
  182. "hbase")
  183. HBASE=1
  184. if [ $STOP -eq 1 ]; then
  185. HUE=1
  186. IMPALA=1
  187. KS_INDEXER=1
  188. fi
  189. if [ $START -eq 1 ]; then
  190. HDFS=1
  191. ZOOKEEPER=1
  192. KS_INDEXER=1
  193. fi
  194. ;;
  195. "hive")
  196. HIVE=1
  197. if [ $STOP -eq 1 ]; then
  198. HUE=1
  199. IMPALA=1
  200. fi
  201. if [ $START -eq 1 ]; then
  202. ZOOKEEPER=1
  203. fi
  204. ;;
  205. "impala")
  206. IMPALA=1
  207. if [ $START -eq 1 ]; then
  208. HDFS=1
  209. ZOOKEEPER=1
  210. HBASE=1
  211. fi
  212. ;;
  213. "oozie")
  214. OOZIE=1
  215. if [ $STOP -eq 1 ]; then
  216. HUE=1
  217. fi
  218. ;;
  219. "sqoop")
  220. SQOOP=1
  221. if [ $STOP -eq 1 ]; then
  222. HUE=1
  223. fi
  224. ;;
  225. # "flume")
  226. # FLUME=1
  227. # if [ $START -eq 1 ]; then
  228. # fi
  229. # ;;
  230. "hue")
  231. HUE=1
  232. if [ $START -eq 1 ]; then
  233. ZOOKEEPER=1
  234. HBASE=1
  235. HIVE=1
  236. HDFS=1
  237. OOZIE=1
  238. YARN=1
  239. SQOOP=1
  240. SOLR=1
  241. IMPALA=1
  242. fi
  243. ;;
  244. esac
  245. done
  246. }
  247.  
  248. function if_command ()
  249. {
  250. STRING="{\n\t\"items\" : [ ] }\n"
  251. RES=$(curl -sX GET -u "$LOGIN:$PASS" "http://""$HOSTNAME"/api/$CV/clusters/$CLUSTER_NAME/commands)
  252. sleep 1000
  253. if [ "$STRING"="$RES" ]; then
  254. return 1
  255. else
  256. return 0
  257. fi
  258. }
  259.  
  260. function wait_command ()
  261. {
  262. echo "Waiting "
  263. while if_command;do
  264. echo -n "."
  265. sleep 2000
  266. done
  267. echo ""
  268. }
  269.  
  270. function start()
  271. {
  272. START=1
  273. check_args
  274.  
  275. if [ $ALL -eq 1 ]; then
  276. PARAM="/api/$CV/clusters/$CLUSTER_NAME/commands/start"
  277. echo "starting all services"
  278. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  279. fi
  280.  
  281. if [ $ZOOKEEPER -eq 1 ]; then
  282. wait_command
  283. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/zookeeper/commands/start"
  284. echo "starting Zookeeper"
  285. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  286. fi
  287. if [ $HDFS -eq 1 ]; then
  288. wait_command
  289. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/hdfs/commands/start"
  290. echo "starting HDFS"
  291. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  292. fi
  293. if [ $SOLR -eq 1 ]; then
  294. wait_command
  295. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/solr/commands/start"
  296. echo "starting SolR"
  297. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  298. fi
  299.  
  300. if [ $HBASE -eq 1 ]; then
  301. wait_command
  302. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/hbase/commands/start"
  303. echo "starting HBase"
  304. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  305. fi
  306.  
  307. if [ $KS_INDEXER -eq 1 ]; then
  308. wait_command
  309. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/ks_indexer/commands/start"
  310. echo "starting ks_indexer"
  311. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  312. fi
  313.  
  314. if [ $YARN -eq 1 ]; then
  315. wait_command
  316. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/yarn/commands/start"
  317. echo "starting YARN"
  318. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  319. fi
  320. #
  321. # if [ $MAPREDUCE -eq 1 ]; then
  322. #wait_command
  323. # PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/mapreduce/commands/start"
  324. # echo "starting MapReduce"
  325. # curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  326. # fi
  327.  
  328. if [ $SPARK -eq 1 ]; then
  329. wait_command
  330. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/spark/commands/start"
  331. echo "starting Spark"
  332. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  333. fi
  334.  
  335. if [ $SQOOP -eq 1 ]; then
  336. wait_command
  337. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/sqoop/commands/start"
  338. echo "starting Sqoop"
  339. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  340. fi
  341.  
  342. if [ $OOZIE -eq 1 ]; then
  343. wait_command
  344. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/oozie/commands/start"
  345. echo "starting Oozie"
  346. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  347. fi
  348. #
  349. # if [ $FLUME -eq 1 ]; then
  350. #wait_command
  351. # PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/flume/commands/start"
  352. # echo "starting Flume"
  353. # curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  354. # fi
  355.  
  356. if [ $HIVE -eq 1 ]; then
  357. wait_command
  358. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/hive/commands/start"
  359. echo "starting Hive"
  360. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  361. fi
  362.  
  363. if [ $IMPALA -eq 1 ]; then
  364. wait_command
  365. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/impala/commands/start"
  366. echo "starting Impala"
  367. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  368. fi
  369.  
  370. if [ $HUE -eq 1 ]; then
  371. wait_command
  372. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/hue/commands/start"
  373. echo "starting HUE"
  374. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  375. fi
  376. }
  377.  
  378. function stop()
  379. {
  380. STOP=1
  381. check_args
  382.  
  383. if [ $ALL -eq 1 ]; then
  384. wait_command
  385. PARAM="/api/$CV/clusters/$CLUSTER_NAME/commands/stop"
  386. echo "stopping all services"
  387. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  388. fi
  389.  
  390. if [ $HUE -eq 1 ]; then
  391. wait_command
  392. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/hue/commands/stop"
  393. echo "stopping HUE"
  394. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  395. fi
  396.  
  397. if [ $SQOOP -eq 1 ]; then
  398. wait_command
  399. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/sqoop/commands/stop"
  400. echo "stopping Sqoop"
  401. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  402. fi
  403.  
  404. if [ $OOZIE -eq 1 ]; then
  405. wait_command
  406. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/oozie/commands/stop"
  407. echo "stopping Oozie"
  408. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  409. fi
  410.  
  411. if [ $IMPALA -eq 1 ]; then
  412. wait_command
  413. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/impala/commands/stop"
  414. echo "stopping Impala"
  415. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  416. fi
  417.  
  418. if [ $SPARK -eq 1 ]; then
  419. wait_command
  420. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/spark/commands/stop"
  421. echo "stopping Spark"
  422. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  423. fi
  424.  
  425. if [ $HIVE -eq 1 ]; then
  426. wait_command
  427. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/hive/commands/stop"
  428. echo "stopping Hive"
  429. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  430. fi
  431. #
  432. # if [ $FLUME -eq 1 ]; then
  433. #wait_command
  434. # PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/flume/commands/stop"
  435. # echo "stopping Flume"
  436. # curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  437. # fi
  438.  
  439. if [ $YARN -eq 1 ]; then
  440. wait_command
  441. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/yarn/commands/stop"
  442. echo "stopping YARN"
  443. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  444. fi
  445. #
  446. # if [ $MAPREDUCE -eq 1 ]; then
  447. #wait_command
  448. # PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/mapreduce/commands/stop"
  449. # echo "stopping MapReduce"
  450. # curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  451. # fi
  452.  
  453. if [ $KS_INDEXER -eq 1 ]; then
  454. wait_command
  455. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/ks_indexer/commands/stop"
  456. echo "stopping ks_indexer"
  457. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  458. fi
  459.  
  460. if [ $HBASE -eq 1 ]; then
  461. wait_command
  462. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/hbase/commands/stop"
  463. echo "stopping HBase"
  464. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  465. fi
  466.  
  467. if [ $SOLR -eq 1 ]; then
  468. wait_command
  469. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/solr/commands/stop"
  470. echo "stopping SolR"
  471. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  472. fi
  473.  
  474. if [ $HDFS -eq 1 ]; then
  475. wait_command
  476. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/hdfs/commands/stop"
  477. echo "stopping HDFS"
  478. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  479. fi
  480.  
  481. if [ $ZOOKEEPER -eq 1 ]; then
  482. wait_command
  483. PARAM="/api/$CV/clusters/$CLUSTER_NAME/services/zookeeper/commands/stop"
  484. echo "stopping Zookeeper"
  485. curl -X POST -u "$LOGIN:$PASS" "http://""$HOSTNAME""$PARAM"
  486. fi
  487. }
  488.  
  489. function restart ()
  490. {
  491. stop
  492. wait_command
  493. start
  494. }
  495.  
  496. function usage()
  497. {
  498. echo "Usage: $0 (start|stop|restart) (all|services) (elk)"
  499. echo "Example: \"\$ $0 start all\" \"\$ $0 stop hbase\" \"\$ $0 restart elk\""
  500. }
  501.  
  502. if [ $# -eq 0 ]; then
  503. usage
  504. exit 1
  505. fi
  506.  
  507. case "$1" in
  508. "start")
  509. start
  510. ;;
  511. "stop")
  512. stop
  513. ;;
  514. "restart")
  515. restart
  516. ;;
  517. *)
  518. usage
  519. exit 1
  520. ;;
  521. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement