summaryrefslogtreecommitdiff
path: root/elements/os-svc-install
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-01-05 17:29:44 +0000
committerGerrit Code Review <review@openstack.org>2015-01-05 17:29:44 +0000
commita39ec21014d724ad4d636df9e5ebadd8b63336ed (patch)
tree9321570dbf4b2819d46aa00160a34e9c3ba9480d /elements/os-svc-install
parent69d4bbc94b0e5c9e23c2e4258aeafa8dfac00877 (diff)
parent5fc2040aa5e8bb146b9b220ded376ca49a1995f9 (diff)
Merge "Log directly to syslog from os services"
Diffstat (limited to 'elements/os-svc-install')
-rwxr-xr-xelements/os-svc-install/bin/os-svc-daemon49
1 files changed, 44 insertions, 5 deletions
diff --git a/elements/os-svc-install/bin/os-svc-daemon b/elements/os-svc-install/bin/os-svc-daemon
index 0092a3d..f3711d4 100755
--- a/elements/os-svc-install/bin/os-svc-daemon
+++ b/elements/os-svc-install/bin/os-svc-daemon
@@ -8,11 +8,13 @@ usage() {
8 echo "" 8 echo ""
9 echo "SERVICENAME, RUNAS, RUNCMD, and POSTSTART can be set via the" 9 echo "SERVICENAME, RUNAS, RUNCMD, and POSTSTART can be set via the"
10 echo "environment as well. Command line arguments will override" 10 echo "environment as well. Command line arguments will override"
11 echo "environment variables." 11 echo "environment variables. By default this will create a python logging"
12 echo "configuration file in /etc/os-logging/servicename.conf"
12 echo "" 13 echo ""
13 echo " -a Use alternate svc-map instead of map-services" 14 echo " -a Use alternate svc-map instead of map-services"
14 echo " -h Show help and exit" 15 echo " -h Show help and exit"
15 echo " -p Print the job file instead of writing to disk" 16 echo " -p Print the job file instead of writing to disk"
17 echo " -l Create neither a python logging.conf nor pass --log-config-append argument to command."
16 echo " -d [NAME] Specify the name of the runtime directory, which will be" 18 echo " -d [NAME] Specify the name of the runtime directory, which will be"
17 echo " /var/run/[NAME]" 19 echo " /var/run/[NAME]"
18 echo " -s POSTSTART post_start will be added to the upstart job. Ignored with systemd." 20 echo " -s POSTSTART post_start will be added to the upstart job. Ignored with systemd."
@@ -32,6 +34,7 @@ INSTALLDIR=
32RUNAS=${RUNAS:-""} 34RUNAS=${RUNAS:-""}
33RUNCMD=${RUNCMD:-""} 35RUNCMD=${RUNCMD:-""}
34ENV=${ENV:-""} 36ENV=${ENV:-""}
37DISABLE_LOGGING_CONF=
35CREATE_DIR_NAME=${CREATE_DIR_NAME:-""} 38CREATE_DIR_NAME=${CREATE_DIR_NAME:-""}
36# The default helps avoid race with daemon listening. http://pad.lv/1179766 39# The default helps avoid race with daemon listening. http://pad.lv/1179766
37POSTSTART=${POSTSTART:-$DEFAULT_POSTSTART} 40POSTSTART=${POSTSTART:-$DEFAULT_POSTSTART}
@@ -53,7 +56,7 @@ OUTPUT=print_to_file
53APPEND=append_to_file 56APPEND=append_to_file
54 57
55nshift=0 58nshift=0
56while getopts "aphd:s:n:i:u:c:e:" opt; do 59while getopts "aplhd:s:n:i:u:c:e:" opt; do
57 case "$opt" in 60 case "$opt" in
58 n) SERVICENAME=$OPTARG;; 61 n) SERVICENAME=$OPTARG;;
59 i) INSTALLDIR=$OPTARG;; 62 i) INSTALLDIR=$OPTARG;;
@@ -63,6 +66,7 @@ while getopts "aphd:s:n:i:u:c:e:" opt; do
63 e) ENV=$OPTARG;; 66 e) ENV=$OPTARG;;
64 a) MAPPING_COMMAND=svc-map;; 67 a) MAPPING_COMMAND=svc-map;;
65 p) OUTPUT=print_only; APPEND=print_only;; 68 p) OUTPUT=print_only; APPEND=print_only;;
69 l) DISABLE_LOGGING_CONF="1";;
66 d) CREATE_DIR_NAME=$OPTARG;; 70 d) CREATE_DIR_NAME=$OPTARG;;
67 h) usage; exit 0;; 71 h) usage; exit 0;;
68 \?) usage; exit 1;; 72 \?) usage; exit 1;;
@@ -108,6 +112,33 @@ if [ -z "$INSTALLDIR" ]; then
108 INSTALLDIR="/opt/stack/venvs/$RUNAS" 112 INSTALLDIR="/opt/stack/venvs/$RUNAS"
109fi 113fi
110 114
115if [ -z "$DISABLE_LOGGING_CONF" ]; then
116 # Set up service-specific logging config
117 LOGGING_CONFIG="/etc/os-logging/$SERVICENAME.config"
118 mkdir /etc/os-logging || true
119 $OUTPUT $LOGGING_CONFIG <<EOF
120[loggers]
121keys=root
122
123[handlers]
124keys=syslog
125
126[formatters]
127keys=normal
128
129[logger_root]
130handlers=syslog
131
132[handler_syslog]
133class=handlers.SysLogHandler
134args=('/dev/log', handlers.SysLogHandler.LOG_USER)
135formatter=normal
136
137[formatter_normal]
138format=$SERVICENAME: %(asctime)s %(levelname)s %(message)s
139EOF
140fi
141
111function install_upstart { 142function install_upstart {
112 local name=$1 143 local name=$1
113 local install_dir=$2 144 local install_dir=$2
@@ -125,6 +156,10 @@ env }
125 fi 156 fi
126 local target_file="/etc/init/$name.conf" 157 local target_file="/etc/init/$name.conf"
127 158
159 if [ -z "$DISABLE_LOGGING_CONF" ]; then
160 args="--log-config-append $LOGGING_CONFIG $args"
161 fi
162
128 $OUTPUT $target_file <<EOF 163 $OUTPUT $target_file <<EOF
129start on runlevel [2345] 164start on runlevel [2345]
130stop on runlevel [016] 165stop on runlevel [016]
@@ -144,13 +179,13 @@ EOF
144 179
145respawn 180respawn
146# the default post-start of 1 second sleep delays respawning enough to 181# the default post-start of 1 second sleep delays respawning enough to
147# not hit the default of 10 times in 5 seconds. Make it 2 times in 5s. 182# not hit the default of 10 times in 5 seconds. Make it 2 times in 10s.
148respawn limit 2 5 183respawn limit 2 10
149 184
150# We're logging to syslog 185# We're logging to syslog
151console none 186console none
152 187
153exec start-stop-daemon --start -c $user --exec $install_dir/bin/$cmd -- $args 2>&1 | logger -t $name 188exec start-stop-daemon --start -c $user --exec $install_dir/bin/$cmd -- $args
154 189
155post-start $POSTSTART 190post-start $POSTSTART
156EOF 191EOF
@@ -172,6 +207,10 @@ function install_systemd {
172Environment=} 207Environment=}
173 fi 208 fi
174 209
210 if [ -z "$DISABLE_LOGGING_CONF" ]; then
211 args="--log-config-append $LOGGING_CONFIG $args"
212 fi
213
175 $OUTPUT /lib/systemd/system/$name.service <<EOF 214 $OUTPUT /lib/systemd/system/$name.service <<EOF
176[Unit] 215[Unit]
177Description=$name Service 216Description=$name Service