systemctl strange error: Invalid arguments - django

Here's my service file:
[Unit]
Description=Daphne Interface
[Service]
ExecStartPre=cd /home/git/hsfzmun/server
ExecStart=/bin/bash/ -c "cd /home/git/hsfzmun/server && /home/git/virtualenvs/hsfzmun/bin/daphne -b 0.0.0.0 -p 8001 -v2 config.asgi:channel_layer"
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all
[Install]
WantedBy=multi-user.target
When I execute sudo systemctl start daphnei I get:
Failed to start daphnei.service: Unit daphnei.service is not loaded properly: Invalid argument.
See system logs and 'systemctl status daphnei.service' for details.
And the result of systemctl status daphnei.service:
* daphnei.service - Daphne Interface
Loaded: error (Reason: Invalid argument)
Active: inactive (dead) (Result: exit-code) since Mon 2017-02-13 19:55:10 CST; 13min ago
Main PID: 16667 (code=exited, status=1/FAILURE)
What's wrong? I am using Ubuntu Server 16.04.

Generally, to debug exact cause of "Invalid argument", you can use:
sudo systemd-analyze verify daphnei.service
or in case of user's local service:
sudo systemd-analyze --user verify daphnei.service

Maybe you've figured it out by now, but there's an extra / after /bin/bash in your ExecStart line.
I may have a slightly newer version of systemd -- when I tried it, the output of systemctl status included this message:
Executable path specifies a directory, ignoring: /bin/bash/ -c "cd /home/git/hsfzmun/server && /home/git/virtualenvs/hsfzmun/bin/daphne -b 0.0.0.0 -p 8001 -v2 config.asgi:channel_layer"
Also, you might consider using a WorkingDirectory line in the service, instead of cd &&

Related

systemctl daemon-reload fails with Invalid Number of Arguments

On Amazon Linux 2 on ec2 instance I editted the elastic-agent service and I get an error "Invalid number of arguments"
[ec2-user#ip-172-31-21-92 ~]$ sudo systemctl daemon-reload elastic-agent
Invalid number of arguments.
I have edited my service file to look like this:
[Unit]
Description=Agent manages other beats based on configuration provided.
Documentation=https://www.elastic.co/products/beats/elastic-agent
Wants=network-online.target
After=network-online.target
[Service]
Environment="BEAT_LOG_OPTS="
Environment="BEAT_CONFIG_OPTS=-c /etc/elastic-agent/elastic-agent.yml"
Environment="BEAT_PATH_OPTS=--path.home /usr/share/elastic-agent --path.config /etc/elastic-agent --path.data /var/lib/elastic-agent --path.logs /var/log/elastic-agent"
ExecStart=/usr/share/elastic-agent/bin/elastic-agent --environment systemd $BEAT_LOG_OPTS $BEAT_CONFIG_OPTS $BEAT_PATH_OPTS -v
Restart=always
[Install]
WantedBy=multi-user.target
The only edit I made to the installed file was to add the "-v" flag to the end of ExecStart
No need to add elastic-agent, just run
sudo systemctl daemon-reload

nginx fails while the website somehow still works

Description
I have built my Django3, gunicorn, nginx, Ubuntu 18.04, Digital Ocean project based on this guide. I only had 1 problem that it does not shows the CSS and all other static files like images. Before during the whole guide nginx have given the correct answers as the guide says and also currently the html site still online and running
To solve this I was in the process of using this another guide to make my static files displayed on my site.
I have done all the steps what the creator recommended but at the
What I have tried
After each step of the following [1.2.3...] commands I have executed the following commands to refresh:
python3 manage.py collectstatic
sudo nginx -t && sudo systemctl restart nginx
sudo systemctl restart gunicorn
1.RUN: sudo ln -s /etc/nginx/sites-available/ch-project /etc/nginx/sites-enabled
1.RESULT: ln: failed to create symbolic link '/etc/nginx/sites-enabled/ch-project': File exists
2.RUN: /etc/nginx/sites-enabled/my-project
2.RESULT: -bash: /etc/nginx/sites-enabled/my-project: Permission denied
3.RUN: systemctl status nginx.service
3.RESULT:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2020-03-26 13:27:08 UTC; 13s ago
Docs: man:nginx(8)
Process: 11111 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 11111 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Main PID: 11111 (code=exited, status=0/SUCCESS)
4.RUN: sudo nginx -t
4.RESULT:
nginx: [emerg] open() "/etc/nginx/sites-enabled/myproject" failed (2: No such file or directory) in /etc/nginx/nginx.conf:62
nginx: configuration file /etc/nginx/nginx.conf test failed
Nginex should be Ok otherwise because the html on the website loads and works perfectly. This stack overflow post says I should maybe do something with the security of the nginx.conf but in that case they talk about a worldpres site so I don't know how to implement that here.
I have tried this stack overflow post's answer previously, bellow the answer it has a subpost to further configure RUN: sudo nginx -c /etc/nginx/sites-enabled/default -t
6.RESULT:
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/sites-enabled/default:21
nginx: configuration file /etc/nginx/sites-enabled/default test failed
The static files still don't load but nginx has been fixed with the following commands.
deleting accidentally created myproject file from /etc/nginx/sites-enabled/myproject what file name is in the official guide but the_actual_myproject has different name RUN:
cd /etc/nginx/sites-enabled
sudo rm myproject
RUN:
namei -l /run/gunicorn.sock
sudo systemctl restart gunicorn
sudo systemctl daemon-reload
sudo systemctl restart gunicorn.socket gunicorn.service
sudo nginx -t && sudo systemctl restart nginx
RESULT:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
RUN: systemctl status nginx.service
RESULT:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-03-26 16:32:09 UTC; 7min ago
Docs: man:nginx(8)
Process: 11111 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, sta
Process: 11111 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=ex
Main PID: 11111 (nginx)
Tasks: 2 (limit: 1152)
CGroup: /system.slice/nginx.service

restarting gunicorn and nginx doesn't reflect changes after pull request

Recently I hosted a Django website on digitalocean. I then edited the content of website locally and pushed them to GitHub then pulled it to server and restarted nginx and gunicorn:
sudo systemctl restart nginx
sudo systemctl restart gunicorn
Then changes didn't reflect back to live website, Just to check if I setup gnuicorn and nginx properly, I ran sudo systemctl status gunicorn.socket I get Failed to dump process list, ignoring: No such file or directory
(venv) leptitoxadmin#ubuntu1:~/pyapps/leptx$ sudo systemctl status gunicorn.socket
[sudo] password for leptxadmin:
Failed to dump process list, ignoring: No such file or directory
● gunicorn.socket - gunicorn socket
Loaded: loaded (/etc/systemd/system/gunicorn.socket; enabled; vendor preset: enabled)
Active: active (running) since Wed 2020-02-12 05:57:58 UTC; 2h 42min ago
Listen: /run/gunicorn.sock (Stream)
CGroup: /system.slice/gunicorn.socket
Feb 12 05:57:58 ubuntu1 systemd[1]: Listening on gunicorn socket.
is this the reason, why the changes don't reflect to live website? How do I solve it? thanks
I think you should also consider reloading daemon as well
sudo systemctl daemon-reload
and then
sudo systemctl restart gunicorn
i have same problem and now i solved!!
./manage.py collectstatic
sudo systemctl restart gunicorn
that code can solve problem!

Starting rqworker using supervisor causes spawn error

Trying to start rqworker as stated in its README using this command:
python manage.py rqworker default
For some reason it gives ERROR (spawn error) and status shows FATAL Exited too quickly (process log may have details). Logs has no any information for error (exit status 1; not expected).
My supervisor configuration:
[program:rqworker]
user=ubuntu
directory=/var/www/project/
command=/var/www/project/venv/bin/python manage.py rqworker default > /var/log/project/rq.log
stopsignal=TERM
autorestart=true
autostart=true
numprocs=1
Running command directly from ubuntu user works as expected.
I submitted a PR on how to set this up on Ubuntu which may help you.
https://github.com/W7PEA/django-rq/blob/4afc19ab9866882c1809f89f84066856c94d75c6/README.rst
Deploying on Ubuntu
Create an rqworker service that runs the high, default, and low queues.
sudo vi /etc/systemd/system/rqworker.service
[Unit]
Description=Django-RQ Worker
After=network.target
[Service]
WorkingDirectory=<<path_to_your_project_folder>>
ExecStart=/home/ubuntu/.virtualenv/<<your_virtualenv>>/bin/python \
<<path_to_your_project_folder>>/manage.py \
rqworker high default low
[Install]
WantedBy=multi-user.target
Enable and start the sevice
sudo systemctl enbable rqworker
sudo systemctl start rqworker

convert following systemd into upstart for ubuntu 14.04 -- uwsgi emperor mode did not work as expected

I have the following script that was given to help me turn on uwsgi at emperor mode.
https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-centos-7
I have tweaked it slightly for the below:
[Unit]
Description=uWSGI Emperor service
[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown vagrant:www-data /run/uwsgi'
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all
[Install]
WantedBy=multi-user.target
I needed to rewrite this for ubuntu 14.04 hence I wrote the below into /etc/init/uwsgi.conf
description "uWSGI Emperor service"
## equivalent to wantedby=multi-user.target
start on runlevel [2345]
# create a directory needed by the daemon
pre-start exec /bin/bash -c 'mkdir -p /run/uwsgi; chown vagrant:www-data /run/uwsgi'
exec /usr/local/bin/uwsgi --emperor /etc/uwsgi/sites
respawn
kill signal SIGQUIT
expect stop
What was expected:
/run/uwsgi will be created with the ownership as vagrant:www-data
it will have 2 .sock files called djangoonpy2.sock and djangoonpy3.sock
What I did see:
/run/uwsgi will be created with the ownership as vagrant:www-data
it only has 1 .sock file called djangoonpy2.sock
I am runnning ubuntu14.04 using vagrant as a virtual machine.
Please advise.