You are not logged in.

#1 2011-08-12 10:02:20

avanc
Member
Registered: 2010-12-21
Posts: 12

Check PID in rc.d script

Hi,

I want to create a rc.d script for tt-rss.
The script has to execute

/usr/bin/php /path/to/update.php -daemon

and send the process into the background.
I read the coresponding wiki page.
However, it isn't a good solution to search for the pid using

pidof -o %PPID /usr/bin/php

since other php processes may run.

What is the correct way to solve this problem?

Sven

Offline

#2 2011-08-12 11:38:02

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Check PID in rc.d script

Maybe use pgrep?

Not sure, but some options might help:

man pgrep wrote:

       -n     Select only the newest (most recently started) of the matching processes.

       -o     Select only the oldest (least recently started) of the matching processes

Offline

#3 2011-08-12 12:27:12

avanc
Member
Registered: 2010-12-21
Posts: 12

Re: Check PID in rc.d script

Thats it!

-f     The pattern is normally only matched against the process name.  When -f is set, the full command line is used.

Thanks!

Offline

#4 2011-08-12 13:12:51

avanc
Member
Registered: 2010-12-21
Posts: 12

Re: Check PID in rc.d script

pgrep works like a charm. However, Iran into a new problem.
I want to start the program as user http.

su -c "my command" http

gives not the desired result. It seems that su with the user http is not allowed...

Offline

#5 2011-08-12 13:24:04

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Check PID in rc.d script

[karol@black ~]$ grep http /etc/passwd
http:x:33:33:http:/srv/http:/bin/false

/bin/false is a dummy shell, so this might be the problem. Can you create another user e.g. http2 with a proper shell?

Offline

#6 2011-08-13 16:07:15

avanc
Member
Registered: 2010-12-21
Posts: 12

Re: Check PID in rc.d script

Ah, that's the problem.

I have to find another solution, since I want to create a package with the rc.d script.

Last edited by avanc (2011-08-13 16:23:43)

Offline

#7 2011-08-14 04:16:27

bluepumpkin
Member
Registered: 2009-08-28
Posts: 58

Re: Check PID in rc.d script

There are two possible solutions that I am aware of:
1. Use a .install script that adds the 'http2' user.
2. Use su with the '-s' flag to specify an alternate shell. This would probably be the better solution. Example:

su http -s "/bin/sh" -c "command"

Last edited by bluepumpkin (2011-08-14 04:17:35)

Offline

Board footer

Powered by FluxBB