glances icon indicating copy to clipboard operation
glances copied to clipboard

Unable to Autostart glances using the systemd instructions [SOLVED]

Open ddetton opened this issue 1 year ago • 1 comments

[SOLVED] See first comment below.

I followed the instructions from here to autostart glances using systemd. https://github.com/nicolargo/glances/wiki/Start-Glances-through-Systemd

===================================== After systemctl enable and start, I run systemctl status glances.service, I get this: image

==================================== My glances.service file looks like this: image

=================================== My Operating System: image

=================================== My Glances & psutil versions image

================================== My Install method:

pip install --user 'glances[all]'

It was installed in $HOME/.local/bin. I added this to my path in my .zshrc script. I can run 'glances -w' just fine from the terminal and it responds to the REST API calls. I just can not get it to autostart with systemd. I am open to other autostart methods if systemd is not going to work for me.

Thanks!

ddetton avatar Feb 06 '24 01:02 ddetton

This stackoverflow article solved this issue for me.

https://stackoverflow.com/questions/35641414/python-import-of-local-module-failing-when-run-as-systemd-systemctl-service

I needed to tell systemd which user to run as. I also put in WorkingDirectory but don't know if that was required or not.

ddetton avatar Feb 07 '24 08:02 ddetton

Note added to https://github.com/nicolargo/glances/wiki/Start-Glances-through-Systemd

nicolargo avatar May 09 '24 12:05 nicolargo

for Fedora with SELinux enabled, this needs a couple extra steps:

/etc/systemd/system/glances.service

[Unit]
Description=Glances
After=network.target

[Service]
User=user
ExecStart=/home/user/.local/bin/glances -w
Restart=always
RemainAfterExit=no

[Install]
WantedBy=multi-user.target

then

sudo systemctl enable glances.service
sudo systemctl start glances.service

then by virtue of journalctl | grep glances, SELinux tells you to create a local policy:

ausearch -c '(glances)' --raw | audit2allow -M my-glances
semodule -X 300 -i my-glances.pp

finally refresh the security context: /sbin/restorecon -v /home/user/.local/bin/glances

and the service is now working.

Vigrond avatar Jul 07 '24 04:07 Vigrond