Home Adding a shell command inside/inline of a systemd service file
Reply: 1

Adding a shell command inside/inline of a systemd service file

Venkata S S Krishna Manikeswar
1#
Venkata S S Krishna Manikeswar Published in 2018-01-13 03:09:52Z

I am running the gunicorn server as a service via systemd, Here is the sample service file:

[Unit]
Description=Gunicorn NGINX
After=network.target

[Service]
User=root
Group=www-data
WorkingDirectory=/test
ExecStart=/usr/local/bin/gunicorn --workers 8 --threads 8 --backlog 100 --bind 10.0.0.20:5000 -m 777 abc:app
Restart=always

[Install]
WantedBy=multi-user.target

I want now to replace the number near --workers and --threads by number of cores using the shell command so that it will dynamically pick the number of cores

nproc --all

Can someone help me how to do this

John Kugelman
2#
John Kugelman Reply to 2018-01-13 03:20:20Z

You can explicitly invoke a shell to get shell parsing.

ExecStart=/bin/bash -c '/usr/local/bin/gunicorn --workers "$(nproc --all)" --threads "$(nproc --all)" --backlog 100 --bind 10.0.0.20:5000 -m 777 abc:app'
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.299776 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO