XRootD
Loading...
Searching...
No Matches
XrdFrmPurgMain.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d F r m P u r g M a i n . c c */
4/* */
5/* (c) 2009 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* All Rights Reserved */
7/* Produced by Andrew Hanushevsky for Stanford University under contract */
8/* DE-AC02-76-SFO0515 with the Department of Energy */
9/* */
10/* This file is part of the XRootD software suite. */
11/* */
12/* XRootD is free software: you can redistribute it and/or modify it under */
13/* the terms of the GNU Lesser General Public License as published by the */
14/* Free Software Foundation, either version 3 of the License, or (at your */
15/* option) any later version. */
16/* */
17/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20/* License for more details. */
21/* */
22/* You should have received a copy of the GNU Lesser General Public License */
23/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25/* */
26/* The copyright holder's institutional names and contributor's names may not */
27/* be used to endorse or promote products derived from this software without */
28/* specific prior written permission of the institution or contributor. */
29/******************************************************************************/
30
31/* This is the "main" part of the frm_purge command. Syntax is:
32*/
33static const char *XrdFrmOpts = ":bc:dfhk:l:n:O:s:S:Tvz";
34static const char *XrdFrmUsage =
35
36 " [-b] [-c <cfgfile>] [-d] [-f] [-k {num|sz{k|m|g}|sig] [-l [=]<fn>] [-n name]"
37 " [-O free[,hold]] [-s pidfile] [-S site] [-T] [-v] [-z] [<spaces>] [<paths>]\n";
38/*
39Where:
40
41 -b Run as a true daemon process in the background.
42
43 -c The configuration file. The default is '/opt/xrootd/etc/xrootd.cf'
44
45 -d Turns on debugging mode.
46
47 -f Fix orphaned files (i.e., lock and pin) by removing them.
48
49 -k Keeps num log files or no more that sz log files.
50
51 -l Specifies location of the log file. This may also come from the
52 XrdOucLOGFILE environmental variable.
53 By default, error messages go to standard error.
54
55 -n The instance name.
56
57 -O Run this one time only as a command. The parms are:
58 {free% | sz{k|m|g}[,hold]
59
60 -s The pidfile name.
61
62 -S The site name.
63
64 -T Runs in test mode (no actual purge will occur).
65
66 -v Verbose mode, typically prints each file purged and other details.
67
68 o-t-a The one-time-args run this as a command only once. The args direct
69 the purging process. These may only be specified when -O specified.
70
71 Syntax is: [space] path | space [path]
72*/
73
74/******************************************************************************/
75/* i n c l u d e f i l e s */
76/******************************************************************************/
77
78#include <unistd.h>
79#include <cctype>
80#include <cerrno>
81#include <cstdlib>
82#include <cstring>
83#include <strings.h>
84#include <cstdio>
85#include <sys/param.h>
86
87#include "XrdFrc/XrdFrcTrace.hh"
89#include "XrdFrm/XrdFrmPurge.hh"
90#include "XrdNet/XrdNetOpts.hh"
92#include "XrdOuc/XrdOucUtils.hh"
93#include "XrdSys/XrdSysError.hh"
97#include "XrdSys/XrdSysTimer.hh"
98#include "XrdSys/XrdSysUtils.hh"
99
100using namespace XrdFrc;
101using namespace XrdFrm;
102
103/******************************************************************************/
104/* G l o b a l V a r i a b l e s */
105/******************************************************************************/
106
109
110// The following is needed to resolve symbols for objects included from xrootd
111//
113 XrdOucTrace XrdTrace(&Say);
114
115/******************************************************************************/
116/* T h r e a d I n t e r f a c e s */
117/******************************************************************************/
118
119void *mainServer(void *parg)
120{
121// int udpFD = *static_cast<int *>(parg);
122// XrdFrmPurge::Server(udpFD);
123 return (void *)0;
124}
125
126/******************************************************************************/
127/* m a i n */
128/******************************************************************************/
129
130int main(int argc, char *argv[])
131{
133 extern int mainConfig();
134
135// Turn off sigpipe and host a variety of others before we start any threads
136//
138
139// Set the default stack size here
140//
141 if (sizeof(long) > 4) XrdSysThread::setStackSize((size_t)1048576);
142 else XrdSysThread::setStackSize((size_t)786432);
143
144// Perform configuration
145//
146 Say.logger(&Logger);
147 XrdLog.logger(&Logger);
148 if (!Config.Configure(argc, argv, &mainConfig)) exit(4);
149
150// Display configuration (deferred because mum might have been in effect)
151//
152 if (!Config.isOTO || Config.Verbose) XrdFrmPurge::Display();
153
154// Now simply poke the server every so often
155//
156 if (Config.isOTO) XrdFrmPurge::Purge();
157 else do {if (Config.StopPurge)
158 {int n = 0;
159 struct stat buf;
160 while(!stat(Config.StopPurge, &buf))
161 {if (!n--)
162 {Say.Emsg("PurgMain", Config.StopPurge,
163 "exists; purging suspended."); n = 12;}
165 }
166 }
168 XrdSysTimer::Snooze(Config.WaitPurge);
169 } while(1);
170
171// All done
172//
173 exit(0);
174}
175
176/******************************************************************************/
177/* m a i n C o n f i g */
178/******************************************************************************/
179
181{
182 XrdFrmConfig::Policy *pP = Config.dfltPolicy.Next;
183 XrdFrmConfig::VPInfo *vP = Config.VPList;
184 XrdNetSocket *udpSock;
185 pthread_t tid;
186 int retc, udpFD;
187
188// If test is in effect, remove the fix flag
189//
190 if (Config.Test) Config.Fix = 0;
191
192// Go through the policy list and add each policy
193//
194 while((pP = Config.dfltPolicy.Next))
195 {if (!XrdFrmPurge::Policy(pP->Sname))
197 pP->Hold, pP->Ext);
198 Config.dfltPolicy.Next = pP->Next;
199 delete pP;
200 }
201
202// Make sure we have a public policy
203//
204 if (!XrdFrmPurge::Policy("public"))
205 XrdFrmPurge::Policy("public", Config.dfltPolicy.minFree,
206 Config.dfltPolicy.maxFree,
207 Config.dfltPolicy.Hold,
208 Config.dfltPolicy.Ext);
209
210// Now add any missing policies (we need one for every space)
211//
212 while(vP)
213 {if (!XrdFrmPurge::Policy(vP->Name))
214 XrdFrmPurge::Policy(vP->Name, Config.dfltPolicy.minFree,
215 Config.dfltPolicy.maxFree,
216 Config.dfltPolicy.Hold,
217 Config.dfltPolicy.Ext);
218 vP = vP->Next;
219 }
220
221// Enable the appropriate spaces and over-ride config value
222//
223 if (!XrdFrmPurge::Init(Config.spacList, Config.cmdFree, Config.cmdHold))
224 return 1;
225
226// We are done if this is a one-time-only call
227//
228 if (Config.isOTO) return 0;
229
230// Get a UDP socket for the server
231//
232 if (!(udpSock = XrdNetSocket::Create(&Say, Config.AdminPath,
233 "purg.udp", Config.AdminMode, XRDNET_UDPSOCKET))) return 1;
234 else {udpFD = udpSock->Detach(); delete udpSock;}
235
236// Start the Server thread
237//
238 if ((retc = XrdSysThread::Run(&tid, mainServer, (void *)&udpFD,
239 XRDSYSTHREAD_BIND, "Server")))
240 {Say.Emsg("main", retc, "create server thread"); return 1;}
241
242// All done
243//
244 return 0;
245}
XrdOucPup XrdCmsParser::Pup & Say
static XrdSysLogger Logger
XrdSysError XrdLog(0, "")
static const char * XrdFrmUsage
static const char * XrdFrmOpts
int main(int argc, char *argv[])
XrdSysError XrdLog(0, "")
int mainConfig()
void * mainServer(void *parg)
#define XRDNET_UDPSOCKET
Definition XrdNetOpts.hh:79
#define stat(a, b)
Definition XrdPosix.hh:101
#define XRDSYSTHREAD_BIND
static void Purge()
static XrdFrmPurge * Policy(const char *sname)
static void Display()
static int Init(XrdOucTList *sP=0, long long minV=-1, int hVal=-1)
static XrdNetSocket * Create(XrdSysError *Say, const char *path, const char *fn, mode_t mode, int isudp=0)
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)
static void setStackSize(size_t stsz, bool force=false)
static void Snooze(int seconds)
static bool SigBlock()
XrdFrmConfig Config
char Sname[XrdOssSpace::minSNbsz]