phsmith / rundeck_exporter

Rundeck Metrics Exporter
GNU General Public License v3.0
58 stars 25 forks source link

Systemd service not working #73

Closed fanis closed 10 months ago

fanis commented 10 months ago

I used the example systemd service, set RUNDECK_TOKEN and OPTIONS in a new /etc/default/rundeck_exporter file, however it fails to start.

I'm pasting below the files after editing out the token/ip/port/url.

/etc/default/rundeck_exporter:

RUNDECK_TOKEN=[token_here]
RUNDECK_OPTIONS="--host [ip] --port [port] --rundeck.url [url] --rundeck.skip_ssl --rundeck.api.version 41 --rundeck.username exporter --rundeck.projects.executions --rundeck.projects.executions.cache --rundeck.cpu.stats --rundeck.memory.stats"

/etc/systemd/system/rundeck_exporter.service:

 [Unit]
 Description=Rundeck exporter service for Prometheus
 Documentation=https://github.com/phsmith/rundeck_exporter/
 After=network-online.target

 [Service]
 User=root
 Restart=on-failure
 EnvironmentFile=/etc/default/rundeck_exporter
 ExecStart=/usr/local/src/rundeck_exporter/rundeck_exporter.py $RUNDECK_OPTIONS

 StandardOutput=append:/var/log/rundeckexporter.log
 StandardError=append:/var/log/rundeckdexporter.log

 [Install]
 WantedBy=multi-user.target

/var/log/rundeckexporter.log shows nothing.

/var/log/syslog shows:

 Sep  1 16:48:16 server systemd[1]: rundeck_exporter.service: Main process exited, code=exited, status=1/FAILURE
 Sep  1 16:48:16 server systemd[1]: rundeck_exporter.service: Failed with result 'exit-code'.
 Sep  1 16:48:17 server systemd[1]: rundeck_exporter.service: Main process exited, code=exited, status=1/FAILURE
 Sep  1 16:48:17 server systemd[1]: rundeck_exporter.service: Failed with result 'exit-code'.
 Sep  1 16:48:17 server systemd[1]: rundeck_exporter.service: Main process exited, code=exited, status=1/FAILURE
 Sep  1 16:48:17 server systemd[1]: rundeck_exporter.service: Failed with result 'exit-code'.
 Sep  1 16:48:17 server systemd[1]: rundeck_exporter.service: Main process exited, code=exited, status=1/FAILURE
 Sep  1 16:48:17 server systemd[1]: rundeck_exporter.service: Failed with result 'exit-code'.
 Sep  1 16:48:18 server systemd[1]: rundeck_exporter.service: Main process exited, code=exited, status=1/FAILURE
 Sep  1 16:48:18 server systemd[1]: rundeck_exporter.service: Failed with result 'exit-code'.
 Sep  1 16:48:18 server systemd[1]: rundeck_exporter.service: Start request repeated too quickly.
 Sep  1 16:48:18 server systemd[1]: rundeck_exporter.service: Failed with result 'exit-code'.

Running the exact same command with hardcoded command parameters (the ones in the env variable OPTIONS from /etc/default/rundeck_exporter) and the env variable RUNDECK_TOKEN prefixed works just fine:

RUNDECK_TOKEN=[token_here] /usr/local/src/rundeck_exporter/rundeck_exporter.py --host [ip] --port [port] --rundeck.url [rundeck_url] --rundeck.skip_ssl --rundeck.api.version 41 --rundeck.username exporter --rundeck.projects.executions --rundeck.projects.executions.cache --rundeck.cpu.stats --rundeck.memory.stats

Any help in determine what the issue is with the systemd configuration would be appreciated.

phsmith commented 10 months ago

Hey @fanis, thanks for your report.

I tested it the same way you did, I cloned the project to /usr/local/src and found this problem:

RUNDECK_TOKEN=..... /usr/local/src/rundeck_exporter/venv/bin/python /usr/local/src/rundeck_exporter/rundeck_exporter.py --host 0.0.0.0 --rundeck.url http://localhost:4440 --rundeck.skip_ssl --rundeck.api.version 41 --rundeck.projects.executions --rundeck.projects.executions.cache --rundeck.cpu.stats --rundeck.memory.stats                                                                                                                                                                                                                
Traceback (most recent call last):
  File "/usr/local/src/rundeck_exporter/rundeck_exporter.py", line 30, in <module>
    __version__ = open('VERSION').read()
                  ^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'VERSION'

After fixing this problem, I was able to run with the systemd service exactly as you did, the only difference is that I set the python from a venv, so you need to make sure that all the dependencies in requirements.txt are installed:

# systemctl start rundeck_exporter   
# systemctl status rundeck_exporter
● rundeck_exporter.service - Rundeck exporter service for Prometheus
     Loaded: loaded (/etc/systemd/system/rundeck_exporter.service; disabled; preset: disabled)
     Active: active (running) since Fri 2023-09-01 13:03:13 -03; 9s ago
       Docs: https://github.com/phsmith/rundeck_exporter/
   Main PID: 452693 (python)
      Tasks: 2 (limit: 47100)
     Memory: 17.6M
        CPU: 92ms
     CGroup: /system.slice/rundeck_exporter.service
             └─452693 /usr/local/src/rundeck_exporter/venv/bin/python /usr/local/src/rundeck_exporter/rundeck_exporter.py --host 0.0.0.0 --rundeck.url http://localhost:4440 --rundeck.skip_ssl --rundeck.api.version 41 --rundeck.username admin --rundeck.projects.executions --rundeck.projects.executions.cache >

set 01 13:03:13 archlegion systemd[1]: Started Rundeck exporter service for Prometheus.

# cat /var/log/rundeck_exporter.log
2023-09-01 13:05:56,546 - INFO - Rundeck exporter server started at 0.0.0.0:9620...

I'll send the fix so you can test it.

fanis commented 10 months ago

Hey @phsmith , thanks for the fix, not sure why I hadn't gotten a notifciation from Github on your comments. I was just coming here to update that I just found the problem and fixed it, the systemd file just needed a WorkingDirectory:

WorkingDirectory=/usr/local/src/rundeck_exporter

I noticed that when testing running the command manually I was already in that directory - moving out of it surfaced the error.

Perhaps this is a side-effect of what you fixed anyway, but it works for me :)