Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Systemd service not working #73

Closed
fanis opened this issue Sep 1, 2023 · 2 comments
Closed

Systemd service not working #73

fanis opened this issue Sep 1, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@fanis
Copy link

fanis commented Sep 1, 2023

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
Copy link
Owner

phsmith commented Sep 1, 2023

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.

phsmith added a commit that referenced this issue Sep 1, 2023
phsmith added a commit that referenced this issue Sep 1, 2023
phsmith added a commit that referenced this issue Sep 1, 2023
* fix(#73): add absolute VERSION path.

* docs(#73): update systemd example
@fanis
Copy link
Author

fanis commented Sep 5, 2023

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 :)

@phsmith phsmith closed this as completed Sep 6, 2023
@phsmith phsmith added the bug Something isn't working label Sep 6, 2023
@phsmith phsmith self-assigned this Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants