<commit_before>#!/usr/bin/python

import json
import os
import subprocess
import sys
import tempfile
from of_daemon import *
from of_util import *
from optparse import OptionParser

if sys.version < '2.5':
    sys.stderr.write("You need Python 2.5 or newer.)\n")
    sys.exit(1)

parser = OptionParser()
parser.add_option("-c", "--cluster-config", dest="cluster_conf")
(opts, args) = parser.parse_args()
if opts.cluster_conf == None:
    sys.stderr.write("you must give a RedFish cluster configuration file\n")
    sys.exit(1)

jo = load_conf_file(opts.cluster_conf)

diter = DaemonIter.from_conf_object(jo, None)
i = 0
for d in diter:
    i = i + 1
    print "processing daemon %d" % i
    print d.jo
    try:
        pid = d.run_with_output("cat " + d.get_pid_file())
        print "error: daemon " + str(i) + " is still running as process " + pid
        continue
    except subprocess.CalledProcessError, e:
        d.run(d.get_binary_path() +  " -c " +  d.get_conf_file())<commit_msg>run.py: delete pid file if pid is dead<commit_after>#!/usr/bin/python

import json
import os
import subprocess
import sys
import tempfile
from of_daemon import *
from of_util import *
from optparse import OptionParser

if sys.version < '2.5':
    sys.stderr.write("You need Python 2.5 or newer.)\n")
    sys.exit(1)

def process_is_running(pid):
    cmd = "ps -p %d" % pid
    try:
        subprocess_check_output(cmd)
        return True
    except:
        return False

parser = OptionParser()
parser.add_option("-c", "--cluster-config", dest="cluster_conf")
(opts, args) = parser.parse_args()
if opts.cluster_conf == None:
    sys.stderr.write("you must give a RedFish cluster configuration file\n")
    sys.exit(1)

jo = load_conf_file(opts.cluster_conf)

diter = DaemonIter.from_conf_object(jo, None)
i = 0
for d in diter:
    i = i + 1
    print "processing daemon %d" % i
    print d.jo
    try:
        pid = d.run_with_output("cat " + d.get_pid_file())
        if (process_is_running(int(pid))):
            print "error: daemon " + str(i) + " is still running as process " + pid
            continue
        else:
            os.unlink(d.get_pid_file())
    except subprocess.CalledProcessError, e:
        pass
    d.run(d.get_binary_path() +  " -c " +  d.get_conf_file())
{'fraction_non_alphanumeric': 0.1227452705675319, 'fraction_numerical': 0.007039155301363837, 'mean_word_length': 3.075268817204301, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '595440', 'n_tokens_mistral': 789, 'n_tokens_neox': 782, 'n_words': 211}