2

Pid files not created in /var/run folder.

rc.d script:

#!/bin/sh

. /etc/rc.subr

name=phpcgi
rcvar=phpcgi_enable
pidfile=/var/run/${name}.pid
command=/usr/local/bin/php-cgi

load_rc_config $name
run_rc_command "$1"

it's working fine but the problem is with pid file. it can not find it when i try to "service phpcgi stop". permissions are correct. how can i fix it ?

dima.h
  • 145
  • 1
  • 6

2 Answers2

2

Try turning on tracing to make the script tell you what it is doing at each step. You'll get lots of output, so I'd recommend capturing it using a script session. Replace the first line of the script with

#!/bin/sh -x

and then run:

# script phpcgi-trace
# service phpcgi start
# service phpcgi stop
# ^D

The file phpcgi-trace will contain a record of everything that the script tries to do. Search through it for clues as to why it's not dropping a pidfile.

EDIT

Note that the pidfile= line in the rc script is there to tell rc how to check the status of the controlled program, or how to stop it. It's not there to tell rc to write a pidfile - that's the responsibility of the controlled program.

If phpcgi doesn't write a pidfile when it starts, the easiest thing to do is to just omit the pidfile= line, and let rc use the process name to check status, etc.

D_Bye
  • 401
  • 2
  • 5
  • There was nothing interesting in script output the way you point me. It just write command line history and nothing else. And the logs are empty. – dima.h Apr 04 '12 at 11:48
  • See my edited answer for more information. We'll get there! – D_Bye Apr 04 '12 at 13:09
0

The pidfile argument is only used by the rc script to check if the process is already running. The script does not create the file for you. The program you're running must create the file itself.

Alternatively you can add the this line to the end of your RC script and the pid file should be created.

echo ${rc_pid} > ${pidfile}
Chris S
  • 77,337
  • 11
  • 120
  • 212
  • This didn't work for me, as ${rc_pid} only returns an empty string. But I found out that the daemon program can be started with the `-P $path_to_pidfile` argument, which works. – Georg Pfolz Feb 27 '19 at 10:18