cc-2055: switch to init.d

-allow install script to be created from any location (no hardcoded paths)
-make python install scripts return 1 on error
-daemon now started automatically on boot using rc.local autostart
-change all prints to logs instead
-create airtime-uninstall shell script (and remove pypo user in here)
-create pypo user in shell script
This commit is contained in:
martin 2011-06-01 12:32:42 -04:00
parent 079d9d36b0
commit 6ab5ac4582
23 changed files with 179 additions and 224 deletions

View file

@ -14,7 +14,7 @@ import shutil
import string
import platform
from configobj import ConfigObj
from subprocess import Popen, PIPE, STDOUT
from subprocess import Popen
if os.geteuid() != 0:
print "Please run this as root."
@ -27,27 +27,6 @@ def create_path(path):
print "Creating directory " + path
os.makedirs(path)
def create_user(username):
print "Checking for user "+username
p = Popen('id '+username, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
output = p.stdout.read()
if (output[0:3] != "uid"):
# Make the pypo user
print "Creating user "+username
os.system("adduser --system --quiet --group --shell /bin/bash "+username)
#set pypo password
p = os.popen('/usr/bin/passwd pypo 1>/dev/null 2>&1', 'w')
p.write('pypo\n')
p.write('pypo\n')
p.close()
else:
print "User already exists."
#add pypo to audio group
os.system("adduser " + username + " audio 1>/dev/null 2>&1")
#add pypo to www-data group
os.system("adduser " + username + " www-data 1>/dev/null 2>&1")
def copy_dir(src_dir, dest_dir):
if (os.path.exists(dest_dir)) and (dest_dir != "/"):
print "Removing old directory "+dest_dir
@ -59,7 +38,6 @@ def copy_dir(src_dir, dest_dir):
def get_current_script_dir():
current_script_dir = os.path.realpath(__file__)
index = current_script_dir.rindex('/')
#print current_script_dir[0:index]
return current_script_dir[0:index]
@ -69,18 +47,13 @@ try:
config = ConfigObj(PATH_INI_FILE)
except Exception, e:
print 'Error loading config file: ', e
sys.exit()
sys.exit(1)
current_script_dir = get_current_script_dir()
#print "Checking and removing any existing media monitor processes"
#os.system("python %s/media-monitor-uninstall.py 1>/dev/null 2>&1"% current_script_dir)
#time.sleep(5)
p = Popen("/etc/init.d/airtime-media-monitor stop", shell=True)
sts = os.waitpid(p.pid, 0)[1]
# Create users
create_user("pypo")
print "Creating log directories"
create_path(config["log_dir"])
os.system("chmod -R 755 " + config["log_dir"])
@ -98,6 +71,9 @@ try:
print "Installing media-monitor daemon"
shutil.copy(config["bin_dir"]+"/airtime-media-monitor-init-d", "/etc/init.d/airtime-media-monitor")
p = Popen("update-rc.d airtime-media-monitor defaults", shell=True)
sts = os.waitpid(p.pid, 0)[1]
print "Waiting for processes to start..."
p = Popen("/etc/init.d/airtime-media-monitor start", shell=True)