How to solve celerybeat is down: no pid file found? - django

I have followed instructions from https://pythad.github.io/articles/2016-12/how-to-run-celery-as-a-daemon-in-production
It works pretty well for celeryd, however when starting celerybeat it says pid file not found.
I've used this tutorial on my previous projects and it did fine for both celeryd and celerybeat. The difference of this project only is all project files including the django project are owned by root. I fail at finding more details about the issue.

You also need to change permissions of the log directories that celery writes to:
sudo chmod 755 /var/log/celery/ /var/run/celery/
sudo chown root:root /var/log/celery/ /var/run/celery/

Related

GCE startup script: can't find $HOME after exporting in startup script

I am trying to run a GCE startup script that downloads all dependencies, clones a repository and runs a python program. Here is the code
#! /usr/bin/bash
apt-get update
apt-get -y install python3.7
apt-get -y install git
export HOME=/home/codingassignment
echo $HOME
cd $HOME
rm -rf sshlogin-counter/
git clone https://rutu2605:************#github.com/rutu2605/sshlogin-counter.git
nohup python3 -u ./sshlogin-counter/alphaclient.py > output.log 2>&1 &
When I run echo$HOME, it displays the path in the log file. However when I cd into it, it says directory not found
May 08 23:15:18 alphaclient google_metadata_script_runner[488]: startup-script: /home/codingassignment
May 08 23:15:18 alphaclient google_metadata_script_runner[488]: startup-script: /tmp/metadata-scripts701519516/startup-script: line 7: cd: /home/codingassignment: No such file or directory
That's because at the time when the script is executed, the /home/codingassignment directory doesn't exist yet. To quote the answer you referred to in the comment:
The startup script is executed as root when the user have been not created yet and no user is logged in
The user home directory for the codingassignment user is created later, when you try to login through SSH for example, if you're using the SSH button in Cloud Console or use the gcloud compute ssh command.
My suggestion:
a) Download the code to some "neutral" directory, like /assignment and set proper permissions for this folder so that the codingassignment user can access it later.
b) Try first creating the user with adduser - this might solve your problem. First create the user, then use su codingassignment to drop root permissions, if you don't need them when executing the script.

How to change permission of django project?

I have created my project in centOS 7 using root.Each time when saving the project after changes its asking the password.How do I change the permissions of the whole project now ?
To make everything writable by anyone run this in directory with your django project:
chmod -R 0777 ./
Are you sure you want to keep it owned by root? I'd suggest to change the owner to whatever services should use the project.
chown -R <some-user> /path/to/project # user may be www-data
chmod -R 755 /path/to/project

Resolving Fatal status in Supervisor and Django

I am using Digital Ocean Ubuntu server to deploy my Django project and follow this guide to set it all up: A Complete Beginner's Guide to Django - Part 7
I am the process of configurig Gunicorn and Supervisor and I get the following error:
I am logged in as non-root but sudo user that I have created called betofolio. My django project is called betofolio.
Below is a screenshot of what my folders look like:
Following the steps from the tutorial:
Create a new file named gunicorn_start inside /home/betofolio:
vim gunicorn_start
I insert the following:
#!/bin/bash
NAME="betofolio"
DIR=/home/betofolio/betofolio
USER=betofolio
GROUP=betofolio
WORKERS=3
BIND=unix:/home/betofolio/run/gunicorn.sock
DJANGO_SETTINGS_MODULE=betofolio.settings
DJANGO_WSGI_MODULE=betofolio.wsgi
LOG_LEVEL=error
cd $DIR
source ../venv/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DIR:$PYTHONPATH
exec ../venv/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $WORKERS \
--user=$USER \
--group=$GROUP \
--bind=$BIND \
--log-level=$LOG_LEVEL \
--log-file=-
Then I save and exit.
Make this file executable:
chmod u+x gunicorn_start
Create two empty folders, one for the socket file and one to store the logs:
mkdir run logs
Configuring Supervisor
Create an empty log file inside the /home/betofolio/logs/ folder:
touch logs/gunicorn.log
Now create a new supervisor file:
sudo vim /etc/supervisor/conf.d/betofolio.conf
[program:betofolio]
command=/home/betofolio/gunicorn_start
user=betofolio
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/betofolio/logs/gunicorn.log
Then:
sudo supervisorctl reread
sudo supervisorctl update
Now check the status:
sudo supervisorctl status betofolio
I get:
I am new to linux and networking, so I am not sure how to resolve this
I was following the same guide, and ran into the same problem. What solved it for me was realizing I didn't have gunicorn installed in my virtual environment. I had done a pip3 install gunicorn, but you need to do pip install gunicorn. You may have to say sudo before if it says you don't have permission (sudo pip install gunicorn)
go into the logs folder, and open gunicorn.logs. This file is in /home/(user)/logs, and type less gunicorn.logs to see it. It will show you why it's failing. In my case it said it couldn't find gunicorn in the location I had specified within the gunicorn_start file.
Make sure you have the virtual environment activated The command line turns into (name of virtual env) $...
cd into /home/(user)/(venv)/bins, and type ls to see the files in the directory, and see if gunicorn is in there.
After fixing this it still wouldn't run, and I realized in the log files I had some typos in the gunicorn_start file, so that logs file is very handy to troubleshoot.

Cannot Start GUIX Daemon

I've followed all the steps in the installation of GUIX at https://www.gnu.org/software/guix/manual/html_node/Binary-Installation.html#Binary-Installation but when I run
sudo ln -sf ~root/.guix-profile/lib/systemd/system/guix-daemon.service /etc/systemd/system/
sudo systemctl enable guix-daemon
it errors as
Failed to execute operation: Too many levels of symbolic links
The contents of ~root/.guix-profile/lib/systemd/system/guix-daemon.service looks correct. Only one symbolic link is involved.
What's wrong?
Update: I solved it by copying the file as
sudo cp -f ~root/.guix-profile/lib/systemd/system/guix-daemon.service /etc/systemd/system/
instead. It seems there's a limitation on the number of symbolic links.
Update: Next problem:
The command
sudo systemctl start guix-daemon
doesn't printing anything on stdout but the daemon is not created:
ps -fel|grep guix
returns nothing.

Location of celeryd folder on Ubuntu?

I'm following instructions to setup djcelery in production.
Download the daemon script :
https://github.com/ask/celery/blob/master/contrib/generic-init.d/celeryd
Put it in /etc/init.d/celeryd
However, I don't have a folder in /etc/init.d/ called celeryd.
I'm running Ubuntu, celery works if I run manage.py celeryd -l info so its all setup and installed correctly.
Where is the correct folder to add the script on Ubuntu?
They meant "put it in /etc/init.d/ as celeryd". Since it's already named celeryd, just put it in /etc/init.d.