0

I've written a small python script to act as a LSB compliant init script for an Apache Tomcat service. I've done this script and initial tests on my work laptop which runs openSUSE; The actual deployment is to be made on Ubuntu Server (no jokes about it please, I also feel sad about it).

While the script works perfectly under openSUSE (python 2.7.3), in Ubuntu it's behavior is different (also python 2.7.3)...

When I perform the subprocess.Popen call, in openSUSE it opens the process and then I capture the .pid to a 'control' file...

In Ubuntu, the very same script, the subprocess.Popen call opens two process, one starting with '/usr/bin -c java (...)' and then another 'java (...)'. This is really annoying has the PID written is the one from the /bin/sh...

This is my first time working with Ubuntu Server and though I'm already planning to migrate everything to RHEL (where this non-sense doesn't happen also), I'm still interested in knowing why this happens in Ubuntu and potential ways to dodge around it...

The start function is this one

def start():
    set_user()
    with open(CATALINA_OUT, "a") as log:
        tomcat = subprocess.Popen(TOMCAT_CMD + 'start', shell=True, stdout=log, stderr=log)
    write_pidfile(tomcat.pid)

def set_user():
    os.setgid(int(TOMCAT_GID))
    os.setuid(int(TOMCAT_UID))
4

1 回答 1

1

假设TOMCAT_CMD基本上java -whatever它似乎可能/usr/bin/java只是大多数平台上的 Java(一些变体),而是一个 shell 脚本,在 Ubuntu 上实现了 Debian Java 策略的一些细节,然后exec使用正确的参数:使用系统的首选 Java 二进制文件。对于它的价值,后者通常是一件好事,因为它可以更容易地从一个 Java 实现切换到另一个,但如果你只关心一个特定的实现,那么你可以直接链接到该实现的二进制文件TOMCAT_CMD(和/ 或如果您想完全符合 Debian 并且不能使用 shell 脚本,请在 Python 中重新实现该策略)。

于 2013-04-27T17:28:27.527 回答