NI Linux Real-Time Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Handling stale PID files

Hello,

This question is specifically for the cRIO-9068, but I would imagine the answer is similar for all of the Linux targets.

If I have a service, such as mysql, running it places a lock file (usually just with it's PID in it) on the file system so it knows that it is running (usually so you can't launch multiple instances).  If I loose power to the cRIO, this lock file still exists on disk.  While booting, the service will start and check to see if a lock file exists, and if it does check to see if the PID exists in the process list.

Now, most of the time thi won't be an issue because the PID within the lock file won't match an existing PID (just by likelihood), however this isn't guaranteed.  We have seen a situation where the cRIO is power cycled, mysql comes up and then immediately exists because it thinks that it is already running (because the PID in the lock file is a valid PID).

How does NI suggest handling this situation?  I could write a rc script that deletes all of the PID files, but that sounds a bit silly to me ...

Any and all input is welcome.

Thanks,

-TD

0 Kudos
Message 1 of 5
(4,380 Views)

Not sure if the location for the mysql PID file is configurable, but the usual way to handle this is to store the lock/pid file under /run or /var/volatile.

These locations are mounted as tmpfs (temporary filesystem residing in RAM) and they will get wiped on power loss or re-boot.

Message 2 of 5
(3,776 Views)

Very good point.  I'll take a look to see if it is configurable.

Thanks for the quick response gratian.crisan!!!

-TD

0 Kudos
Message 3 of 5
(3,776 Views)

For those who search for this in the future, this was my solution:

The mysql configuration file is located in /etc/my.cnf (note this is on LabVIEW 2014, with using `opkg install mysql5` to install mysql).

I modified the pid-file field to read `/var/volatile/lock/mysql.pid`.  Save the file and reboot the cRIO-9068.  Simple as that.

@gratian.crisan, thank you again for the support!

-TD

0 Kudos
Message 4 of 5
(3,776 Views)

PID files naturally belong into /var/run - standard for aeons and usually it's an tmpfs (in older times it was just cleared on bootup).

 

Linux Embedded / Kernel Hacker / BSP / Driver development / Systems engineering
0 Kudos
Message 5 of 5
(3,541 Views)