#249 Look into and possibly patch unit files for imagefactoryd
Closed: Fixed Opened by tflink.

We use imagefactory to build the images that we use on the Taskotron workers and distribute those images. When we last rebooted qa12, imagefactoryd didn't start up and it doesn't seem to want to be enabled:

# systemctl status imagefactoryd
 imagefactoryd.service
   Loaded: loaded (/usr/lib/systemd/system/imagefactoryd.service; static; vendor preset: disabled)
   Active: active (running) since Wed 2018-02-07 12:15:11 UTC; 13s ago
  Process: 32038 ExecStart=/usr/bin/imagefactoryd (code=exited, status=0/SUCCESS)
 Main PID: 32041 (imagefactoryd)
    Tasks: 11 (limit: 7372)
   CGroup: /system.slice/imagefactoryd.service
           └─32041 /usr/bin/python /usr/bin/imagefactoryd

Figure out if we need to change how we're enabling the imagefactoryd service to start on boot or if we may need to send a patch upstream so that it can be enabled to start on boot.


Metadata Update from @frantisekz:
- Issue assigned to frantisekz

imagefactoryd.service file is not a proper service file. I've reported this issue to the upstream ( https://github.com/redhat-imaging/imagefactory/issues/417 ).

Apart from that, proposed fix is to do following in our ansible play:

diff --git a/roles/taskotron/imagefactory/tasks/main.yml b/roles/taskotron/imagefactory/tasks/main.yml
+ - name: allow imagefactoryd.service to be enabled
+    blockinfile:
+    path: /etc/systemd/system/imagefactoryd.service
+    block: |
+      [Unit]
+      Requires=libvirtd.service
+      After=libvirtd.service
+
+      [Service]
+      Type=forking
+      ExecStart=/usr/bin/imagefactoryd
+      ExecStop=/usr/bin/killall imagefactoryd
+      PIDFile=/var/run/imagefactoryd.pid
+      LOCKFile=/var/lock/subsys/imagefactoryd
+
+      [Install]
+      WantedBy=multi-user.target

The indentation is off. It shouldn't work as it is currently written. See ansible-doc blockinfile for examples.

Please use a standard file for this that you just copy over (stored in files/). Or is there a reason to use blockinfile instead?

Please include the link to the bug as a comment above the task (something like "This is a workaround for: ". The name will now probably be something like "fix issues in imagefactoryd.service`, since we now fix several things.

Please try changing LOCKFile to a proper name (and test whether it works).

Please note you'll need to call daemon-reload if the service file was changed, before you try to enable it. See buildmaster-configure/tasks/main.yml for inspiration.

The indentation is off. It shouldn't work as it is currently written. See ansible-doc blockinfile for examples.

I was hoping you wouldn't notice... I was too lazy to do a proper git diff, so I just "made it by hand" :)

diff --git a/roles/taskotron/imagefactory/tasks/main.yml b/roles/taskotron/imagefactory/tasks/main.yml
index d28843714..e41bc2f6d 100644
--- a/roles/taskotron/imagefactory/tasks/main.yml
+++ b/roles/taskotron/imagefactory/tasks/main.yml
@@ -16,12 +16,15 @@
 - name: hotfix imagefactory's REST api to allow file download
   copy: src=hotfix_imgfac_RESTv2.py dest=/usr/lib/python2.7/site-packages/imgfac/rest/RESTv2.py owner=root group=root mode=0644
-- name: allow imagefactoryd.service to be enabled
-  blockinfile:
-    path: /usr/lib/systemd/system/imagefactoryd.service
-    block: |
-      [Install]
-      WantedBy=multi-user.target
+# Workaround for https://github.com/redhat-imaging/imagefactory/issues/417
+- name: fix issues in imagefactoryd.service
+  copy:
+    src: imagefactoryd.service
+    dest: /etc/systemd/system/imagefactoryd.service
+  register: imagefactory_service
+
+- name: reload systemd
+  command: systemctl daemon-reload
+  when: imagefactory_service.changed
 - name: enable imagefactory
   service: name=imagefactoryd state=started enabled=yes

and .service file:

# Workaround for https://github.com/redhat-imaging/imagefactory/issues/417
[Unit]
Requires=libvirtd.service
After=libvirtd.service
[Service]
Type=forking
ExecStart=/usr/bin/imagefactoryd 
ExecStop=/usr/bin/killall imagefactoryd
PIDFile=/var/run/imagefactoryd.pid
[Install]
WantedBy=multi-user.target

I was hoping you wouldn't notice... I was too lazy to do a proper git diff, so I just "made it by hand" :)

I always notice! :-)

+# Workaround for https://github.com/redhat-imaging/imagefactory/issues/417

Can you please also include this comment in the .service file? Thanks.

Looks good to me. Please push and deploy (and verify it works) in dev, and then in prod.

Issue fixed by:
https://infrastructure.fedoraproject.org/cgit/ansible.git/commit/?id=ace5dbaa1764803819c01bbaf8a29d8f1e03c70c
https://infrastructure.fedoraproject.org/cgit/ansible.git/commit/?id=4936b644e903bd43c09e12d570b5ec24a0f54d3e

Fix deployed on [taskotron-prod-client-hosts] & [taskotron-dev-client-hosts]

Metadata Update from @frantisekz:
- Issue close_status updated to: Fixed
- Issue status updated to: Closed (was: Open)

Thanks @frantisekz ! Here, have a :cookie: .

Metadata Update from @kparal:
- Issue status updated to: Open (was: Closed)

Oh Pagure, how much we love you...

Metadata Update from @kparal:
- Issue close_status updated to: Fixed
- Issue status updated to: Closed (was: Open)

Metadata