2717 pkg.depotd: need smf support for depot mode options
authorBrock Pytlik <bpytlik@sun.com>
Mon, 03 Nov 2008 06:14:48 -0800
changeset 661 edf14bae4465
parent 660 ea2809ad4582
child 662 b9632e3d7b26
2717 pkg.depotd: need smf support for depot mode options
src/man/pkg.depotd.1m.txt
src/pkg-server.xml
src/setup.py
src/svc-pkg-depot
--- a/src/man/pkg.depotd.1m.txt	Mon Nov 03 14:04:30 2008 +0000
+++ b/src/man/pkg.depotd.1m.txt	Mon Nov 03 06:14:48 2008 -0800
@@ -46,6 +46,13 @@
                                 stdout, none, or an absolute pathname.
                                 The default value is stderr.
 
+     pkg/mirror                 (boolean) Sets whether package mirror mode 
+                                is used. When true, publishing and metadata
+                                operations are disabled and only a limited
+                                browser user interface is provided. This
+                                property may not be true when pkg/readonly is
+                                true. The default value is false.
+
      pkg/port                   (count) The port number on which the
                                 instance should listen for incoming
                                 package requests.  The default value is
@@ -57,6 +64,13 @@
                                 webserver in a reverse proxy
                                 configuration.
 
+     pkg/readonly               (boolean) Sets whether modifying operations, 
+                                such as those initiated by pkgsend(1M) are 
+                                disabled. Retrieval operations are still 
+                                available. This property may not be true
+                                when pkg/mirror is true. The default value
+                                is false.
+
      pkg/socket_timeout         (count) The maximum number of seconds the
                                 server should wait for a response from a
                                 client before closing a connection.  The
@@ -92,22 +106,13 @@
      --content-root root_dir    Overrides pkg/content_root with the value
                                 given by root_dir.
 
-     --mirror                   Package mirror mode; publishing and
-                                metadata operations are disabled and
-                                only a limited browser user interface is
-                                provided.  This option may not be
-                                combined with the --readonly or
-                                --rebuild options.
+     --mirror                   Overrides pkg/mirror and sets it to be true.
 
      --proxy-base url           Overrides pkg/proxy_base with the value
                                 given by url.  Ignored if empty value is
                                 provided.
 
-     --readonly                 Modifying operations, such as those
-                                initiated by pkgsend(1M) are disabled.
-                                Retrieval operations are still available.
-                                This option may not be combined with the
-                                --mirror or --rebuild options.
+     --readonly                 Overrides pkg/readonly and sets it to be true.
 
      --rebuild                  Any existing repository catalog will be
                                 destroyed and then recreated on startup.
--- a/src/pkg-server.xml	Mon Nov 03 14:04:30 2008 +0000
+++ b/src/pkg-server.xml	Mon Nov 03 06:14:48 2008 -0800
@@ -39,8 +39,6 @@
 
 	<create_default_instance enabled='false' />
 
-	<single_instance/>
-
 	<dependency
 		name='fs'
 		grouping='require_all'
@@ -85,7 +83,7 @@
 	<exec_method
 		type='method'
 		name='start'
-		exec='/usr/lib/pkg.depotd -d %{pkg/inst_root} -p %{pkg/port} -s %{pkg/threads} -t %{pkg/socket_timeout} --content-root=%{pkg/content_root} --log-access=%{pkg/log_access} --log-errors=%{pkg/log_errors} --proxy-base=%{pkg/proxy_base}'
+                exec='/lib/svc/method/svc-pkg-depot start'
 		timeout_seconds='0' />
 
 	<exec_method
@@ -111,6 +109,8 @@
 			value='none' />
 		<propval name='log_errors' type='astring'
 			value='stderr' />
+		<propval name='mirror' type='boolean' value='false'/>
+		<propval name='readonly' type='boolean' value='false'/>
 	</property_group>
 
 	<stability value='Unstable' />
--- a/src/setup.py	Mon Nov 03 14:04:30 2008 +0000
+++ b/src/setup.py	Mon Nov 03 06:14:48 2008 -0800
@@ -96,6 +96,7 @@
 
 scripts_dir = 'usr/bin'
 lib_dir = 'usr/lib'
+svc_method_dir = 'lib/svc/method'
 
 man1_dir = 'usr/share/man/cat1'
 man1m_dir = 'usr/share/man/cat1m'
