Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #CentOS 7.2 / RHEL 7.2 service script
- #Create a service user and let the user own the WSO2 ESB installation
- sudo adduser wso2esb
- sudo chown -R wso2esb:wso2esb /opt/wso2esb-5.0.0
- #These instructions are working with RHEL 7.2 (or CentOS 7.2)
- #Create a service file
- sudo vi /opt/wso2esb-5.0.0/bin/service.sh
- #!/bin/bash
- # --------------------------------------------------------------
- #
- # Licensed to the Apache Software Foundation (ASF) under one
- # or more contributor license agreements. See the NOTICE file
- # distributed with this work for additional information
- # regarding copyright ownership. The ASF licenses this file
- # to you under the Apache License, Version 2.0 (the
- # "License"); you may not use this file except in compliance
- # with the License. You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing,
- # software distributed under the License is distributed on an
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- # KIND, either express or implied. See the License for the
- # specific language governing permissions and limitations
- # under the License.
- #
- # --------------------------------------------------------------
- # This service script will be executed to start the servers.
- # --------------------------------------------------------------
- #
- USER="wso2bps" #eg: ubuntu
- PRODUCT_CODE="BPS" #eg: CEP
- CARBON_HOME="/opt/wso2bps-3.6.0" #eg: /mnt/10.0.0.1/wso2esb-4.9.0
- LOCK_FILE="${CARBON_HOME}/wso2carbon.lck"
- PID_FILE="${CARBON_HOME}/wso2carbon.pid"
- CMD="${CARBON_HOME}/bin/wso2server.sh" #eg: ${CARBON_HOME}/bin/wso2server.sh
- JAVA_HOME="{{bps_java_path}}" #eg: /usr/java/default
- export JAVA_HOME=$JAVA_HOME
- # Status the service
- status() {
- if [ -f $PID_FILE ]
- then
- PID=`cat $PID_FILE`
- ps -fp $PID > /dev/null 2>&1
- PIDVAL=$?
- else
- PIDVAL=3
- fi
- if [ $PIDVAL -eq 0 ]
- then
- echo "WSO2 $PRODUCT_CODE server is running ..."
- else
- echo "WSO2 $PRODUCT_CODE server is stopped."
- fi
- return $PIDVAL
- }
- # Start the service
- start() {
- if [ -f $PID_FILE ]
- then
- PID=`cat $PID_FILE`
- ps -fp $PID > /dev/null 2>&1
- PIDVAL=$?
- else
- PIDVAL=3
- fi
- if [ $PIDVAL -eq 0 ]
- then
- echo "WSO2 $PRODUCT_CODE server is running ..."
- else
- echo -n "Starting WSO2 $PRODUCT_CODE server: "
- touch $LOCK_FILE
- su $USER -c "$CMD -Dsetup start > /dev/null 2>&1 &"
- sleep 5
- if [ -f $PID_FILE ]
- then
- PID=`cat $PID_FILE`
- ps -fp $PID > /dev/null 2>&1
- PIDVAL=$?
- if [ $PIDVAL -eq 0 ]
- then
- echo "success"
- else
- echo "failure"
- fi
- else
- echo "failure"
- PIDVAL=2
- fi
- fi
- echo
- return $PIDVAL
- }
- # Restart the service
- restart() {
- echo -n "Restarting WSO2 $PRODUCT_CODE server: "
- touch $LOCK_FILE
- su $USER -c "$CMD restart > /dev/null 2>&1 &"
- sleep 15
- if [ -f $PID_FILE ]
- then
- PID=`cat $PID_FILE`
- ps -fp $PID > /dev/null 2>&1
- PIDVAL=$?
- if [ $PIDVAL -eq 0 ]
- then
- echo "success"
- else
- echo "failure"
- fi
- else
- echo "failure"
- PIDVAL=2
- fi
- echo
- return $PIDVAL
- }
- # Stop the service
- stop() {
- if [ -f $PID_FILE ]
- then
- PID=`cat $PID_FILE`
- ps -fp $PID > /dev/null 2>&1
- PIDVAL=$?
- if [ $PIDVAL -eq 0 ]
- then
- echo -n "Stopping WSO2 $PRODUCT_CODE server: "
- su $USER -c "$CMD stop > /dev/null 2>&1 &"
- rm -f $LOCK_FILE
- sleep 10
- PID=`cat $PID_FILE`
- ps -fp $PID > /dev/null 2>&1
- PIDVAL=$?
- if [ $PIDVAL -eq 0 ]
- then
- echo "failure"
- PIDVAL=2
- else
- echo "success"
- PIDVAL=0
- fi
- else
- echo "WSO2 $PRODUCT_CODE server is not running."
- PIDVAL=0
- fi
- else
- echo "WSO2 $PRODUCT_CODE server is not running."
- PIDVAL=0
- fi
- echo
- return $PIDVAL
- }
- ### main logic ###
- case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- status)
- status
- ;;
- restart|reload|condrestart)
- restart
- ;;
- *)
- echo $"Usage: $0 {start|stop|restart|reload|status}"
- exit 1
- esac
- exit $?
- ##### END OF THE SERVICE FILE #####
- sudo chmod 755 /opt/wso2esb-5.0.0/bin/service.sh
- sudo vi /usr/lib/systemd/system/wso2esb.service
- [Unit]
- Description=WSO2 ESB Service
- After=network.target
- [Service]
- ExecStart=/opt/wso2esb-5.0.0/bin/service.sh start
- ExecStop=/opt/wso2esb-5.0.0/bin/service.sh stop
- RemainAfterExit=yes
- [Install]
- WantedBy=multi-user.target
- cd /etc/systemd/system/multi-user.target.wants
- ln –s / usr/lib/systemd/system/wso2esb.service
- #Enable the service
- #bug workaround
- sudo systemctl daemon-reexec
- sudo systemctl enable wso2esb.service
- #List services:
- systemctl --type=service
- #Start service
- sudo systemctl start wso2esb.service
- ##########
- # simple service for any app
- etc/systemd/system/myserver.service
- [Unit]
- Description=Custom Server
- After=network.target
- [Service]
- Type=simple
- User=the_username
- ExecStart=/srv/...../bin/service.sh
- Restart=on-abort
- [Install]
- WantedBy=multi-user.target
- systemctl daemon-reload
- systemctl enable myserver.service
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement