You are not logged in.

#1 2013-11-08 03:23:00

miek
Member
Registered: 2012-09-03
Posts: 25
Website

[Solved] systemd virtualenv leave zombies after stop/restart

Hi,

I've been running a django-based forum for some time now and recently installed it on a beaglebone black with arch. I've had quite a few generations of this forum (it started as an html blog, then python blog, then php blog, then python forum, then django forum, etc. etc. for a few years). Anyways, this time I wanted to do a clean setup using virtualenv2 and git.

So my virtualenv2 (python2) is in /srv/http, and I wanted to start the forum using systemd. I used an ugly cron job to start the service @reboot after ~20 seconds (so that the network has time to get up and running), and the service does start successfully. My problem is that for some reason, I can't terminate it without rebooting.

I'm guessing that this has something to do with virtualenv but I'm not quite sure. Here are the relevant files:

root crontab:

@reboot /usr/bin/sleep 20 && /usr/bin/systemctl start forum > /var/log/cron_forum.log 2>&1

/usr/lib/systemd/system/forum.service:

[Unit]
Description=Forum huitcent
After=network.target

[Service]
ExecStartPre=/usr/bin/rm -rf /var/run/forum ; /usr/bin/mkdir /var/run/forum ; /usr/bin/chown -R html:html /var/run/forum ; /usr/bin/mount -t nfs4 alarmpi:/partage/Media /srv/http/huitcent/media
ExecStart=/usr/bin/bash -c 'source /srv/http/bin/activate ; /srv/http/bin/uwsgi --socket /var/run/forum/forum.sock --chmod-socket --processes 1 --master --uid html --gid html --logto /var/log/forum.log --wsgi-file /srv/http/huitcent/uwsgi/wsgi.py'
ExecStop=/usr/bin/bash -c 'deactivate ; /usr/bin/rm -rf /var/run/forum' ; /usr/bin/umount /srv/http/huitcent/media

[Install]
WantedBy=multi-user.target

So after a reboot, when the 20 seconds delay is over, systemctl status returns:

[root@bbbforum system]# systemctl status forum
forum.service - Forum huitcent
   Loaded: loaded (/usr/lib/systemd/system/forum.service; disabled)
   Active: active (running) since Thu 2013-11-07 21:57:04 EST; 12min ago
  Process: 301 ExecStartPre=/usr/bin/mount -t nfs4 alarmpi:/partage/Media /srv/http/huitcent/media (code=exited, status=0/SUCCESS)
  Process: 298 ExecStartPre=/usr/bin/chown -R html:html /var/run/forum (code=exited, status=0/SUCCESS)
  Process: 295 ExecStartPre=/usr/bin/mkdir /var/run/forum (code=exited, status=0/SUCCESS)
  Process: 293 ExecStartPre=/usr/bin/rm -rf /var/run/forum (code=exited, status=0/SUCCESS)
 Main PID: 316 (bash)
   CGroup: /system.slice/forum.service
           ├─316 /usr/bin/bash -c source /srv/http/bin/activate ; /srv/http/bin/uwsgi --socket /var/run/forum/forum.sock --chmod-socket --processes 1 --master --uid html --gid html --logto /var/log/forum.log --wsgi-file /srv/http/huitce...
           ├─321 /srv/http/bin/uwsgi --socket /var/run/forum/forum.sock --chmod-socket --processes 1 --master --uid html --gid html --logto /var/log/forum.log --wsgi-file /srv/http/huitcent/uwsgi/wsgi.py
           └─322 /srv/http/bin/uwsgi --socket /var/run/forum/forum.sock --chmod-socket --processes 1 --master --uid html --gid html --logto /var/log/forum.log --wsgi-file /srv/http/huitcent/uwsgi/wsgi.py

...which is fine. Basically:

init
|---316
    |---321
        |---322

If, however, I stop the service, only processes 316 and 322 above stop. Process 321 becomes orphan (not shown with systemd status anymore, but adopted by init) but generates a new subprocess to replace 322 (361 at the moment). If I start the service again, 321/322 remain alive (321 owned by init), and a new trio is generated. It gets messy quickly.

Any idea what I might be doing wrong? Should I simply create a bash script take out virtualenv of the service file? Why would that be required?

Thanks,

Mike

Last edited by miek (2013-11-13 17:52:40)

Offline

#2 2013-11-13 17:52:27

miek
Member
Registered: 2012-09-03
Posts: 25
Website

Re: [Solved] systemd virtualenv leave zombies after stop/restart

Hum afterall the error had nothing to do with virtualenv, I simply shouldn't have used the "--master" option for uwsgi. Here's my new forum.service:

[Unit]
Description=Forum huitcent
After=network.target

[Service]
ExecStartPre=/usr/bin/rm -rf /var/run/forum ; /usr/bin/mkdir /var/run/forum ; /usr/bin/chown -R html:html /var/run/forum ; /usr/bin/mount -t nfs4 alarmpi:/partage/Media /srv/http/huitcent/media
ExecStart=/usr/bin/bash -c "source /srv/http/bin/activate ; /srv/http/bin/uwsgi --socket /var/run/forum/forum.sock --chmod-socket --processes 1 --uid html --gid html --logto /var/log/forum.log --wsgi-file /srv/http/huitcent/uwsgi/wsgi.py"
ExecStop=/usr/bin/rm -rf /var/run/forum ; /usr/bin/umount /srv/http/huitcent/media

[Install]
WantedBy=multi-user.target

Offline

Board footer

Powered by FluxBB