@@ -117,6 +118,9 @@
                 ['depot.py', 'pkg.depotd'],
                 ['updatemanagernotifier.py', 'updatemanagernotifier'],
                 ],
+        svc_method_dir: [
+                ['svc-pkg-depot', 'svc-pkg-depot'],
+                ],
         }
             
 scripts_windows = {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/svc-pkg-depot	Mon Nov 03 06:14:48 2008 -0800
@@ -0,0 +1,123 @@
+#!/usr/bin/ksh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+
+# Load SMF constants and functions
+. /lib/svc/share/smf_include.sh
+
+if [[ -z "$SMF_FMRI" ]]; then
+	echo "this script can only be invoked by smf(5)"	
+	exit $SMF_EXIT_ERR_NOSMF
+fi
+
+case "$1" in
+'start')
+	# Handles depot startup
+
+	# boolean_props are properties which are communicated to the depot
+	# via a flag being present or absent on the command line.
+	boolean_props="mirror readonly"
+	set -A boolean_cmd_line "mirror" "readonly"
+
+	# short_option_props are properties which are communicated to the depot
+	# via a single character flag which takes an argument.
+	short_option_props="inst_root port threads socket_timeout"
+	set -A short_option_cmd_line "d" "p" "s" "t"
+
+	# short_option_props are properties which are communicated to the depot
+	# via a long option flag which takes an argument.
+	long_option_props="content_root log_access log_errors proxy_base"
+	set -A long_option_cmd_line "content-root" "log-access" \
+            "log-errors" "proxy-base"
+
+	bool_ops=""
+	option_props=""
+
+	# Go through each property in boolean_props and, if its value is set
+	# to true in SMF, add the appropriate command line flag to the string.
+	cnt=0
+	for b in $boolean_props; do
+	    val=$(svcprop -p pkg/$b $SMF_FMRI)
+	    if [[ $? -ne 0 ]]; then
+		echo "service property pkg/$b not defined for service: $SMF_FMRI"
+		exit $SMF_EXIT_ERR_CONFIG
+	    fi
+	    # If the property is set to true, add the flag.
+	    if [[ $val == 'true' ]]; then
+		bool_ops="$bool_ops --${boolean_cmd_line[$cnt]}"
+	    fi
+	    cnt=$(($cnt + 1))
+	done
+
+	# Go through each property in short_option_props and, if its value is
+	# set to something other than none, add the appropriate command line
+        # flag and argument to the string.
+	cnt=0
+	for o in $short_option_props; do
+	    val=$(svcprop -p pkg/$o $SMF_FMRI)
+	    if [[ $? -ne 0 ]]; then
+		echo "service property pkg/$o not defined for service: $SMF_FMRI"
+		exit $SMF_EXIT_ERR_CONFIG
+	    fi
+	    # If the SMF property is set to something other than 'none', add 
+            # the flag and its argument to the command.
+	    if [[ $val != '""' ]]; then
+		option_ops="$option_ops -${short_option_cmd_line[$cnt]} $val"
+	    fi
+	    cnt=$(($cnt + 1))
+	done
+
+	# Go through each property in long_option_props and, if its value is
+	# set to something other than none, add the appropriate command line
+        # flag and argument to the string.
+	cnt=0
+	for o in $long_option_props; do
+	    val=$(svcprop -p pkg/$o $SMF_FMRI)
+	    if [[ $? -ne 0 ]]; then
+		echo "service property pkg/$o not defined for service: $SMF_FMRI"
+		exit $SMF_EXIT_ERR_CONFIG
+	    fi
+	    # If the SMF property is set to something other than 'none', add
+            # the flag and its argument to the command.
+	    if [[ $val != '""' ]]; then
+		option_ops="$option_ops --${long_option_cmd_line[$cnt]}=$val"
+	    fi
+	    cnt=$(($cnt + 1))
+	done
+
+	# Build the command to start pkg.depotd with the specified options.
+	cmd="/usr/lib/pkg.depotd $bool_ops $option_ops"
+	# Echo the command so that the log contains the command used to start
+	# the depot.
+	echo $cmd
+
+	exec $cmd
+
+	;;
+*)
+	echo "Usage: $0 start"
+	exit $SMF_EXIT_ERR_CONFIG
+	;;
+
+esac
+exit $SMF_EXIT_OK