Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

My understanding is that it's generally a good idea to create a PID file for daemon processes and that startproc is a good way to start these daemons.

I know that startproc takes -i and -p arguments that refer to PID files but it doesn't create a PID file or update it with the ID of the daemon process that it starts. Echoing $! also doesn't give the right process identifier when startproc is used.

Does anyone have any advice as to how the PID of a daemon started with startproc can be elicited?


For what it's worth, I'm writing an rc script and want to start a JVM as a non-privileged user. I don't really want to give this user a login shell (so su -c "java ..." user is not an option) and I don't really want a root process hanging around while the daemon is running either (which rules out sudo -Eu user java ...). So, while I acknowledge that these are possible workarounds, I don't find either of them to be ideal. Please feel free, though, to correct me if my assumptions about these alternatives are wrong.

share|improve this question
    
What's your OS? Is pidof available? The manpage for startproc on linux-tutorial.info/… doesn't know a -i option. –  ott-- Jun 12 '13 at 2:58
    
I'm using OpenSuSE 11.4. pidof is available but given that there may be several JVMs running this may be tricky. –  Adam George Jun 12 '13 at 9:35
    
You could compare the /proc/<pid>/cmdline of each pidof java to determine if such a daemon is already running. Note that the cmdline args are separated by \0 characters. –  ott-- Jun 12 '13 at 10:59
add comment

1 Answer

up vote 0 down vote accepted

Looks like nobody knows a way of doing this, then.

Instead, I just did what Tomcat basically does; write a shell script and invoke this from my service instead of invoking java directly.

This shell script also takes care of creating the PID file using echo $! after starting the JVM. For shutdown, I've written a similar script that checks this PID file and removes it after a successful shutdown. Both scripts are invoked using sudo -Eu $USER script_name.sh from the service.

Technically, this doesn't answer my question because the solution doesn't use startproc at all, but it works and avoids the cumbersome task of comparing command lines of running processes.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.