I know what the problem is but I am unsure what a good solution is.
So, I have a uwsgi process that I am using for Graphite to work with Nginx. Here is some background information:
I installed uwsgi from pip and I run uwsgi with the -configfile (.ini):
[uwsgi]
processes = 1
socket = 127.0.0.1:3031
gid = root
uid = root
chdir = /opt/graphite/conf
daemonize = /var/log/graphite/uwsgi.log
#pidfile = /var/run/uwsgi.pid
module = wsgi:application
I have an init script that does the following (I found it on the internet AND this is not done):
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="uwsgi daemon"
NAME=uwsgi
DAEMON=/usr/local/bin/uwsgi
CONFIGFILE=/opt/graphite/conf/$NAME.ini
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
start() {
if [ -f "$PIDFILE" ];then
echo "${NAME} Service already running" >&2
return 1
fi
echo "Starting $NAME" >&2
$DAEMON $CONFIGFILE || echo -n "uwsgi already running"
}
stop() {
$DAEMON --stop $PIDFILE || echo -n "uwsgi not running"
rm -f $PIDFILE
echo "$DAEMON STOPPED."
}
Here is the situation: if I have the .ini file create the PID - it comes up with process ID that is not even close to what the actual PID is. The way it works, as from what I found is that uwsgi starts and then picks up the config file and daemonizes the process. So, if I were to use something along the lines of
ps -ef |awk '/[u]wsgi/{print $2}' > $PIDFILE
it will have 2 process IDs. e.g.
cat /opt/uwsgi/uwsgi.ini
4121
4141
Now the second PID # is the actual running process.
How can I use the awk command to grab the PID but then cut it so that I only touch the PIDFILE with the second #?
I am not sure what command to use. Any ideas?