[CalendarServer-changes] [13964] CalendarServer/trunk/calendarserver/tools/config.py
source_changes at macosforge.org
source_changes at macosforge.org
Mon Sep 15 13:03:36 PDT 2014
Revision: 13964
http://trac.calendarserver.org//changeset/13964
Author: sagen at apple.com
Date: 2014-09-15 13:03:36 -0700 (Mon, 15 Sep 2014)
Log Message:
-----------
Adds --stop --start and --restart to calendarserver_config
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/config.py
Modified: CalendarServer/trunk/calendarserver/tools/config.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/config.py 2014-09-15 20:03:34 UTC (rev 13963)
+++ CalendarServer/trunk/calendarserver/tools/config.py 2014-09-15 20:03:36 UTC (rev 13964)
@@ -25,6 +25,7 @@
import os
import plistlib
import signal
+import subprocess
import sys
import xml
@@ -78,6 +79,8 @@
]
+
+
def usage(e=None):
if e:
print(e)
@@ -90,6 +93,9 @@
print("options:")
print(" -h --help: print this help and exit")
print(" -f --config: Specify caldavd.plist configuration path")
+ print(" -r --restart: Restart the calendar service")
+ print(" --start: Start the calendar service and agent")
+ print(" --stop: Stop the calendar service and agent")
print(" -w --writeconfig: Specify caldavd.plist configuration path for writing")
if e:
@@ -102,10 +108,13 @@
def main():
try:
(optargs, args) = getopt(
- sys.argv[1:], "hf:w:", [
+ sys.argv[1:], "hf:rw:", [
"help",
"config=",
"writeconfig=",
+ "restart",
+ "start",
+ "stop",
],
)
except GetoptError, e:
@@ -113,6 +122,9 @@
configFileName = DEFAULT_CONFIG_FILE
writeConfigFileName = ""
+ doStop = False
+ doStart = False
+ doRestart = False
for opt, arg in optargs:
if opt in ("-h", "--help"):
@@ -124,6 +136,15 @@
elif opt in ("-w", "--writeconfig"):
writeConfigFileName = arg
+ if opt == "--stop":
+ doStop = True
+
+ if opt == "--start":
+ doStart = True
+
+ if opt in ("-r", "--restart"):
+ doRestart = True
+
try:
config.load(configFileName)
except ConfigurationError, e:
@@ -139,13 +160,76 @@
if not writeConfigFileName:
writeConfigFileName = configFileName
+ if doStop:
+ setServiceState("org.calendarserver.agent", "disable")
+ setServiceState("org.calendarserver.calendarserver", "disable")
+ setEnabled(False)
+
+ if doStart:
+ setServiceState("org.calendarserver.agent", "enable")
+ setServiceState("org.calendarserver.calendarserver", "enable")
+ setEnabled(True)
+
+ if doStart or doStop:
+ setReverseProxies()
+ sys.exit(0)
+
+ if doRestart:
+ restartService(config.PIDFile)
+ sys.exit(0)
+
writable = WritableConfig(config, writeConfigFileName)
writable.read()
processArgs(writable, args)
+def setServiceState(service, state):
+ """
+ Invoke serverctl to enable/disable a service
+ """
+ SERVERCTL = "/Applications/Server.app/Contents/ServerRoot/usr/sbin/serverctl"
+ child = subprocess.Popen(
+ args=[SERVERCTL, state, "service={}".format(service)],
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ )
+ output, error = child.communicate()
+ if child.returncode:
+ sys.stdout.write(
+ "Error from serverctl: %d, %s" % (child.returncode, error)
+ )
+
+def setEnabled(enabled):
+ command = {
+ "command": "writeConfig",
+ "Values": {
+ "EnableCalDAV": enabled,
+ "EnableCardDAV": enabled,
+ },
+ }
+
+ runner = Runner([command], quiet=True)
+ runner.run()
+
+
+def setReverseProxies():
+ """
+ Invoke calendarserver_reverse_proxies
+ """
+ SERVERCTL = "/Applications/Server.app/Contents/ServerRoot/usr/libexec/calendarserver_reverse_proxies"
+ child = subprocess.Popen(
+ args=[SERVERCTL, ],
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ )
+ child.communicate()
+
+
+
def processArgs(writable, args, restart=True):
"""
Perform the read/write operations requested in the command line args.
@@ -207,12 +291,13 @@
dictionaries with a "command" key, plus command-specific data.
"""
- def __init__(self, commands):
+ def __init__(self, commands, quiet=False):
"""
@param commands: the commands to run
@type commands: list of plist strings
"""
self.commands = commands
+ self.quiet = quiet
def validate(self):
@@ -291,7 +376,8 @@
respond(command, {"error": str(e)})
else:
config.reload()
- self.command_readConfig(command)
+ if not self.quiet:
+ self.command_readConfig(command)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140915/6779e8b0/attachment.html>
More information about the calendarserver-changes
mailing list