Created
November 18, 2016 17:03
-
-
Save floriankraft/c8dc5972ba23abdeeffb7d331d672c3e to your computer and use it in GitHub Desktop.
Corrected init.d script for starting Bitbucket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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-latest" | |
# BITBUCKET_HOME: Path to the Bitbucket home directory | |
BITBUCKET_HOME="/home/bitbucket/bitbucket_home" | |
# ================================================================================== | |
# ================================================================================== | |
# ================================================================================== | |
# 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_INSTALLDIR/work/catalina.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 | |
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 | |
log_failure_msg "$NAME is not running." | |
fi | |
} | |
case "$1" in | |
start) | |
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" | |
do_start | |
case "$?" in | |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; | |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; | |
esac | |
;; | |
stop) | |
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" | |
do_stop | |
case "$?" in | |
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; | |
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; | |
esac | |
;; | |
status) | |
if [ ! -e $PIDFILE ]; then | |
log_failure_msg "$NAME is not running." | |
return 1 | |
fi | |
status_of_proc -p $PIDFILE "bitbucket" $NAME && exit 0 || exit $? | |
;; | |
restart|force-reload) | |
# | |
# If the "reload" option is implemented then remove the | |
# 'force-reload' alias | |
# | |
log_daemon_msg "Restarting $DESC" "$NAME" | |
do_stop | |
case "$?" in | |
0|1) | |
do_start | |
case "$?" in | |
0) log_end_msg 0 ;; | |
1) log_end_msg 1 ;; # Old process is still running | |
*) log_end_msg 1 ;; # Failed to start | |
esac | |
;; | |
*) | |
# Failed to stop | |
log_end_msg 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