From 0ef528941ef7400c81047d6c397b9323e0f6d821 Mon Sep 17 00:00:00 2001 From: mkonecny Date: Fri, 17 Dec 2010 12:46:09 -0500 Subject: [PATCH 1/3] -added pypo uninstall script. -pypo-install script now gives OS a little time to create directories before attempting to work with them. --- pypo/install/pypo-install.py | 6 +++++ pypo/install/pypo-uninstall.py | 48 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 pypo/install/pypo-uninstall.py diff --git a/pypo/install/pypo-install.py b/pypo/install/pypo-install.py index da6d11835..8f91f33d3 100644 --- a/pypo/install/pypo-install.py +++ b/pypo/install/pypo-install.py @@ -91,6 +91,7 @@ try: shutil.copy("pypo-daemontools-logger.sh", "/etc/service/pypo-fetch/log/run") os.system("chmod -R 755 /etc/service/pypo-fetch") os.system("chown -R pypo:pypo /etc/service/pypo-fetch") + time.sleep(1) os.system("svc -t /etc/service/pypo-fetch") print "Installing daemontool script pypo-push" @@ -100,6 +101,7 @@ try: shutil.copy("pypo-daemontools-logger.sh", "/etc/service/pypo-push/log/run") os.system("chmod -R 755 /etc/service/pypo-push") os.system("chown -R pypo:pypo /etc/service/pypo-push") + time.sleep(1) os.system("svc -t /etc/service/pypo-push") print "Installing daemontool script pypo-liquidsoap" @@ -111,8 +113,12 @@ try: shutil.copy("pypo-daemontools-logger.sh", "/etc/service/pypo-liquidsoap/log/run") os.system("chmod -R 755 /etc/service/pypo-liquidsoap") os.system("chown -R pypo:pypo /etc/service/pypo-liquidsoap") + time.sleep(1) os.system("svc -u /etc/service/pypo-liquidsoap") + print "Waiting for processes to start..." + time.sleep(2) + p = Popen('svstat /etc/service/pypo-fetch', shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) output = p.stdout.read() if (output.find("unable to open supervise/ok: file does not exist") >= 0): diff --git a/pypo/install/pypo-uninstall.py b/pypo/install/pypo-uninstall.py new file mode 100644 index 000000000..956ed7e38 --- /dev/null +++ b/pypo/install/pypo-uninstall.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import sys +import time + +if os.geteuid() != 0: + print "Please run this as root." + sys.exit(1) + +BASE_PATH = '/opt/pypo/' + +def remove_path(path): + os.system("rm -rf " + path) + +def remove_user(username): + os.system("killall -u " + username) + + #allow all process to be completely closed before we attempt to delete user + print "Waiting for processes to close..." + time.sleep(5) + + os.system("deluser --remove-home " + username) + #os.system("delgroup " + username) + +try: + print "Removing log directories" + remove_path("/var/log/pypo") + + print "Removing pypo files" + remove_path(BASE_PATH) + + print "Removing daemontool script pypo-fetch" + os.system("svc -dx /etc/service/pypo-fetch") + remove_path("rm -rf /etc/service/pypo-fetch") + + print "Removing daemontool script pypo-push" + os.system("svc -dx /etc/service/pypo-push") + remove_path("rm -rf /etc/service/pypo-push") + + print "Removing daemontool script pypo-liquidsoap" + os.system("svc -dx /etc/service/pypo-liquidsoap") + remove_path("rm -rf /etc/service/pypo-liquidsoap") + + remove_user("pypo") +except Exception, e: + print "exception:" + str(e) \ No newline at end of file From 1c16f6f9e7fb9a14d745bf522a0ee8b4ea0d10a9 Mon Sep 17 00:00:00 2001 From: mkonecny Date: Fri, 17 Dec 2010 14:15:53 -0500 Subject: [PATCH 2/3] -refactored pypo install and uninstall scripts into start/stop/install/uninstall scripts --- pypo/install/pypo-install.py | 12 ++++-------- pypo/install/pypo-start.py | 22 ++++++++++++++++++++++ pypo/install/pypo-stop.py | 22 ++++++++++++++++++++++ pypo/install/pypo-uninstall.py | 10 ++++++---- 4 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 pypo/install/pypo-start.py create mode 100644 pypo/install/pypo-stop.py diff --git a/pypo/install/pypo-install.py b/pypo/install/pypo-install.py index 8f91f33d3..0f7737ad3 100644 --- a/pypo/install/pypo-install.py +++ b/pypo/install/pypo-install.py @@ -43,7 +43,7 @@ def copy_dir(src_dir, dest_dir): if not (os.path.exists(dest_dir)): print "Copying directory "+src_dir+" to "+dest_dir shutil.copytree(src_dir, dest_dir) - + try: # Create users create_user("pypo") @@ -91,9 +91,7 @@ try: shutil.copy("pypo-daemontools-logger.sh", "/etc/service/pypo-fetch/log/run") os.system("chmod -R 755 /etc/service/pypo-fetch") os.system("chown -R pypo:pypo /etc/service/pypo-fetch") - time.sleep(1) - os.system("svc -t /etc/service/pypo-fetch") - + print "Installing daemontool script pypo-push" create_path("/etc/service/pypo-push") create_path("/etc/service/pypo-push/log") @@ -101,8 +99,6 @@ try: shutil.copy("pypo-daemontools-logger.sh", "/etc/service/pypo-push/log/run") os.system("chmod -R 755 /etc/service/pypo-push") os.system("chown -R pypo:pypo /etc/service/pypo-push") - time.sleep(1) - os.system("svc -t /etc/service/pypo-push") print "Installing daemontool script pypo-liquidsoap" os.system("svc -dk /etc/service/pypo-liquidsoap") @@ -113,10 +109,10 @@ try: shutil.copy("pypo-daemontools-logger.sh", "/etc/service/pypo-liquidsoap/log/run") os.system("chmod -R 755 /etc/service/pypo-liquidsoap") os.system("chown -R pypo:pypo /etc/service/pypo-liquidsoap") - time.sleep(1) - os.system("svc -u /etc/service/pypo-liquidsoap") print "Waiting for processes to start..." + time.sleep(5) + os.system("python ./pypo-start.py") time.sleep(2) p = Popen('svstat /etc/service/pypo-fetch', shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) diff --git a/pypo/install/pypo-start.py b/pypo/install/pypo-start.py new file mode 100644 index 000000000..abc80bbc5 --- /dev/null +++ b/pypo/install/pypo-start.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import sys + +if os.geteuid() != 0: + print "Please run this as root." + sys.exit(1) + +try: + print "Starting daemontool script pypo-fetch" + os.system("svc -t /etc/service/pypo-fetch") + + print "Starting daemontool script pypo-push" + os.system("svc -t /etc/service/pypo-push") + + print "Starting daemontool script pypo-liquidsoap" + os.system("svc -t /etc/service/pypo-liquidsoap") + +except Exception, e: + print "exception:" + str(e) \ No newline at end of file diff --git a/pypo/install/pypo-stop.py b/pypo/install/pypo-stop.py new file mode 100644 index 000000000..6e055b6b1 --- /dev/null +++ b/pypo/install/pypo-stop.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import sys + +if os.geteuid() != 0: + print "Please run this as root." + sys.exit(1) + +try: + print "Stopping daemontool script pypo-fetch" + os.system("svc -dx /etc/service/pypo-fetch") + + print "Stopping daemontool script pypo-push" + os.system("svc -dx /etc/service/pypo-push") + + print "Stopping daemontool script pypo-liquidsoap" + os.system("svc -dx /etc/service/pypo-liquidsoap") + +except Exception, e: + print "exception:" + str(e) \ No newline at end of file diff --git a/pypo/install/pypo-uninstall.py b/pypo/install/pypo-uninstall.py index 956ed7e38..f3dcfb079 100644 --- a/pypo/install/pypo-uninstall.py +++ b/pypo/install/pypo-uninstall.py @@ -21,10 +21,15 @@ def remove_user(username): print "Waiting for processes to close..." time.sleep(5) + os.system("delgroup " + username) os.system("deluser --remove-home " + username) + + #pypo group appears to be deleted when removing user. #os.system("delgroup " + username) try: + os.system("python ./pypo-stop.py") + print "Removing log directories" remove_path("/var/log/pypo") @@ -32,17 +37,14 @@ try: remove_path(BASE_PATH) print "Removing daemontool script pypo-fetch" - os.system("svc -dx /etc/service/pypo-fetch") remove_path("rm -rf /etc/service/pypo-fetch") print "Removing daemontool script pypo-push" - os.system("svc -dx /etc/service/pypo-push") remove_path("rm -rf /etc/service/pypo-push") print "Removing daemontool script pypo-liquidsoap" - os.system("svc -dx /etc/service/pypo-liquidsoap") remove_path("rm -rf /etc/service/pypo-liquidsoap") - remove_user("pypo") + #remove_user("pypo") except Exception, e: print "exception:" + str(e) \ No newline at end of file From afd9f80f59e6b83e09449ea1a2627a5918f24981 Mon Sep 17 00:00:00 2001 From: mkonecny Date: Fri, 17 Dec 2010 15:39:36 -0500 Subject: [PATCH 3/3] -removed errors and warning from displaying in the console during pypo install/uninstall --- pypo/install/pypo-install.py | 4 ++-- pypo/install/pypo-uninstall.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pypo/install/pypo-install.py b/pypo/install/pypo-install.py index 0f7737ad3..7634e1263 100644 --- a/pypo/install/pypo-install.py +++ b/pypo/install/pypo-install.py @@ -101,7 +101,7 @@ try: os.system("chown -R pypo:pypo /etc/service/pypo-push") print "Installing daemontool script pypo-liquidsoap" - os.system("svc -dk /etc/service/pypo-liquidsoap") + os.system("svc -dk /etc/service/pypo-liquidsoap > /dev/null 2>&1") os.system("killall liquidsoap") create_path("/etc/service/pypo-liquidsoap") create_path("/etc/service/pypo-liquidsoap/log") @@ -132,7 +132,7 @@ try: #os.symlink(BASE_PATH+"bin/pypo-log.sh", "/usr/local/bin/") - + print "Install complete." except Exception, e: print "exception:" + str(e) diff --git a/pypo/install/pypo-uninstall.py b/pypo/install/pypo-uninstall.py index f3dcfb079..c50c91abe 100644 --- a/pypo/install/pypo-uninstall.py +++ b/pypo/install/pypo-uninstall.py @@ -21,8 +21,7 @@ def remove_user(username): print "Waiting for processes to close..." time.sleep(5) - os.system("delgroup " + username) - os.system("deluser --remove-home " + username) + os.system("deluser --remove-home " + username + " > /dev/null") #pypo group appears to be deleted when removing user. #os.system("delgroup " + username) @@ -45,6 +44,7 @@ try: print "Removing daemontool script pypo-liquidsoap" remove_path("rm -rf /etc/service/pypo-liquidsoap") - #remove_user("pypo") + remove_user("pypo") + print "Uninstall complete." except Exception, e: print "exception:" + str(e) \ No newline at end of file