Skip to content

Instantly share code, notes, and snippets.

@breenie
Last active February 27, 2019 15:28
Show Gist options
  • Select an option

  • Save breenie/2cef65fb507e2c106680f586846752e2 to your computer and use it in GitHub Desktop.

Select an option

Save breenie/2cef65fb507e2c106680f586846752e2 to your computer and use it in GitHub Desktop.
Bitbucket Server init script for RHEL/CentOS. Cobbled together from the official scripts and other littered about GitHub
#! /bin/sh
### BEGIN INIT INFO
# Provides: bitbucket
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Initscript for Atlassian Bitbucket Server
# Description: Automatically start Atlassian Bitbucket Server when the system starts up.
# Provide commands for manually starting and stopping Bitbucket Server.
### END INIT INFO
# Adapt the following lines to your configuration
# RUNUSER: The user to run Bitbucket Server as.
RUNUSER=bitbucket
# BITBUCKET_INSTALLDIR: The path to the Bitbucket Server installation directory
BITBUCKET_INSTALLDIR="/opt/atlassian/bitbucket/6.0.1"
# BITBUCKET_HOME: Path to the Bitbucket home directory
BITBUCKET_HOME="/data/atlassian/stash"
# ==================================================================================
# ==================================================================================
# ==================================================================================
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Atlassian Bitbucket Server"
NAME=bitbucket
PIDFILE=$BITBUCKET_HOME/log/bitbucket.pid
SCRIPTNAME=/etc/init.d/$NAME
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
# load RHEL init.d functions
. /etc/init.d/functions
run_with_home() {
if [ "$RUNUSER" != "$USER" ]; then
su - "$RUNUSER" -c "export BITBUCKET_HOME=${BITBUCKET_HOME};${BITBUCKET_INSTALLDIR}/bin/$1"
else
export BITBUCKET_HOME=${BITBUCKET_HOME};${BITBUCKET_INSTALLDIR}/bin/$1
fi
}
#
# Function that starts the daemon/service
#
do_start()
{
run_with_home start-bitbucket.sh
}
#
# Function that stops the daemon/service
#
do_stop()
{
if [ -e $PIDFILE ]; then
run_with_home stop-bitbucket.sh
else
echo -n "$DESC is not running."
return 1
fi
}
case "$1" in
start)
do_start
case "$?" in
0) echo -n "Starting $DESC " && success && echo ;;
1) echo -n "Starting $DESC " && warning && echo ;;
2) echo -n "unknown error starting $DESC " && failure && echo ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && echo "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0) echo -n "Stopping $DESC " && success && echo ;;
1) echo -n "Stopping $DESC " && passed && echo ;;
2) echo -n "unknown error " && failure && echo ;;
esac
;;
status)
status -p $PIDFILE $NAME
;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
echo -n "Restarting $DESC "
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) success && echo ;;
1) warning && echo ;; # Old process is still running
*) failure && echo ;; # Failed to start
esac
;;
*)
# Failed to stop
failure
echo
exit 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment