I’m building a web api with Flask. I got error when I use “sudo systemctl restart nginx” for ngnix restart after server installations, wsgi installations
$ sudo systemctl status nginx.servic
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 Mon 2021-12-06 09:36:31 UTC; 23h ago
Docs: man:nginx(8)
Process: 3210037 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Dec 06 09:36:31 systemd[1]: Starting A high performance web server and a reverse proxy server…
Dec 06 09:36:31 nginx[3210037]: nginx: [emerg] unknown directive “brotli” in /etc/nginx/conf.d/brotli.conf:1
Dec 06 09:36:31 nginx[3210037]: nginx: configuration file /etc/nginx/nginx.conf test failed
Dec 06 09:36:31 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Dec 06 09:36:31 systemd[1]: nginx.service: Failed with result ‘exit-code’.
Dec 06 09:36:31 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
How can I solve this?
I checked sites-enabled and sites-available?
Related
I am following this How To Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu 18.04 guide.
I have created the following file .socket
sudo nano /etc/systemd/system/gunicorn.socket
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
I have created the following file .service. How I have formatted my own version
sudo nano /etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=guilhermenog
Group=www-data
WorkingDirectory=/home/guilhermenog/projetoagenda
ExecStart=/home/guilhermenog/projetoagenda/venv/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
agenda.wsgi:application
[Install]
WantedBy=multi-user.target
Than I have tried to execute the following code
sudo systemctl start gunicorn.socket
And i have recibed this message error
Job for gunicorn.socket failed
See "systemctl status gunicorn.socket" and "journalctl -xe" for details.
After i tried the recommended code
● gunicorn.socket - gunicorn socket
Loaded: loaded (/etc/systemd/system/gunicorn.socket; enabled; vendor preset: enabled)
Active: inactive (dead)
Listen: /run/gunicorn.sock (Stream)
Apr 26 18:41:45 projetoagenda systemd[1]: gunicorn.socket: Socket service gunicorn.service not
loaded, refusing.
Apr 26 18:41:45 projetoagenda systemd[1]: Failed to listen on gunicorn socket.
Apr 26 18:48:41 projetoagenda systemd[1]: gunicorn.socket: Socket service gunicorn.service not
loaded, refusing.
Apr 26 18:48:41 projetoagenda systemd[1]: Failed to listen on gunicorn socket.
Apr 26 18:52:53 projetoagenda systemd[1]: gunicorn.socket: Socket service gunicorn.service not
loaded, refusing.
Apr 26 18:52:53 projetoagenda systemd[1]: Failed to listen on gunicorn socket.
Apr 26 18:53:27 projetoagenda systemd[1]: gunicorn.socket: Socket service gunicorn.service not
loaded, refusing.
Apr 26 18:53:27 projetoagenda systemd[1]: Failed to listen on gunicorn socket.
Apr 26 19:02:09 projetoagenda systemd[1]: gunicorn.socket: Socket service gunicorn.service not
loaded, refusing.
Apr 26 19:02:09 projetoagenda systemd[1]: Failed to listen on gunicorn socket.
i have followed this sugetions but nothing happen
Failed to start gunicorn.service: Unit gunicorn.service not found. Ubunto 18.04
sorry for this question, it´s my firts time asking help in english.
I had the same issue and it was also returning the same error. I managed to fix it for myself so I decided to share what I did, perhaps someone finds it useful too:
Fix: First I ran command: sudo systemctl enable gunicorn.socket (it created symlink)
Then I tried running: sudo systemctl start gunicorn.socket - but it returned that the job for gunicorn socket failed, however, I ran sudo systemctl enable gunicorn.socket again and then sudo systemctl start gunicorn.socket and the issue was no more and upon checking status ( command sudo systemctl status gunicorn.socket) it finally returned that it is active (listening).
I am setting up my django production project to work with celery on an ubuntu server. It works fine when i run task manually with
celery -A project worker -l INFO
but systemd stops every time i set it up and run. Configuration settings below.
/etc/default/celeryd
# most people will only start one node:
CELERYD_NODES="worker1"
# but you can also start multiple and configure settings
# for each in CELERYD_OPTS
#CELERYD_NODES="worker1 worker2 worker3"
# alternatively, you can specify the number of nodes to start:
#CELERYD_NODES=10
# Absolute or relative path to the 'celery' command:
CELERY_BIN="/home/steph/icecream/venv/bin/celery"
#CELERY_BIN="/virtualenvs/def/bin/celery"
# App instance to use
# comment out this line if you don't use an app
CELERY_APP="homestud"
# or fully qualified:
#CELERY_APP="proj.tasks:app"
# Where to chdir at start.
CELERYD_CHDIR="/home/steph/icecream/hometutors/homestud/"
# Extra command-line arguments to the worker
CELERYD_OPTS="--time-limit=300 --concurrency=8"
# Configure node-specific settings by appending node name to arguments:
#CELERYD_OPTS="--time-limit=300 -c 8 -c:worker2 4 -c:worker3 2 -Ofair:worker1"
# Set logging level to DEBUG
#CELERYD_LOG_LEVEL="DEBUG"
# %n will be replaced with the first part of the node name.
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"
# Workers should run as an unprivileged user.
# You need to create this user manually (or you can choose
# a user/group combination that already exists (e.g., nobody).
CELERYD_USER="celery"
CELERYD_GROUP="celery"
CELERYD_LOG_LEVEL="INFO"
# If enabled PID and log directories will be created if missing,
# and owned by the userid/group configured.
CELERY_CREATE_DIRS=1
/etc/systemd/system/celery.service
[Unit]
Description=Celery Service
After=network.target
[Service]
Type=forking
User=celery
Group=celery
EnvironmentFile=/etc/default/celeryd
WorkingDirectory=/home/steph/icecream/hometutors/homestud
ExecStart=/home/steph/icecream/venv/bin/celery multi start ${CELERYD_NODES} \
-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}
ExecStop=/home/steph/icecream/venv/bin/celery ${CELERY_BIN} multi stopwait ${CELERYD_NODES} \
--pidfile=${CELERYD_PID_FILE}
ExecReload=/home/steph/icecream/venv/bin/celery ${CELERY_BIN} multi restart ${CELERYD_NODES} \
-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}
[Install]
WantedBy=multi-user.target
when i run sudo systemctl status celery
● celery.service - Celery Service
Loaded: loaded (/etc/systemd/system/celery.service; enabled; vendor preset: enabled)
Active: failed (Result: signal) since Tue 2021-04-06 12:38:51 UTC; 5min ago
Process: 80579 ExecStart=/home/steph/icecream/venv/bin/celery multi start ${CELERYD_NODES} -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} --logfile=${CELERYD_LOG_FILE} --loglevel=${CEL>
Main PID: 80594 (code=killed, signal=KILL)
Apr 06 12:37:15 homestud-ubuntu-server systemd[1]: Starting Celery Service...
Apr 06 12:37:16 homestud-ubuntu-server celery[80579]: celery multi v5.0.5 (singularity)
Apr 06 12:37:16 homestud-ubuntu-server celery[80579]: > Starting nodes...
Apr 06 12:37:16 homestud-ubuntu-server celery[80579]: > worker1#homestud-ubuntu-server: OK
Apr 06 12:37:17 homestud-ubuntu-server systemd[1]: Started Celery Service.
Apr 06 12:37:21 homestud-ubuntu-server systemd[1]: celery.service: Main process exited, code=killed, status=9/KILL
Apr 06 12:38:51 homestud-ubuntu-server systemd[1]: celery.service: State 'stop-sigterm' timed out. Killing.
Apr 06 12:38:51 homestud-ubuntu-server systemd[1]: celery.service: Killing process 80606 (python) with signal SIGKILL.
Apr 06 12:38:51 homestud-ubuntu-server systemd[1]: celery.service: Failed with result 'signal'.
I also had the same issue, but turns out that it is because of low RAM (1 GB) at the production server. Kindly upgrade it to at least 2 GB and this issue will be resolved.
Hi I recently bought a Raspberry Pi 4
I am trying to program a discord bot for my server
Here is the error
pi#raspberrypi:~ $ sudo nano /lib/systemd/system/discordbot.service
pi#raspberrypi:~ $ sudo systemctl status discordbot.service
● discordbot.service - My Discord Bot Service
Loaded: loaded (/lib/systemd/system/discordbot.service; enabled; vendor preset: enabled)
Active: failed (Result: start-limit-hit) since Wed 2020-06-03 22:28:41 +08; 20min ago
Main PID: 856 (code=exited, status=0/SUCCESS)
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Service RestartSec=100ms expired, scheduling restart.
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Scheduled restart job, restart counter is at 5.
Jun 03 22:28:41 raspberrypi systemd[1]: Stopped My Discord Bot Service.
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Start request repeated too quickly.
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Failed with result 'start-limit-hit'.
Jun 03 22:28:41 raspberrypi systemd[1]: Failed to start My Discord Bot Service.
Here is the log to see my error
pi#raspberrypi:~ $ journalctl -e -u discordbot
Jun 03 22:28:41 raspberrypi systemd[1]: Started My Discord Bot Service.
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Succeeded.
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Service RestartSec=1
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Scheduled restart jo
Jun 03 22:28:41 raspberrypi systemd[1]: Stopped My Discord Bot Service.
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Start request repeat
Jun 03 22:28:41 raspberrypi systemd[1]: discordbot.service: Failed with result '
Jun 03 22:28:41 raspberrypi systemd[1]: Failed to start My Discord Bot Service.
[2]+ Stopped journalctl -e -u discordbot
Here is the code for the systemd
[Unit]
Description=My Discord Bot Service
After=network-online.target
[Service]
Type=idle
Restart=always
User=pi
ExecStart=/usr/bin/python3 /home/pi/discordbot/discordbot.py
[Install]
WantedBy=multi-user.target
I have tried to find solutions for hours but none helped
All help is appreciated :)
I have a system user account called user created like this:
useradd -r user
I have a very simple Python program which logs just one line:
#!/usr/bin/env python
import logging
import os
# Set logging options
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
logging.info('LOG SOMETHING')
And I have a systemd service to run that Python program:
[Unit]
Description=Run simple.py
[Service]
ExecStart=/usr/local/bin/simple.py
User=user
If I run the Python program from the command line, with both root and user users, it works just fine:
# /usr/local/bin/simple.py
INFO:root:LOG SOMETHING
# runuser -l user -c '/usr/local/bin/simple.py'
runuser: warning: cannot change directory to /home/user: No such file or directory
INFO:root:LOG SOMETHING
Ignore that warning. That's because the system user account user doesn't have a home directory.
Now, if I run the systemd service as the user user (note the User=user at the end of the service file), the logging sometimes fails, sometimes doesn't fail:
# systemctl start simple.service
# systemctl start simple.service
# systemctl start simple.service
# systemctl start simple.service
# systemctl start simple.service
# systemctl start simple.service
# journalctl -u simple.service | tail -18
Dec 08 17:57:23 localhost systemd[1]: Starting Run simple.py...
Dec 08 17:57:23 localhost systemd[1]: Started Run simple.py.
Dec 08 17:57:24 localhost systemd[1]: Starting Run simple.py...
Dec 08 17:57:24 localhost systemd[1]: Started Run simple.py.
Dec 08 17:57:25 localhost systemd[1]: Starting Run simple.py...
Dec 08 17:57:25 localhost systemd[1]: Started Run simple.py.
Dec 08 17:57:25 localhost systemd[1]: Starting Run simple.py...
Dec 08 17:57:25 localhost systemd[1]: Started Run simple.py.
Dec 08 17:57:26 localhost systemd[1]: Starting Run simple.py...
Dec 08 17:57:26 localhost simple.py[12774]: INFO:root:LOG SOMETHING
Dec 08 17:57:26 localhost systemd[1]: Started Run simple.py.
Dec 08 17:57:27 localhost systemd[1]: Starting Run simple.py...
Dec 08 17:57:27 localhost systemd[1]: Started Run simple.py.
Now, if I run the systemd service as the root user (just removing the User=user at the end of the service file, and of course running systemctl daemon-reload), the logging always works:
# systemctl start simple.service
# journalctl -u simple.service | tail -18
Dec 08 18:04:03 localhost systemd[1]: Starting Run simple.py...
Dec 08 18:04:03 localhost simple.py[12827]: INFO:root:LOG SOMETHING
Dec 08 18:04:03 localhost systemd[1]: Started Run simple.py.
Dec 08 18:04:03 localhost systemd[1]: Starting Run simple.py...
Dec 08 18:04:03 localhost simple.py[12835]: INFO:root:LOG SOMETHING
Dec 08 18:04:03 localhost systemd[1]: Started Run simple.py.
Dec 08 18:04:04 localhost systemd[1]: Starting Run simple.py...
Dec 08 18:04:04 localhost simple.py[12843]: INFO:root:LOG SOMETHING
Dec 08 18:04:04 localhost systemd[1]: Started Run simple.py.
Dec 08 18:04:05 localhost systemd[1]: Starting Run simple.py...
Dec 08 18:04:05 localhost simple.py[12851]: INFO:root:LOG SOMETHING
Dec 08 18:04:05 localhost systemd[1]: Started Run simple.py.
Dec 08 18:04:05 localhost systemd[1]: Starting Run simple.py...
Dec 08 18:04:05 localhost simple.py[12859]: INFO:root:LOG SOMETHING
Dec 08 18:04:05 localhost systemd[1]: Started Run simple.py.
Dec 08 18:04:06 localhost systemd[1]: Starting Run simple.py...
Dec 08 18:04:06 localhost simple.py[12867]: INFO:root:LOG SOMETHING
Dec 08 18:04:06 localhost systemd[1]: Started Run simple.py.
Why is that?
I am trying to execute a python3 with systemd in a ubuntu 16.
Following are the configs
[Unit]
Description=email notification server
After=multi-user.target
[Service]
WorkingDirectory=/home/ubuntu/email-noti
Restart=on-failure
ExecStart=/usr/lib/python3 /home/ubuntu/email-noti/email_reader.py
[Install]
WantedBy=multi-user.target
*please note that email_reader.py import a config file and few python3 files from /home/ubuntu/email-noti/
but it always end with following error
● email-noti.service - email notification server
Loaded: loaded (/etc/systemd/system/email-noti.service; enabled; vendor preset: enabled)
Active: inactive (dead) (Result: exit-code) since Tue 2017-03-07 18:00:38 UTC; 6s ago
Process: 11859 ExecStart=/usr/lib/python3 /home/ubuntu/email-noti/email_reader.py (code=exited, status=203/EXEC)
Main PID: 11859 (code=exited, status=203/EXEC)
Mar 07 18:00:38 ip-172-31-24-115 systemd[1]: email-noti.service: Service hold-off time over, scheduling restart.
Mar 07 18:00:38 ip-172-31-24-115 systemd[1]: Stopped email notification server.
Mar 07 18:00:38 ip-172-31-24-115 systemd[1]: email-noti.service: Start request repeated too quickly.
Mar 07 18:00:38 ip-172-31-24-115 systemd[1]: Failed to start email notification server.
but when i manually execute the email_reader.py works totally fine.
Any help appreciated