How to run glances as a background process on ubuntu and send the output to file.

1,265 views
Skip to first unread message

Daniel Sigrist

unread,
Jun 24, 2020, 11:07:43 PM6/24/20
to Glances Users
HI all,

I need to run glances on the background so I can exit the terminal. I'm running ubuntu 18.04.

I tried:

glances -t 60 --export-csv /tmp/glances.csv &

but the program exists in a few seconds and doesn't right anything in the file.

Can you help?


thank you.

Ben Watson

unread,
Jun 25, 2020, 10:15:39 AM6/25/20
to Glances Users
You could run it as a (systemd) service.  Here's an example service unit that you can tweak to your liking:

# Ansible managed

[Install]
WantedBy=multi-user.target

[Service]
ExecStart=/usr/local/bin/glances -C /etc/glances/glances_server.conf -s -p 61209
Group=root
Restart=on-failure
RestartSec=30
TimeoutSec=30
Type=simple
User=root

[Unit]
After=network.target
Description=Glances Server
~                                                                 


Adekunbi Adewojo

unread,
Jun 25, 2020, 4:52:01 PM6/25/20
to Glances Users
Hi,

I am running it this way. However at times the system doesn't start up and I think it is because it can't locate glances under /usr/local/bin/glances. What is best way of installing it? I have tried the python way, the snap way and the curl way but they all have different issues. 

Also, please I installed grafana and did all the connection but grafana do not report any data. How can I fix that one?

Thanks.

Daniel Sigrist

unread,
Jun 26, 2020, 4:12:14 PM6/26/20
to Glances Users
Hi Ben,

thank you for the suggestion. I created the service, but it's not working. it complains about  "_curses.error: setupterm: could not find terminal"

here is the syslog info:

Jun 26 20:09:36 ip-172-26-10-63 systemd[1]: Started Glances Server.
Jun 26 20:09:38 ip-172-26-10-63 glances[13538]: Traceback (most recent call last):
Jun 26 20:09:38 ip-172-26-10-63 glances[13538]:   File "/usr/bin/glances", line 11, in <module>
Jun 26 20:09:38 ip-172-26-10-63 glances[13538]:     load_entry_point('Glances==2.11.1', 'console_scripts', 'glances')()
Jun 26 20:09:38 ip-172-26-10-63 glances[13538]:   File "/usr/lib/python3/dist-packages/glances/__init__.py", line 134, in main
Jun 26 20:09:38 ip-172-26-10-63 glances[13538]:     start(config=config, args=args)
Jun 26 20:09:38 ip-172-26-10-63 glances[13538]:   File "/usr/lib/python3/dist-packages/glances/__init__.py", line 100, in start
Jun 26 20:09:38 ip-172-26-10-63 glances[13538]:     mode = GlancesMode(config=config, args=args)
Jun 26 20:09:38 ip-172-26-10-63 glances[13538]:   File "/usr/lib/python3/dist-packages/glances/standalone.py", line 79, in __init__
Jun 26 20:09:38 ip-172-26-10-63 glances[13538]:     self.screen = GlancesCursesStandalone(config=config, args=args)
Jun 26 20:09:38 ip-172-26-10-63 glances[13538]:   File "/usr/lib/python3/dist-packages/glances/outputs/glances_curses.py", line 104, in __init__
Jun 26 20:09:38 ip-172-26-10-63 glances[13538]:     self.screen = curses.initscr()
Jun 26 20:09:38 ip-172-26-10-63 glances[13538]:   File "/usr/lib/python3.6/curses/__init__.py", line 30, in initscr
Jun 26 20:09:38 ip-172-26-10-63 glances[13538]:     fd=_sys.__stdout__.fileno())
Jun 26 20:09:38 ip-172-26-10-63 glances[13538]: _curses.error: setupterm: could not find terminal
Jun 26 20:09:38 ip-172-26-10-63 systemd[1]: glances_report.service: Main process exited, code=exited, status=1/FAILURE
Jun 26 20:09:38 ip-172-26-10-63 systemd[1]: glances_report.service: Failed with result 'exit-code'.

and here is my service file:

[Install]
WantedBy=multi-user.target

[Service]
ExecStart=/usr/bin/glances -t 60 --export-csv /tmp/test_glances_service.csv
Group=ubuntu
Restart=on-failure
RestartSec=30
TimeoutSec=30
Type=simple
User=ubuntu


[Unit]
After=network.target
Description=Glances Server
Documentation=https://glances.readthedocs.io/en/stable/index.html

thank you.
Reply all
Reply to author
Forward
0 new messages