Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

created Confluence init script, this doesnt work with current Conflue…

…nce install 3.5.16 but will test after upgrading wiki-test
  • Loading branch information...
commit ffc60233a03898244e0232f2b204e4f0e034bc91 1 parent fbff2a1
@sean-m authored
Showing with 306 additions and 3 deletions.
  1. +3 −3 jira-init
  2. +303 −0 wiki-init
View
6 jira-init
@@ -9,10 +9,10 @@
#
### BEGIN INIT INFO
# Provides: JIRA
-# Required-Start: mysql networking
+# Required-Start: $local_fs mysql networking
# Required-Stop: mysql networking
-# Default-Start: 3
-# Default-Stop: 0 1 6
+# Default-Start: 3 5
+# Default-Stop: 0 1 2 6
# Short-Description: JIRA issue tracker
# Description: Web based project/issue tracking
### END INIT INFO
View
303 wiki-init
@@ -0,0 +1,303 @@
+#!/usr/bin/python
+#
+# Init script for CONFLUENCE
+#
+# chkconfig: 123456 1 99
+# description: CONFLUENCE init script
+#
+# Author: Sean McArdle
+#
+### BEGIN INIT INFO
+# Provides: CONFLUENCE
+# Required-Start: $local_fs mysql networking
+# Required-Stop: mysql networking
+# Default-Start: 3 5
+# Default-Stop: 0 1 2 6
+# Short-Description: CONFLUENCE issue tracker
+# Description: Web based project/issue tracking
+### END INIT INFO
+
+import sys, os, subprocess, re, time
+
+
+'''
+Monkey-patch for subprocess.check_output from Python 2.7
+From: https://gist.github.com/edufelipe/1027906
+'''
+if "check_output" not in dir( subprocess ): # duck punch it in!
+ def f(*popenargs, **kwargs):
+ if 'stdout' in kwargs:
+ raise ValueError('stdout argument not allowed, it will be overridden.')
+ process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
+ output, unused_err = process.communicate()
+ retcode = process.poll()
+ if retcode:
+ cmd = kwargs.get("args")
+ if cmd is None:
+ cmd = popenargs[0]
+ raise subprocess.CalledProcessError(retcode, cmd)
+ return output
+ subprocess.check_output = f
+
+
+'''
+Adjust the following values to fit your application
+'''
+APP_NAME = 'CONFLUENCE'
+APP_DIR = '/data/confluence/confluence-3.5.16-std/'
+APP_START = APP_DIR + 'bin/start-wiki.sh'
+APP_STOP = APP_DIR + 'bin/shutdown.sh'
+PID_PATH = APP_DIR + 'work/catalina.pid'
+
+def lock():
+ """
+ Create the /var/lock/subsys file
+ """
+ if not os.path.exists('/var/lock/subsys/'):
+ os.makedirs('/var/lock/subsys/')
+
+ open('/var/lock/subsys/' + APP_NAME, 'w').close()
+
+def locked():
+ """
+ Return True if the lock file exists
+ """
+ return os.path.exists('/var/lock/subsys/' + APP_NAME)
+
+def unlock():
+ """
+ Remove the /var/lock/subsys file
+ """
+ os.remove('/var/lock/subsys/' + APP_NAME)
+
+def isAlive(pid):
+ '''
+ os.kill(pid, 0) does not kill the process and throws and exception if it
+ doesn't exist.
+ '''
+ try:
+ os.kill(int(pid), 0)
+ return True
+ except:
+ return False
+
+def file_check(file):
+ return os.path.exists(file)
+
+def start():
+ if not file_check(APP_START):
+ print('file: ' + APP_START + ' does not exist!')
+ return 1
+
+ if not locked():
+ print('Starting ' + APP_NAME + '...')
+ try:
+ init = subprocess.check_output(APP_START, shell = False,
+ stderr = subprocess.STDOUT)
+ lock()
+ except subprocess.CalledProcessError, e:
+ print('There was an error starting ' + APP_NAME)
+# print(e.output)
+ return e.returncode
+
+ status()
+ else:
+ print('Service locked, check status.')
+
+
+def stop():
+ """
+ Shut everything down, clean up.
+ """
+ if not file_check(APP_STOP):
+ print('file: ' + APP_STOP + ' does not exist!')
+ return 1
+
+ if locked():
+ print('Stopping ' + APP_NAME + '...')
+ try:
+ init = subprocess.check_output(APP_STOP, shell = False,
+ stderr = subprocess.STDOUT)
+ unlock()
+ except subprocess.CalledProcessError, e:
+ print('There was an error stopping ' + APP_NAME)
+ # print(e.output)
+ return e.returncode
+
+ status()
+ else:
+ print('No process lock, check status.')
+
+
+def restart():
+ """
+ Stop and then start
+ """
+ stop()
+ start()
+
+def status():
+ """
+ Print any relevant status info, and return a status code, an integer:
+
+ 0 program is running or service is OK
+ 1 program is dead and /var/run pid file exists
+ 2 program is dead and /var/lock lock file exists
+ 3 program is not running
+ 4 program or service status is unknown
+ 5-99 reserved for future LSB use
+ 100-149 reserved for distribution use
+ 150-199 reserved for application use
+ 200-254 reserved
+
+ @see: http://dev.linux-foundation.org/betaspecs/booksets/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
+ """
+
+ if locked():
+ if os.path.exists(PID_PATH):
+ pid = open(PID_PATH, 'r').readline()
+ if isAlive(pid):
+ print('Processs ' + APP_NAME + ' running on pid: ' + str(pid))
+ return 0
+ else:
+ print('Process not found, stale pid file exists.')
+ unlock()
+ return 1
+ else:
+ print('Can not find process although lock file exists.')
+ return 2
+ else:
+ if os.path.exists(PID_PATH):
+ pid = open(PID_PATH, 'r').readline()
+ if isAlive(pid):
+ lock()
+ print('Processs running on pid: ' + str(pid))
+ return 0
+ else:
+ print('Process not found, stale pid file exists.')
+ return 1
+ else:
+ print(APP_NAME + ' is not running.')
+ return 3
+
+def test():
+ """
+ This is my way of "unit testing" the script. This function
+ calls each of actions, mimicking the switchboard below.
+
+ It then verifies that the functions did what they were supposed to,
+ and reports any problems to stderr.
+
+ @TODO: this could be used to inspect the system (e.g. open a web page if this is
+ a web server control script) instead of the script.
+
+ @TODO: you'll need to also check for PID files and running processes!
+ """
+ # Since this will turn off the system when its complete,
+ # I want to warn the user and give them the chance to opt out if they
+ # chose this option by accident.
+
+ ok = raw_input("""
+******************
+TESTING MY SERVICE
+******************
+
+This will TURN OFF my-service after all the tests.
+
+This should only be done for testing and debugging purposes.
+
+Are you sure you want to do this? [Y/N]: """
+ ).lower()
+
+ if ok != 'y':
+ print >> sys.stderr, "Aborting..."
+ return
+
+ print "Writing Lock File..."
+ lock()
+ print "Verifying lock file..."
+ if os.path.exists('/var/lock/subsys/my-service'):
+ print "Lock file written..."
+ else:
+ print >> sys.stderr, "ERROR: Lock file was NOT written"
+
+ print "Starting..."
+ start()
+ # Do stuff to check the start() function
+ #
+ #
+
+ # we call status a couple of times so we can test if it's returning the right
+ # output under different circumstances
+ status()
+
+ print "Stopping..."
+ stop()
+ # Do stuff to check the stop() function
+ #
+ #
+
+ print "Removing lock file..."
+ unlock()
+
+ if os.path.exists('/var/lock/subsys/my-service'):
+ print >> sys.stderr, "ERROR: Could not remove lock file"
+ else:
+ print "Lock file removed successfully"
+
+ # one more time to see what it looks like when the service off
+ status()
+
+
+
+# Main program switchboard - wrap everything in a try block to
+# ensure the right return code is sent to the shell, and keep things tidy.
+#
+# @TODO: need to raise custom exception instead of ValueError, and
+# handle other exceptions better.
+#
+# @TODO: put lock/unlock calls inside of start/stop?
+if __name__ == '__main__':
+ # if not root...kick out
+ if not os.geteuid()==0:
+ sys.exit("\nOnly root can run this script\n")
+
+ try:
+ # if there's fewer than 2 options on the command line
+ # (sys.argv[0] is the program name)
+ if len(sys.argv) == 1:
+ raise ValueError;
+
+ action = str(sys.argv[1]).strip().lower()
+
+ if action == 'start':
+ start()
+ sys.exit(0)
+ elif action == 'stop':
+ stop()
+ sys.exit(0)
+ elif action == 'restart' or action == 'force-reload':
+ restart()
+ sys.exit(0)
+ elif action == 'status':
+ OK = status()
+ sys.exit(OK)
+ elif action == 'test':
+ test()
+ sys.exit(0)
+ else:
+ raise ValueError
+
+ except (SystemExit):
+ # calls to sys.exit() raise this error :(
+ pass
+ except (ValueError):
+ print >> sys.stderr, "Usage: " + sys.argv[0] + " [start|stop|restart|status]"
+ # return 2 for "bad command line option"
+ sys.exit(2)
+ except:
+ # all other exceptions get caught here
+ extype, value = sys.exc_info()[:2]
+ print >> sys.stderr, "ERROR: %s (%s)" % (extype, value)
+ # return 1 for "general error"
+ sys.exit(1)
Please sign in to comment.
Something went wrong with that request. Please try again.