1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#
# 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
# 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
#
#
# Load SMF constants and functions
if [[ -z "$SMF_FMRI" ]]; then
echo "this script can only be invoked by smf(7)"
exit $SMF_EXIT_ERR_NOSMF
fi
case "$1" in
'start')
# Handles mDNS depot startup
# retrieve the pkg_root property. If the variable is left empty
# pkg_root is /
if [[ $? -ne 0 ]]; then
"service: $SMF_FMRI"
exit $SMF_EXIT_ERR_CONFIG
fi
# make sure pkg_root ends with a /
if [[ $? -ne 0 ]]; then
pkg_root="${pkg_root}/"
fi
# adjust the PYTHONPATH to point to the current environment
# we need to make sure to adjust the PYTHONPATH accordingly
# to a Python 2.7 or 3.4 environment
python_ver=$(head -1 ${pkg_root}usr/lib/pkg.depotd 2>/dev/null |
if [[ $python_ver != *python* ]]; then
echo "invalid python version $python_ver found in"
echo "${pkg_root}usr/lib/pkg.depotd"
exit $SMF_EXIT_ERR_FATAL
fi
export PYTHONPATH
#
# If this process has net_privaddr, then we pass it along.
# If not, we ensure that we don't specify it, since that will
# cause ppriv to throw an error.
#
privaddr=""
if [[ $? == 0 ]]; then
echo "Dropping net_privaddr privilege."
privaddr=",net_privaddr"
fi
#
# Build up the privileges available starting with "basic". This
# provides some protection even when the depot runs as root.
#
wrapper="ppriv -s \
A=basic,-file_link_any,-proc_info,-proc_session$privaddr -e"
# Build the command to start pkg.depotd.
# Echo the command so that the log contains the command used to start
# the depot.
echo $cmd
exec $cmd
;;
'stop')
#
# Strategy: First, try shutting down depot using polite kill. Use up
# as much as possible of the allotted timeout period waiting for polite
# kill to take effect. As time runs out, try a more aggressive kill.
#
if [[ $? -ne 0 ]]; then
echo "service property stop/timeout_seconds not defined" \
"for service: $SMF_FMRI"
exit $SMF_EXIT_ERR_CONFIG
fi
#
# Note that we're working around an oddity in smf_kill_contract: it
# waits in 5 second chunks and can overshoot the specified timeout
# by as many as 4 seconds. Example: a specified wait of 6 will result
# in a wait of 10 seconds in reality. Since we may potentially do a
# first kill and then a second, we must ensure that at least 8 seconds
# of slop is left in reserve. To be paranoid, we go for 10.
#
ret=$?
# '2' indicates timeout with non-empty contract.
echo "Gentle contract kill timed out after" \
"$POLITE seconds, trying SIGKILL." >&2
#
# Again, despite the specified timeout, this will
# take a minimum of 5 seconds to complete.
#
exit $SMF_EXIT_ERR_FATAL
fi
fi
else
# If the timeout is too short, we just try once, politely.
fi
;;
*)
echo "Usage: $0 { start | stop }"
exit $SMF_EXIT_ERR_CONFIG
;;
esac
exit $SMF_EXIT_OK