Skip to content

Commit

Permalink
Drop pid files and fix working dirs
Browse files Browse the repository at this point in the history
When using systemd, the pid files are actually not important so they can
be dropped.

The the WorkingDirectory is set to ~ which will resolve to the user's
home directory. That means systemd will ensure it is mounted before
starting services. Pulp itself doesn't use it so it's a cheap way for
a more reliable service start.

Subscribing to [email protected] is another bugfix to ensure all
workers use the correct service definition.

Explicitly setting the type and group is more for consistency and
doesn't actually change anything.
  • Loading branch information
ekohl authored and wbclark committed Oct 5, 2020
1 parent 00af33a commit b3b7c13
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
8 changes: 4 additions & 4 deletions manifests/service.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# configure, enable, and start pulpcore services
# @api private
class pulpcore::service {

systemd::unit_file { 'pulpcore-api.service':
content => template('pulpcore/pulpcore-api.service.erb'),
active => true,
Expand All @@ -26,9 +25,10 @@

Integer[1, $pulpcore::worker_count].each |$n| {
service { "pulpcore-worker@${n}.service":
ensure => running,
enable => true,
require => [Systemd::Unit_file['[email protected]'], Class['systemd::systemctl::daemon_reload']],
ensure => running,
enable => true,
require => Class['systemd::systemctl::daemon_reload'],
subscribe => Systemd::Unit_file['[email protected]'],
}
}

Expand Down
10 changes: 2 additions & 8 deletions templates/pulpcore-api.service.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Wants=network-online.target
Environment="DJANGO_SETTINGS_MODULE=pulpcore.app.settings"
Environment="PULP_SETTINGS=<%= scope['pulpcore::settings_file'] %>"
User=<%= scope['pulpcore::user'] %>
PIDFile=/run/pulpcore-api.pid
Group=<%= scope['pulpcore::group'] %>
WorkingDirectory=~
RuntimeDirectory=pulpcore-api
ExecStart=/usr/bin/gunicorn pulpcore.app.wsgi:application \
--bind '<%= scope['pulpcore::api_host'] %>:<%= scope['pulpcore::api_port'] %>' \
Expand All @@ -23,13 +24,6 @@ SyslogIdentifier=pulpcore-api
Restart=always
RestartSec=3

# This directive is set to an absolute path in other Pulp units. Using an
# absolute path is an abuse of the directive, as it should be a relative path,
# not an absolute path. PIDFile is now used to ensure that PID files are laid
# out in a standard way. If this directive had any other effects, it is better
# to use the correct directive than to uncomment this.
# WorkingDirectory=/var/run/pulpcore-api/

[Install]
WantedBy=multi-user.target

3 changes: 2 additions & 1 deletion templates/pulpcore-content.service.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Wants=network-online.target
Environment="DJANGO_SETTINGS_MODULE=pulpcore.app.settings"
Environment="PULP_SETTINGS=<%= scope['pulpcore::settings_file'] %>"
User=<%= scope['pulpcore::user'] %>
WorkingDirectory=/var/run/pulpcore-content/
Group=<%= scope['pulpcore::group'] %>
WorkingDirectory=~
RuntimeDirectory=pulpcore-content
ExecStart=/usr/bin/gunicorn pulpcore.content:server \
--bind '<%= scope['pulpcore::content_host'] %>:<%= scope['pulpcore::content_port'] %>' \
Expand Down
5 changes: 3 additions & 2 deletions templates/pulpcore-resource-manager.service.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ After=network-online.target
Wants=network-online.target

[Service]
Type=simple
Environment="DJANGO_SETTINGS_MODULE=pulpcore.app.settings"
Environment="PULP_SETTINGS=<%= scope['pulpcore::settings_file'] %>"
User=<%= scope['pulpcore::user'] %>
WorkingDirectory=/var/run/pulpcore-resource-manager/
Group=<%= scope['pulpcore::group'] %>
WorkingDirectory=~
RuntimeDirectory=pulpcore-resource-manager
ExecStart=/usr/bin/rq worker \
-w pulpcore.tasking.worker.PulpWorker -n resource-manager \
--pid=/var/run/pulpcore-resource-manager/resource-manager.pid \
-c 'pulpcore.rqconfig' \
--disable-job-desc-logging

Expand Down
4 changes: 2 additions & 2 deletions templates/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ After=network-online.target
Wants=network-online.target

[Service]
Type=simple
EnvironmentFile=-/etc/default/pulp-workers
EnvironmentFile=-/etc/default/pulp-workers-%i
Environment="DJANGO_SETTINGS_MODULE=pulpcore.app.settings"
Environment="PULP_SETTINGS=<%= scope['pulpcore::settings_file'] %>"
User=<%= scope['pulpcore::user'] %>
Group=<%= scope['pulpcore::group'] %>
WorkingDirectory=/var/run/pulpcore-worker-%i/
WorkingDirectory=~
RuntimeDirectory=pulpcore-worker-%i
ExecStart=/usr/bin/rq worker \
-w pulpcore.tasking.worker.PulpWorker \
--pid=/var/run/pulpcore-worker-%i/reserved-resource-worker-%i.pid \
-c 'pulpcore.rqconfig' \
--disable-job-desc-logging

Expand Down

0 comments on commit b3b7c13

Please sign in to comment.