Question

I'm new to Linux and have inherited keeping our single linux server running. It's our SVN server so it's relatively important.

Turns out the guy who maintained it before me had a cron task to email him when there are too many svnserve processes running, as they seem to be left dangling instead of terminating correctly.

First part of the question is, given that I run

ps -fu cvsuser

and get a list of the processes, how can I kill the ones that have an STIME not today? For example, something like

kill where STIME = Oct30

The other question is, does anyone know how to avoid having these dangling svnserve processes? (Here's the other question.)

Was it helpful?

Solution

Just for the fun of it (GNU bash, version 3.2.39)

ps h -u cvsuser -o pid,start   # h - no header, only output pid and start
    | grep -v ':'              # exclude entries from the last 24 hours
    | egrep -o '^\ *[0-9]+'    # get the pid (handling possible leading space)
    | xargs -i echo kill "{}"  # pretend to kill - take out the echo if you're happy

This relies on the following from 'man ps' STANDARD FORMAT SPECIFIERS:

If the process was started less than 24 hours ago, the output format is "HH:MM:SS", else it is " mmm dd" (where mmm is a three-letter month name).

OTHER TIPS

At the risk of suggesting you re-engineer your infrastructure, I've had great results using Apache and mod dav svn instead of svnserve - Apache's httpd is pretty darn bulletproof after the last decade or so of production usage.

for our cvs/svn/git server, rather than using a cronjob that looked for old processes by relying on the output of ps, we used the timeout program.

$ grep server /etc/xinetd.d/svnserve
server          = /usr/bin/timeout
server_args     = 12h /usr/bin/svnserve -i -R -r /svnroot

replace "12h" with an appropriate timeout for your site (although i can't imagine most people needing more than 12 hours to checkout a single repo)

Off the top of my head, I would do something like this:

ps -fu username | awk '$5 !~ /[0-9]:[0-9]/ { print $2 }' | xargs kill

Since the fifth field of the ps output shows day-old processes with the month/day (e.g. Oct31) and without the time (e.g. 12:32), the regex with awk simply excludes those processes whose fifth field is still a time. I am assuming, possibly wrongly, that ps starts to show the date only for processes that have been running for more than 24 hours.

To identify and kill the processes:

ps h -u csvuser -o pid,lstart | grep 'May 29' | sed 's/^ \+//' | 
cut -d ' ' -f 1 | xargs -n 1 kill

The ps command will find all processes owned by csvuser and output the pid and start time:

16324 Thu May 29 04:02:06 2008
22144 Tue Jul 22 04:02:05 2008
11315 Wed Oct  8 04:02:00 2008

The grep command will find the date you are looking for

16324 Thu May 29 04:02:06 2008

The sed command will remove leading spaces for cut,

The cut command will output only the first field:

16324

And the xargs command will run the kill command once for each line passing the pid as the argument. Replace the grep statement as needed to match whatever you need.

As for why the svnserve processes are not exiting properly, I don't know, I haven't seen this on my subversion servers, you probably should open a separate question for this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top