Browse Source

Merge "Log directly to syslog from os services"

Jenkins 4 years ago
parent
commit
a39ec21014

+ 44
- 5
elements/os-svc-install/bin/os-svc-daemon View File

@@ -8,11 +8,13 @@ usage() {
8 8
     echo ""
9 9
     echo "SERVICENAME, RUNAS, RUNCMD, and POSTSTART can be set via the"
10 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 13
     echo ""
13 14
     echo "  -a             Use alternate svc-map instead of map-services"
14 15
     echo "  -h             Show help and exit"
15 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 18
     echo "  -d [NAME]      Specify the name of the runtime directory, which will be"
17 19
     echo "                 /var/run/[NAME]"
18 20
     echo "  -s POSTSTART   post_start will be added to the upstart job. Ignored with systemd."
@@ -32,6 +34,7 @@ INSTALLDIR=
32 34
 RUNAS=${RUNAS:-""}
33 35
 RUNCMD=${RUNCMD:-""}
34 36
 ENV=${ENV:-""}
37
+DISABLE_LOGGING_CONF=
35 38
 CREATE_DIR_NAME=${CREATE_DIR_NAME:-""}
36 39
 # The default helps avoid race with daemon listening. http://pad.lv/1179766
37 40
 POSTSTART=${POSTSTART:-$DEFAULT_POSTSTART}
@@ -53,7 +56,7 @@ OUTPUT=print_to_file
53 56
 APPEND=append_to_file
54 57
 
55 58
 nshift=0
56
-while getopts "aphd:s:n:i:u:c:e:" opt; do
59
+while getopts "aplhd:s:n:i:u:c:e:" opt; do
57 60
     case "$opt" in
58 61
         n) SERVICENAME=$OPTARG;;
59 62
         i) INSTALLDIR=$OPTARG;;
@@ -63,6 +66,7 @@ while getopts "aphd:s:n:i:u:c:e:" opt; do
63 66
         e) ENV=$OPTARG;;
64 67
         a) MAPPING_COMMAND=svc-map;;
65 68
         p) OUTPUT=print_only; APPEND=print_only;;
69
+        l) DISABLE_LOGGING_CONF="1";;
66 70
         d) CREATE_DIR_NAME=$OPTARG;;
67 71
         h) usage; exit 0;;
68 72
         \?) usage; exit 1;;
@@ -108,6 +112,33 @@ if [ -z "$INSTALLDIR" ]; then
108 112
     INSTALLDIR="/opt/stack/venvs/$RUNAS"
109 113
 fi
110 114
 
115
+if [ -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]
121
+keys=root
122
+
123
+[handlers]
124
+keys=syslog
125
+
126
+[formatters]
127
+keys=normal
128
+
129
+[logger_root]
130
+handlers=syslog
131
+
132
+[handler_syslog]
133
+class=handlers.SysLogHandler
134
+args=('/dev/log', handlers.SysLogHandler.LOG_USER)
135
+formatter=normal
136
+
137
+[formatter_normal]
138
+format=$SERVICENAME: %(asctime)s %(levelname)s %(message)s
139
+EOF
140
+fi
141
+
111 142
 function install_upstart {
112 143
     local name=$1
113 144
     local install_dir=$2
@@ -125,6 +156,10 @@ env }
125 156
     fi
126 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 163
     $OUTPUT $target_file <<EOF
129 164
 start on runlevel [2345]
130 165
 stop on runlevel [016]
@@ -144,13 +179,13 @@ EOF
144 179
 
145 180
 respawn
146 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.
148
-respawn limit 2 5
182
+# not hit the default of 10 times in 5 seconds. Make it 2 times in 10s.
183
+respawn limit 2 10
149 184
 
150 185
 # We're logging to syslog
151 186
 console none
152 187
 
153
-exec start-stop-daemon --start -c $user --exec $install_dir/bin/$cmd -- $args 2>&1 | logger -t $name
188
+exec start-stop-daemon --start -c $user --exec $install_dir/bin/$cmd -- $args
154 189
 
155 190
 post-start $POSTSTART
156 191
 EOF
@@ -172,6 +207,10 @@ function install_systemd {
172 207
 Environment=}
173 208
     fi
174 209
 
210
+    if [ -z "$DISABLE_LOGGING_CONF" ]; then
211
+        args="--log-config-append $LOGGING_CONFIG $args"
212
+    fi
213
+
175 214
     $OUTPUT /lib/systemd/system/$name.service <<EOF
176 215
 [Unit]
177 216
 Description=$name Service

+ 1
- 1
elements/swift-proxy/install.d/swift-source-install/76-swift-proxy View File

@@ -10,6 +10,6 @@ $SWIFT_VENV_DIR/bin/pip install keystonemiddleware
10 10
 $SWIFT_VENV_DIR/bin/pip install python-swiftclient
11 11
 $SWIFT_VENV_DIR/bin/pip install pycrypto
12 12
 
13
-os-svc-daemon -i "$SWIFT_VENV_DIR" swift-proxy swift swift-proxy-server "/etc/swift/proxy-server.conf"
13
+os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-proxy swift swift-proxy-server "/etc/swift/proxy-server.conf"
14 14
 
15 15
 ln -s $SWIFT_VENV_DIR/bin/swift-recon /usr/local/bin/swift-recon

+ 13
- 13
elements/swift-storage/install.d/swift-source-install/76-swift-storage View File

@@ -2,20 +2,20 @@
2 2
 
3 3
 set -eux
4 4
 
5
-os-svc-daemon -i "$SWIFT_VENV_DIR" swift-account swift swift-account-server /etc/swift/account-server.conf
6
-os-svc-daemon -i "$SWIFT_VENV_DIR" swift-account-auditor swift swift-account-auditor /etc/swift/account-server.conf
7
-os-svc-daemon -i "$SWIFT_VENV_DIR" swift-account-reaper swift swift-account-reaper /etc/swift/account-server.conf
8
-os-svc-daemon -i "$SWIFT_VENV_DIR" swift-account-replicator swift swift-account-replicator /etc/swift/account-server.conf
5
+os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-account swift swift-account-server /etc/swift/account-server.conf
6
+os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-account-auditor swift swift-account-auditor /etc/swift/account-server.conf
7
+os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-account-reaper swift swift-account-reaper /etc/swift/account-server.conf
8
+os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-account-replicator swift swift-account-replicator /etc/swift/account-server.conf
9 9
 
10
-os-svc-daemon -i "$SWIFT_VENV_DIR" swift-container swift swift-container-server /etc/swift/container-server.conf
11
-os-svc-daemon -i "$SWIFT_VENV_DIR" swift-container-auditor swift swift-container-auditor /etc/swift/container-server.conf
12
-os-svc-daemon -i "$SWIFT_VENV_DIR" swift-container-replicator swift swift-container-replicator /etc/swift/container-server.conf
13
-os-svc-daemon -i "$SWIFT_VENV_DIR" swift-container-sync swift swift-container-sync /etc/swift/container-server.conf
14
-os-svc-daemon -i "$SWIFT_VENV_DIR" swift-container-updater swift swift-container-updater /etc/swift/container-server.conf
10
+os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-container swift swift-container-server /etc/swift/container-server.conf
11
+os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-container-auditor swift swift-container-auditor /etc/swift/container-server.conf
12
+os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-container-replicator swift swift-container-replicator /etc/swift/container-server.conf
13
+os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-container-sync swift swift-container-sync /etc/swift/container-server.conf
14
+os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-container-updater swift swift-container-updater /etc/swift/container-server.conf
15 15
 
16
-os-svc-daemon -i "$SWIFT_VENV_DIR" swift-object swift swift-object-server /etc/swift/object-server.conf
17
-os-svc-daemon -i "$SWIFT_VENV_DIR" swift-object-auditor swift swift-object-auditor /etc/swift/object-server.conf
18
-os-svc-daemon -i "$SWIFT_VENV_DIR" swift-object-replicator swift swift-object-replicator /etc/swift/object-server.conf
19
-os-svc-daemon -i "$SWIFT_VENV_DIR" swift-object-updater swift swift-object-updater /etc/swift/object-server.conf
16
+os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-object swift swift-object-server /etc/swift/object-server.conf
17
+os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-object-auditor swift swift-object-auditor /etc/swift/object-server.conf
18
+os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-object-replicator swift swift-object-replicator /etc/swift/object-server.conf
19
+os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-object-updater swift swift-object-updater /etc/swift/object-server.conf
20 20
 
21 21
 ln -s $SWIFT_VENV_DIR/bin/swift-recon-cron /usr/local/bin/swift-recon-cron

Loading…
Cancel
Save