Re: [systemd-devel] Best approach to run python service in virtualenv with systemd

2016-04-17 Thread Lennart Poettering
On Thu, 14.04.16 15:40, Stanislav Kopp (stask...@gmail.com) wrote:

> yes, looks normal to me.
> 
> mercurial:/srv/kallithea# cat kallithea.pid
> 7410mercurial:/srv/kallithea#

So this suggests that your service doesn't place a trailing newline in
that file, which isn't pretty, but actually shouldn't really matter,
as systemd is fine both with and without it.

> 7410 is the right PID of process.

My only guess is that your package is writing the PID file only after
having double forked or so. That means systemd might read the file
before it is correctly written by your daemon.

The error message you see is generated when the string in that file is
not a valid PID. It's generated by this piece of code:

https://github.com/systemd/systemd/blob/master/src/core/service.c#L797

My guess is now that your service creates the PID file early, but does
not actually write the PID to it, before returning, but delays that in
some racy way. This way, the PID file will sometimes exist but be
empty when systemd tries to read it and you see the error you are
seeing.

To verify that, consider using gdb to attach to PID 1. Set a
breakpoint on the log_warning() invocation, run your service, and then
check what the "p" string contains...

Other than that, check that your service is properly writing its PID
files, i.e. before returning in the parent process. See daemon(7) for
details.

(Of course, even better would be do drop the whole PID file, and
forking madness and use Type=notify or so, and sd_notify() – or some
Python equivalent – to let systemd know when you are complete.)

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] Best approach to run python service in virtualenv with systemd

2016-04-13 Thread Stanislav Kopp
Hi all,

I'm trying to run kallithea using virtualenv, it kinda works (I can
stop/start service) with this unit file


[Unit]
Description=Start Kallithea service
After=network.target

[Service]
Type=forking
User=kallithea
WorkingDirectory=/srv/kallithea
ExecStart=/srv/kallithea/venv/bin/python2
/srv/kallithea/venv/bin/paster serve --daemon
--pid-file=/srv/kallithea/kallithea.pid
--log-file=/srv/kallithea/kallithea.log my.ini
PIDFile=/srv/kallithea/kallithea.pid

[Install]
WantedBy=multi-user.target
#

but I always see "Failed to read PID from file
/srv/kallithea/kallithea.pid: Invalid argument" in "systemctl status",
I know that "PIDFile" option isn't a best practice and should be
avoided, but withou it service doesn't running.
Is there any better methods to run it or at least remove this pid error message?


Thanks,
Stan
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel