Browse code

Default developer use case to systemd

This moves the developer use case over to systemd, and updates all the
relevant docs to discuss the systemd workflow instead of screen. It
does so by defaulting USE_SCREEN=False, so will not impact people that
set it explicitly.

Change-Id: I6d664612bc2b850eb7f56852afbc841867223ab7

Sean Dague authored on 2017/05/02 19:14:11
Showing 8 changed files
1 1
deleted file mode 100644
... ...
@@ -1,189 +0,0 @@
1
-===========================
2
- Using Systemd in DevStack
3
-===========================
4
-
5
-.. note::
6
-
7
-   This is an in progress document as we work out the way forward here
8
-   with DevStack and systemd.
9
-
10
-DevStack can be run with all the services as systemd unit
11
-files. Systemd is now the default init system for nearly every Linux
12
-distro, and systemd encodes and solves many of the problems related to
13
-poorly running processes.
14
-
15
-Why this instead of screen?
16
-===========================
17
-
18
-The screen model for DevStack was invented when the number of services
19
-that a DevStack user was going to run was typically < 10. This made
20
-screen hot keys to jump around very easy. However, the landscape has
21
-changed (not all services are stoppable in screen as some are under
22
-Apache, there are typically at least 20 items)
23
-
24
-There is also a common developer workflow of changing code in more
25
-than one service, and needing to restart a bunch of services for that
26
-to take effect.
27
-
28
-To enable this add the following to your local.conf::
29
-
30
-  USE_SYSTEMD=True
31
-
32
-
33
-
34
-Unit Structure
35
-==============
36
-
37
-.. note::
38
-
39
-   Originally we actually wanted to do this as user units, however
40
-   there are issues with running this under non interactive
41
-   shells. For now, we'll be running as system units. Some user unit
42
-   code is left in place in case we can switch back later.
43
-
44
-All DevStack user units are created as a part of the DevStack slice
45
-given the name ``devstack@$servicename.service``. This lets us do
46
-certain operations at the slice level.
47
-
48
-Manipulating Units
49
-==================
50
-
51
-Assuming the unit ``n-cpu`` to make the examples more clear.
52
-
53
-Enable a unit (allows it to be started)::
54
-
55
-  sudo systemctl enable devstack@n-cpu.service
56
-
57
-Disable a unit::
58
-
59
-  sudo systemctl disable devstack@n-cpu.service
60
-
61
-Start a unit::
62
-
63
-  sudo systemctl start devstack@n-cpu.service
64
-
65
-Stop a unit::
66
-
67
-  sudo systemctl stop devstack@n-cpu.service
68
-
69
-Restart a unit::
70
-
71
-  sudo systemctl restart devstack@n-cpu.service
72
-
73
-See status of a unit::
74
-
75
-  sudo systemctl status devstack@n-cpu.service
76
-
77
-Operating on more than one unit at a time
78
-
79
-Systemd supports wildcarding for unit operations. To restart every
80
-service in devstack you can do that following::
81
-
82
-  sudo systemctl restart devstack@*
83
-
84
-Or to see the status of all Nova processes you can do::
85
-
86
-  sudo systemctl status devstack@n-*
87
-
88
-We'll eventually make the unit names a bit more meaningful so that
89
-it's easier to understand what you are restarting.
90
-
91
-Querying Logs
92
-=============
93
-
94
-One of the other major things that comes with systemd is journald, a
95
-consolidated way to access logs (including querying through structured
96
-metadata). This is accessed by the user via ``journalctl`` command.
97
-
98
-
99
-Logs can be accessed through ``journalctl``. journalctl has powerful
100
-query facilities. We'll start with some common options.
101
-
102
-Follow logs for a specific service::
103
-
104
-  journalctl -f --unit devstack@n-cpu.service
105
-
106
-Following logs for multiple services simultaneously::
107
-
108
-  journalctl -f --unit devstack@n-cpu.service --unit
109
-  devstack@n-cond.service
110
-
111
-or you can even do wild cards to follow all the nova services::
112
-
113
-  journalctl -f --unit devstack@n-*
114
-
115
-Use higher precision time stamps::
116
-
117
-  journalctl -f -o short-precise --unit devstack@n-cpu.service
118
-
119
-
120
-Known Issues
121
-============
122
-
123
-Be careful about systemd python libraries. There are 3 of them on
124
-pypi, and they are all very different. They unfortunately all install
125
-into the ``systemd`` namespace, which can cause some issues.
126
-
127
-- ``systemd-python`` - this is the upstream maintained library, it has
128
-  a version number like systemd itself (currently ``233``). This is
129
-  the one you want.
130
-- ``systemd`` - a python 3 only library, not what you want.
131
-- ``python-systemd`` - another library you don't want. Installing it
132
-  on a system will break ansible's ability to run.
133
-
134
-
135
-If we were using user units, the ``[Service]`` - ``Group=`` parameter
136
-doesn't seem to work with user units, even though the documentation
137
-says that it should. This means that we will need to do an explicit
138
-``/usr/bin/sg``. This has the downside of making the SYSLOG_IDENTIFIER
139
-be ``sg``. We can explicitly set that with ``SyslogIdentifier=``, but
140
-it's really unfortunate that we're going to need this work
141
-around. This is currently not a problem because we're only using
142
-system units.
143
-
144
-Future Work
145
-===========
146
-
147
-oslo.log journald
148
-
149
-Journald has an extremely rich mechanism for direct logging including
150
-structured metadata. We should enhance oslo.log to take advantage of
151
-that. It would let us do things like::
152
-
153
-  journalctl REQUEST_ID=......
154
-
155
-  journalctl INSTANCE_ID=......
156
-
157
-And get all lines related to the request id or instance id. (Note:
158
-this work has been started at https://review.openstack.org/#/c/451525/)
159
-
160
-log colorizing
161
-
162
-We lose log colorization through this process. We might want to build
163
-a custom colorizer that we could run journalctl output through
164
-optionally for people.
165
-
166
-user units
167
-
168
-It would be great if we could do services as user units, so that there
169
-is a clear separation of code being run as not root, to ensure running
170
-as root never accidentally gets baked in as an assumption to
171
-services. However, user units interact poorly with devstack-gate and
172
-the way that commands are run as users with ansible and su.
173
-
174
-Maybe someday we can figure that out.
175
-
176
-References
177
-==========
178
-
179
-- Arch Linux Wiki - https://wiki.archlinux.org/index.php/Systemd/User
180
-- Python interface to journald -
181
-  https://www.freedesktop.org/software/systemd/python-systemd/journal.html
182
-- Systemd documentation on service files -
183
-  https://www.freedesktop.org/software/systemd/man/systemd.service.html
184
-- Systemd documentation on exec (can be used to impact service runs) -
185
-  https://www.freedesktop.org/software/systemd/man/systemd.exec.html
... ...
@@ -278,43 +278,22 @@ number of days of old log files to keep.
278 278
 
279 279
         LOGDAYS=1
280 280
 
281
-The some of the project logs (Nova, Cinder, etc) will be colorized by
282
-default (if ``SYSLOG`` is not set below); this can be turned off by
283
-setting ``LOG_COLOR`` to ``False``.
284
-
285
-    ::
281
+Some coloring is used during the DevStack runs to make it easier to
282
+see what is going on. This can be disabled with::
286 283
 
287 284
         LOG_COLOR=False
288 285
 
289 286
 Logging the Service Output
290 287
 ~~~~~~~~~~~~~~~~~~~~~~~~~~
291 288
 
292
-DevStack will log the ``stdout`` output of the services it starts.
293
-When using ``screen`` this logs the output in the screen windows to a
294
-file.  Without ``screen`` this simply redirects stdout of the service
295
-process to a file in ``LOGDIR``.
296
-
297
-    ::
298
-
299
-        LOGDIR=$DEST/logs
289
+By default, services run under ``systemd`` and are natively logging to
290
+the systemd journal.
300 291
 
301
-Note the use of ``DEST`` to locate the main install directory; this
302
-is why we suggest setting it in ``local.conf``.
303
-
304
-Enabling Syslog
305
-~~~~~~~~~~~~~~~
306
-
307
-Logging all services to a single syslog can be convenient. Enable
308
-syslogging by setting ``SYSLOG`` to ``True``. If the destination log
309
-host is not localhost ``SYSLOG_HOST`` and ``SYSLOG_PORT`` can be used
310
-to direct the message stream to the log host.
311
-
312
-    ::
292
+To query the logs use the ``journalctl`` command, such as::
313 293
 
314
-        SYSLOG=True
315
-        SYSLOG_HOST=$HOST_IP
316
-        SYSLOG_PORT=516
294
+  journalctl --unit devstack@*
317 295
 
296
+More examples can be found in :ref:`journalctl-examples`.
318 297
 
319 298
 Example Logging Configuration
320 299
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... ...
@@ -326,7 +305,6 @@ a file, keep service logs and disable color in the stored files.
326 326
 
327 327
        [[local|localrc]]
328 328
        DEST=/opt/stack/
329
-       LOGDIR=$DEST/logs
330 329
        LOGFILE=$LOGDIR/stack.sh.log
331 330
        LOG_COLOR=False
332 331
 
... ...
@@ -587,9 +565,7 @@ Swift
587 587
 
588 588
 Swift is disabled by default.  When enabled, it is configured with
589 589
 only one replica to avoid being IO/memory intensive on a small
590
-VM. When running with only one replica the account, container and
591
-object services will run directly in screen. The others services like
592
-replicator, updaters or auditor runs in background.
590
+VM.
593 591
 
594 592
 If you would like to enable Swift you can add this to your ``localrc``
595 593
 section:
... ...
@@ -630,7 +606,7 @@ install the swift3 middleware emulation. Swift will be configured to
630 630
 act as a S3 endpoint for Keystone so effectively replacing the
631 631
 ``nova-objectstore``.
632 632
 
633
-Only Swift proxy server is launched in the screen session all other
633
+Only Swift proxy server is launched in the systemd system all other
634 634
 services are started in background and managed by ``swift-init`` tool.
635 635
 
636 636
 Heat
... ...
@@ -8,56 +8,33 @@ with it?
8 8
 Inspecting Services
9 9
 ===================
10 10
 
11
-By default most services in DevStack are running in a `screen
12
-<https://www.gnu.org/software/screen/manual/screen.html>`_
13
-session.
11
+By default most services in DevStack are running as `systemd` units
12
+named `devstack@$servicename.service`. You can see running services
13
+with.
14 14
 
15 15
 .. code-block:: bash
16 16
 
17
-   os3:~> screen -list
18
-   There is a screen on:
19
-        28994.stack	(08/10/2016 09:01:33 PM)	(Detached)
20
-   1 Socket in /var/run/screen/S-sdague.
17
+   sudo systemctl status --unit="devstack@*"
21 18
 
22
-You can attach to this screen session using ``screen -r`` which gives
23
-you a view of the services in action.
24
-
25
-.. image:: assets/images/screen_session_1.png
26
-   :width: 100%
27
-
28
-Basic Screen Commands
29
-
30
-The following minimal commands will be useful to using screen:
31
-
32
-* ``ctrl-a n`` - go to next window. Next is assumed to be right of
33
-  current window.
34
-* ``ctrl-a p`` - go to previous window. Previous is assumed to be left
35
-  of current window.
36
-* ``ctrl-a [`` - entry copy/scrollback mode. This allows you to
37
-  navigate back through the logs with the up arrow.
38
-* ``ctrl-a d`` - detach from screen. Gets you back to a normal
39
-  terminal, while leaving everything running.
40
-
41
-For more about using screen, see the excellent `screen manual
42
-<https://www.gnu.org/software/screen/manual/screen.html>`_.
19
+To learn more about the basics of systemd, see :doc:`/systemd`
43 20
 
44 21
 Patching a Service
45 22
 ==================
46 23
 
47 24
 If you want to make a quick change to a running service the easiest
48
-way to do this is:
25
+way to do that is to change the code directly in /opt/stack/$service
26
+and then restart the affected daemons.
27
+
28
+.. code-block:: bash
29
+
30
+   sudo systemctl restart --unit=devstack@n-cpu.service
31
+
32
+If your change impacts more than one daemon you can restart by
33
+wildcard as well.
49 34
 
50
-* attach to screen
51
-* navigate to the window in question
52
-* ``ctrl-c`` to kill the service
53
-* make appropriate changes to the code
54
-* ``up arrow`` in the screen window to display the command used to run
55
-  that service
56
-* ``enter`` to restart the service
35
+.. code-block:: bash
57 36
 
58
-This works for services, except those running under Apache (currently
59
-just ``keystone`` by default).
37
+   sudo systemctl restart --unit="devstack@n-*"
60 38
 
61 39
 .. warning::
62 40
 
... ...
@@ -102,14 +79,6 @@ in gerrit by using the ref name that gerrit assigns to each change.
102 102
    NOVA_BRANCH=refs/changes/10/353710/1
103 103
 
104 104
 
105
-Testing Changes to Apache Based Services
106
-========================================
107
-
108
-When testing changes to Apache based services, such as ``keystone``,
109
-you can either use the Testing a Patch Series approach above, or make
110
-changes in the code tree and issue an apache restart.
111
-
112
-
113 105
 Testing Changes to Libraries
114 106
 ============================
115 107
 
... ...
@@ -132,9 +101,17 @@ your changes instead of just upstream master.
132 132
    OSLOPOLICY_REPO=/home/sdague/oslo.policy
133 133
    OSLOPOLICY_BRANCH=better_exception
134 134
 
135
-Because libraries are used by many services, library changes really
136
-need to go through a full ``./unstack.sh && ./stack.sh`` to see your
137
-changes in action.
135
+As libraries are not installed `editable` by pip, after you make any
136
+local changes you will need to:
137
+
138
+* cd to top of library path
139
+* sudo pip install -U .
140
+* restart all services you want to use the new library
141
+
142
+You can do that with wildcards such as
143
+
144
+.. code-block:: bash
145
+
146
+   sudo systemctl restart --unit="devstack@n-*"
138 147
 
139
-To figure out the repo / branch names for every library that's
140
-supported, you'll need to read the devstack source.
148
+which will restart all nova services.
... ...
@@ -41,8 +41,9 @@ Why not use packages?
41 41
 ~~~~~~~~~~~~~~~~~~~~~
42 42
 
43 43
 Unlike packages, DevStack leaves your cloud ready to develop -
44
-checkouts of the code and services running in screen. However, many
45
-people are doing the hard work of packaging and recipes for production
44
+checkouts of the code and services running locally under systemd,
45
+making it easy to hack on and test new patches. However, many people
46
+are doing the hard work of packaging and recipes for production
46 47
 deployments.
47 48
 
48 49
 Why isn't $MY\_FAVORITE\_DISTRO supported?
... ...
@@ -21,3 +21,4 @@
21 21
    development
22 22
    hacking
23 23
    guides
24
+   systemd
24 25
new file mode 100644
... ...
@@ -0,0 +1,167 @@
0
+===========================
1
+ Using Systemd in DevStack
2
+===========================
3
+
4
+By default DevStack is run with all the services as systemd unit
5
+files. Systemd is now the default init system for nearly every Linux
6
+distro, and systemd encodes and solves many of the problems related to
7
+poorly running processes.
8
+
9
+Why this instead of screen?
10
+===========================
11
+
12
+The screen model for DevStack was invented when the number of services
13
+that a DevStack user was going to run was typically < 10. This made
14
+screen hot keys to jump around very easy. However, the landscape has
15
+changed (not all services are stoppable in screen as some are under
16
+Apache, there are typically at least 20 items)
17
+
18
+There is also a common developer workflow of changing code in more
19
+than one service, and needing to restart a bunch of services for that
20
+to take effect.
21
+
22
+Unit Structure
23
+==============
24
+
25
+.. note::
26
+
27
+   Originally we actually wanted to do this as user units, however
28
+   there are issues with running this under non interactive
29
+   shells. For now, we'll be running as system units. Some user unit
30
+   code is left in place in case we can switch back later.
31
+
32
+All DevStack user units are created as a part of the DevStack slice
33
+given the name ``devstack@$servicename.service``. This makes it easy
34
+to understand which services are part of the devstack run, and lets us
35
+disable / stop them in a single command.
36
+
37
+Manipulating Units
38
+==================
39
+
40
+Assuming the unit ``n-cpu`` to make the examples more clear.
41
+
42
+Enable a unit (allows it to be started)::
43
+
44
+  sudo systemctl enable devstack@n-cpu.service
45
+
46
+Disable a unit::
47
+
48
+  sudo systemctl disable devstack@n-cpu.service
49
+
50
+Start a unit::
51
+
52
+  sudo systemctl start devstack@n-cpu.service
53
+
54
+Stop a unit::
55
+
56
+  sudo systemctl stop devstack@n-cpu.service
57
+
58
+Restart a unit::
59
+
60
+  sudo systemctl restart devstack@n-cpu.service
61
+
62
+See status of a unit::
63
+
64
+  sudo systemctl status devstack@n-cpu.service
65
+
66
+Operating on more than one unit at a time
67
+-----------------------------------------
68
+
69
+Systemd supports wildcarding for unit operations. To restart every
70
+service in devstack you can do that following::
71
+
72
+  sudo systemctl restart devstack@*
73
+
74
+Or to see the status of all Nova processes you can do::
75
+
76
+  sudo systemctl status devstack@n-*
77
+
78
+We'll eventually make the unit names a bit more meaningful so that
79
+it's easier to understand what you are restarting.
80
+
81
+.. _journalctl-examples:
82
+
83
+Querying Logs
84
+=============
85
+
86
+One of the other major things that comes with systemd is journald, a
87
+consolidated way to access logs (including querying through structured
88
+metadata). This is accessed by the user via ``journalctl`` command.
89
+
90
+
91
+Logs can be accessed through ``journalctl``. journalctl has powerful
92
+query facilities. We'll start with some common options.
93
+
94
+Follow logs for a specific service::
95
+
96
+  journalctl -f --unit devstack@n-cpu.service
97
+
98
+Following logs for multiple services simultaneously::
99
+
100
+  journalctl -f --unit devstack@n-cpu.service --unit
101
+  devstack@n-cond.service
102
+
103
+or you can even do wild cards to follow all the nova services::
104
+
105
+  journalctl -f --unit devstack@n-*
106
+
107
+Use higher precision time stamps::
108
+
109
+  journalctl -f -o short-precise --unit devstack@n-cpu.service
110
+
111
+
112
+Known Issues
113
+============
114
+
115
+Be careful about systemd python libraries. There are 3 of them on
116
+pypi, and they are all very different. They unfortunately all install
117
+into the ``systemd`` namespace, which can cause some issues.
118
+
119
+- ``systemd-python`` - this is the upstream maintained library, it has
120
+  a version number like systemd itself (currently ``234``). This is
121
+  the one you want.
122
+- ``systemd`` - a python 3 only library, not what you want.
123
+- ``python-systemd`` - another library you don't want. Installing it
124
+  on a system will break ansible's ability to run.
125
+
126
+
127
+If we were using user units, the ``[Service]`` - ``Group=`` parameter
128
+doesn't seem to work with user units, even though the documentation
129
+says that it should. This means that we will need to do an explicit
130
+``/usr/bin/sg``. This has the downside of making the SYSLOG_IDENTIFIER
131
+be ``sg``. We can explicitly set that with ``SyslogIdentifier=``, but
132
+it's really unfortunate that we're going to need this work
133
+around. This is currently not a problem because we're only using
134
+system units.
135
+
136
+Future Work
137
+===========
138
+
139
+log colorizing
140
+--------------
141
+
142
+We lose log colorization through this process. We might want to build
143
+a custom colorizer that we could run journalctl output through
144
+optionally for people.
145
+
146
+user units
147
+----------
148
+
149
+It would be great if we could do services as user units, so that there
150
+is a clear separation of code being run as not root, to ensure running
151
+as root never accidentally gets baked in as an assumption to
152
+services. However, user units interact poorly with devstack-gate and
153
+the way that commands are run as users with ansible and su.
154
+
155
+Maybe someday we can figure that out.
156
+
157
+References
158
+==========
159
+
160
+- Arch Linux Wiki - https://wiki.archlinux.org/index.php/Systemd/User
161
+- Python interface to journald -
162
+  https://www.freedesktop.org/software/systemd/python-systemd/journal.html
163
+- Systemd documentation on service files -
164
+  https://www.freedesktop.org/software/systemd/man/systemd.service.html
165
+- Systemd documentation on exec (can be used to impact service runs) -
166
+  https://www.freedesktop.org/software/systemd/man/systemd.exec.html
... ...
@@ -1474,6 +1474,13 @@ if [[ -n "$DEPRECATED_TEXT" ]]; then
1474 1474
     echo_summary "WARNING: $DEPRECATED_TEXT"
1475 1475
 fi
1476 1476
 
1477
+# If USE_SYSTEMD is enabled, tell the user about using it.
1478
+if [[ "$USE_SYSTEMD" == "True" ]]; then
1479
+    echo "Services are running under systemd unit files."
1480
+    echo "For more information see: "
1481
+    echo "https://docs.openstack.org/developer/devstack/systemd.html"
1482
+fi
1483
+
1477 1484
 # Indicate how long this took to run (bash maintained variable ``SECONDS``)
1478 1485
 echo_summary "stack.sh completed in $SECONDS seconds."
1479 1486
 
... ...
@@ -80,12 +80,19 @@ NOVA_ENABLED_APIS=osapi_compute,metadata
80 80
 # Set the root URL for Horizon
81 81
 HORIZON_APACHE_ROOT="/dashboard"
82 82
 
83
+# TODO(sdague): Queens
84
+#
85
+# All the non systemd paths should be removed in queens, they only
86
+# exist in Pike to support testing from grenade. Ensure that all this
87
+# is cleaned up and purged, which should dramatically simplify the
88
+# devstack codebase.
89
+
83 90
 # Whether to use 'dev mode' for screen windows. Dev mode works by
84 91
 # stuffing text into the screen windows so that a developer can use
85 92
 # ctrl-c, up-arrow, enter to restart the service. Starting services
86 93
 # this way is slightly unreliable, and a bit slower, so this can
87 94
 # be disabled for automated testing by setting this value to False.
88
-USE_SCREEN=$(trueorfalse True USE_SCREEN)
95
+USE_SCREEN=$(trueorfalse False USE_SCREEN)
89 96
 
90 97
 # Whether to use SYSTEMD to manage services
91 98
 USE_SYSTEMD=$(trueorfalse False USE_SYSTEMD)
... ...
@@ -100,9 +107,6 @@ else
100 100
     JOURNALCTL_F="journalctl -f -o short-precise --unit"
101 101
 fi
102 102
 
103
-if [[ "$USE_SYSTEMD" == "True" ]]; then
104
-    USE_SCREEN=False
105
-fi
106 103
 
107 104
 # Whether or not to enable Kernel Samepage Merging (KSM) if available.
108 105
 # This allows programs that mark their memory as mergeable to share
... ...
@@ -157,6 +161,10 @@ elif [[ -f $RC_DIR/.localrc.auto ]]; then
157 157
     source $RC_DIR/.localrc.auto
158 158
 fi
159 159
 
160
+# TODO(sdague): Delete all this in Queens.
161
+if [[ "$USE_SYSTEMD" == "True" ]]; then
162
+    USE_SCREEN=False
163
+fi
160 164
 # if we are forcing off USE_SCREEN (as we do in the gate), force on
161 165
 # systemd. This allows us to drop one of 3 paths through the code.
162 166
 if [[ "$USE_SCREEN" == "False" ]]; then