Advertisement
gusto2

CentOS 7.2 WSO2ESB service script

Nov 4th, 2016
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.23 KB | None | 0 0
  1. #CentOS 7.2 / RHEL 7.2 service script
  2.  
  3. #Create a service user and let the user own the WSO2 ESB installation
  4. sudo adduser wso2esb
  5. sudo chown -R wso2esb:wso2esb /opt/wso2esb-5.0.0
  6.  
  7. #These instructions are working with RHEL 7.2 (or CentOS 7.2)
  8.  
  9.  
  10. #Create a service file
  11. sudo vi /opt/wso2esb-5.0.0/bin/service.sh
  12.  
  13. #!/bin/bash
  14. # --------------------------------------------------------------
  15. #
  16. # Licensed to the Apache Software Foundation (ASF) under one
  17. # or more contributor license agreements.  See the NOTICE file
  18. # distributed with this work for additional information
  19. # regarding copyright ownership.  The ASF licenses this file
  20. # to you under the Apache License, Version 2.0 (the
  21. # "License"); you may not use this file except in compliance
  22. # with the License.  You may obtain a copy of the License at
  23. #
  24. #     http://www.apache.org/licenses/LICENSE-2.0
  25. #
  26. # Unless required by applicable law or agreed to in writing,
  27. # software distributed under the License is distributed on an
  28. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29. # KIND, either express or implied.  See the License for the
  30. # specific language governing permissions and limitations
  31. # under the License.
  32. #
  33. # --------------------------------------------------------------
  34. # This service script will be executed to start the servers.
  35. # --------------------------------------------------------------
  36. #
  37.  
  38. USER="wso2bps"                        #eg: ubuntu
  39. PRODUCT_CODE="BPS"                    #eg: CEP
  40. CARBON_HOME="/opt/wso2bps-3.6.0"      #eg: /mnt/10.0.0.1/wso2esb-4.9.0
  41. LOCK_FILE="${CARBON_HOME}/wso2carbon.lck"
  42. PID_FILE="${CARBON_HOME}/wso2carbon.pid"
  43. CMD="${CARBON_HOME}/bin/wso2server.sh"     #eg: ${CARBON_HOME}/bin/wso2server.sh
  44. JAVA_HOME="{{bps_java_path}}"          #eg: /usr/java/default
  45.  
  46. export JAVA_HOME=$JAVA_HOME
  47.  
  48. # Status the service
  49. status() {
  50.  if [ -f $PID_FILE ]
  51.      then
  52.   PID=`cat $PID_FILE`
  53.   ps -fp $PID > /dev/null 2>&1
  54.   PIDVAL=$?
  55.      else
  56.   PIDVAL=3
  57.  fi
  58.  
  59.  if [ $PIDVAL -eq 0 ]
  60.      then
  61.   echo "WSO2 $PRODUCT_CODE server is running ..."
  62.      else
  63.   echo "WSO2 $PRODUCT_CODE server is stopped."
  64.  fi
  65.  return $PIDVAL
  66. }
  67.  
  68. # Start the service
  69. start() {
  70.  if [ -f $PID_FILE ]
  71.      then
  72.   PID=`cat $PID_FILE`
  73.   ps -fp $PID > /dev/null 2>&1
  74.   PIDVAL=$?
  75.      else
  76.   PIDVAL=3
  77.  fi
  78.  
  79.  if [ $PIDVAL -eq 0 ]
  80.      then
  81.         echo "WSO2 $PRODUCT_CODE server is running ..."
  82.      else
  83.         echo -n "Starting WSO2 $PRODUCT_CODE server: "
  84.         touch $LOCK_FILE
  85.         su $USER -c "$CMD -Dsetup start > /dev/null 2>&1 &"
  86.         sleep 5
  87.         if [ -f $PID_FILE ]
  88.      then
  89.    PID=`cat $PID_FILE`
  90.    ps -fp $PID > /dev/null 2>&1
  91.    PIDVAL=$?
  92.    if [ $PIDVAL -eq 0 ]
  93.        then
  94.     echo "success"
  95.        else
  96.     echo "failure"
  97.    fi
  98.      else
  99.    echo "failure"
  100.    PIDVAL=2
  101.         fi
  102.  fi
  103.  echo
  104.  return $PIDVAL
  105. }
  106.  
  107. # Restart the service
  108. restart() {
  109.  echo -n "Restarting WSO2 $PRODUCT_CODE server: "
  110.  touch $LOCK_FILE
  111.  su $USER -c "$CMD restart > /dev/null 2>&1 &"
  112.  sleep 15
  113.  if [ -f $PID_FILE ]
  114.      then
  115.   PID=`cat $PID_FILE`
  116.   ps -fp $PID > /dev/null 2>&1
  117.   PIDVAL=$?
  118.   if [ $PIDVAL -eq 0 ]
  119.       then
  120.    echo "success"
  121.       else
  122.    echo "failure"
  123.   fi
  124.      else
  125.   echo "failure"
  126.   PIDVAL=2
  127.  fi
  128.  echo
  129.  return $PIDVAL
  130. }
  131.  
  132. # Stop the service
  133. stop() {
  134.  if [ -f $PID_FILE ]
  135.      then
  136.   PID=`cat $PID_FILE`
  137.   ps -fp $PID > /dev/null 2>&1
  138.   PIDVAL=$?
  139.   if [ $PIDVAL -eq 0 ]
  140.       then
  141.    echo -n "Stopping WSO2 $PRODUCT_CODE server: "
  142.    su $USER -c "$CMD stop > /dev/null 2>&1 &"
  143.    rm -f $LOCK_FILE
  144.    sleep 10
  145.    PID=`cat $PID_FILE`
  146.    ps -fp $PID > /dev/null 2>&1
  147.    PIDVAL=$?
  148.    if [ $PIDVAL -eq 0 ]
  149.        then
  150.     echo "failure"
  151.     PIDVAL=2
  152.        else
  153.     echo "success"
  154.     PIDVAL=0
  155.    fi
  156.       else
  157.          echo "WSO2 $PRODUCT_CODE server is not running."
  158.          PIDVAL=0
  159.   fi
  160.      else
  161.         echo "WSO2 $PRODUCT_CODE server is not running."
  162.         PIDVAL=0
  163.  fi
  164.  echo
  165.  return $PIDVAL
  166. }
  167.  
  168.  
  169. ### main logic ###
  170. case "$1" in
  171. start)
  172.     start
  173.     ;;
  174. stop)
  175.     stop
  176.     ;;
  177. status)
  178.     status
  179.     ;;
  180. restart|reload|condrestart)
  181.     restart
  182.     ;;
  183. *)
  184.    echo $"Usage: $0 {start|stop|restart|reload|status}"
  185.    exit 1
  186. esac
  187. exit $?
  188.  
  189.  
  190.  
  191.  
  192. ##### END OF THE SERVICE FILE #####
  193.  
  194.  
  195. sudo chmod 755 /opt/wso2esb-5.0.0/bin/service.sh
  196.  
  197. sudo vi /usr/lib/systemd/system/wso2esb.service
  198.  
  199. [Unit]
  200. Description=WSO2 ESB Service
  201. After=network.target
  202.  
  203. [Service]
  204. ExecStart=/opt/wso2esb-5.0.0/bin/service.sh start
  205. ExecStop=/opt/wso2esb-5.0.0/bin/service.sh stop
  206. RemainAfterExit=yes
  207.  
  208. [Install]
  209. WantedBy=multi-user.target
  210.  
  211. cd /etc/systemd/system/multi-user.target.wants
  212. ln –s / usr/lib/systemd/system/wso2esb.service
  213.  
  214. #Enable the service
  215.  #bug workaround
  216. sudo systemctl daemon-reexec
  217. sudo systemctl enable wso2esb.service
  218.  
  219. #List services:
  220. systemctl --type=service
  221.  
  222. #Start service
  223. sudo systemctl start wso2esb.service
  224.  
  225.  
  226.  
  227. ##########
  228.  
  229. # simple service  for any app
  230.  
  231. etc/systemd/system/myserver.service
  232.  
  233.  
  234.  
  235. [Unit]
  236. Description=Custom Server
  237. After=network.target
  238.  
  239. [Service]
  240. Type=simple
  241. User=the_username
  242. ExecStart=/srv/...../bin/service.sh
  243. Restart=on-abort
  244.  
  245.  
  246. [Install]
  247. WantedBy=multi-user.target
  248.  
  249.  
  250. systemctl daemon-reload
  251. systemctl enable myserver.service
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement