49 #include "maintagent.h"
52 char BuildVersion[]=
"maintagent build version: " VERSION_S
" r(" COMMIT_HASH_S
").\n";
60 int main(
int argc,
char **argv)
65 char agentRev[myBUFSIZ];
66 char *agentDesc =
"Maintenance Agent";
77 snprintf(agentRev,
sizeof(agentRev),
"%s.%s", VERSION, COMMIT_HASH);
81 int validateFoldersExe = 0;
82 int verifyFilePermsExe = 0;
83 int removeUploadsExe = 0;
84 int normalizeUploadPrioritiesExe = 0;
85 int removeTempsExe = 0;
86 int vacAnalyzeExe = 0;
87 int processExpiredExe = 0;
88 int removeOrphanedFilesExe = 0;
89 int reIndexAllTablesExe = 0;
90 int removeOrphanedRowsExe = 0;
91 int removeOrphanedLogs = 0;
92 int removeExpiredTokensExe = 0;
93 int tokenRetentionPeriod = 30;
94 int removeOldGoldExe = 0;
95 int removeOldLogsExe = 0;
97 char oldLogsDate[11] = {};
100 while ((cmdopt = getopt(argc, argv,
"aAc:DEFghiIl:LNo:pPRt:TUvVZ")) != -1)
105 if (validateFoldersExe == 0)
108 validateFoldersExe = 1;
110 if (verifyFilePermsExe == 0)
113 verifyFilePermsExe = 1;
115 if (removeUploadsExe == 0)
118 removeUploadsExe = 1;
120 if (normalizeUploadPrioritiesExe == 0)
123 normalizeUploadPrioritiesExe = 1;
125 if (removeTempsExe == 0)
130 if (vacAnalyzeExe == 0)
135 if (removeOrphanedLogs == 0)
138 removeOrphanedLogs = 1;
142 if (validateFoldersExe == 0)
145 validateFoldersExe = 1;
147 if (verifyFilePermsExe == 0)
150 verifyFilePermsExe = 1;
152 if (removeUploadsExe == 0)
155 removeUploadsExe = 1;
157 if (normalizeUploadPrioritiesExe == 0)
160 normalizeUploadPrioritiesExe = 1;
162 if (removeTempsExe == 0)
167 if (vacAnalyzeExe == 0)
172 if (processExpiredExe == 0)
175 processExpiredExe = 1;
177 if (removeOrphanedFilesExe == 0)
180 removeOrphanedFilesExe = 1;
182 if (reIndexAllTablesExe == 0)
185 reIndexAllTablesExe = 1;
187 if (removeOrphanedRowsExe == 0)
190 removeOrphanedRowsExe = 1;
192 if (removeOrphanedLogs == 0)
195 removeOrphanedLogs = 1;
199 if (vacAnalyzeExe == 0)
206 if (validateFoldersExe == 0)
209 validateFoldersExe = 1;
219 if (normalizeUploadPrioritiesExe == 0)
222 normalizeUploadPrioritiesExe = 1;
226 if (removeOldGoldExe == 0)
228 strncpy(goldOlder, optarg, 10);
230 removeOldGoldExe = 1;
237 if (verifyFilePermsExe == 0)
240 verifyFilePermsExe = 1;
244 if (removeUploadsExe == 0)
247 removeUploadsExe = 1;
251 if (removeExpiredTokensExe == 0)
253 tokenRetentionPeriod = atol(optarg);
255 removeExpiredTokensExe = 1;
259 if (removeTempsExe == 0)
266 if (processExpiredExe == 0)
269 processExpiredExe = 1;
273 if (removeOrphanedFilesExe == 0)
276 removeOrphanedFilesExe = 1;
280 if (reIndexAllTablesExe == 0)
283 reIndexAllTablesExe = 1;
287 if (removeOrphanedRowsExe == 0)
290 removeOrphanedRowsExe = 1;
294 if (removeOldLogsExe == 0)
296 strncpy(oldLogsDate, optarg, 10);
298 removeOldLogsExe = 1;
302 if (removeOrphanedLogs == 0)
305 removeOrphanedLogs = 1;
PGconn * pgConn
Database connection.
void exitNow(int exitVal)
Exit function. This does all cleanup and should be used instead of calling exit() or main() return.
FUNCTION int fo_GetAgentKey(PGconn *pgConn, const char *agent_name, long Upload_pk, const char *rev, const char *agent_desc)
Get the latest enabled agent key (agent_pk) from the database.
char * fo_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.
int agent_verbose
Common verbose flags for the agents, this is used so that the scheduler can change the verbose level ...
void fo_scheduler_connect(int *argc, char **argv, PGconn **db_conn)
Establish a connection between an agent and the scheduler.
FUNCTION void removeOrphanedRows()
remove orphaned rows from fossology database
FUNCTION void verifyFilePerms(int fix)
Verify and optionally fix file permissions.
FUNCTION void deleteOldGold(char *date)
Delete gold files which are older than specified date.
FUNCTION void removeTemps()
Remove orphaned temp tables from deprecated pkgmettagetta and old delagent.
fo_dbManager * dbManager
fo_dbManager object
FUNCTION void reIndexAllTables()
reindex of all indexes in fossology database
FUNCTION void removeOldLogFiles(const char *olderThan)
FUNCTION void removeUploads()
Remove Uploads with no pfiles.
FUNCTION void removeOrphanedLogFiles()
FUNCTION void processExpired()
Process expired uploads (slow)
FUNCTION void removeExpiredTokens(long int retentionPeriod)
remove expired personal access tokens from fossology database
FUNCTION void validateFolders()
Validate folder and foldercontents tables.
FUNCTION void removeOrphanedFiles()
Remove orphaned files from the repository (slow) Loop through each file in the repository and make su...
FUNCTION void vacAnalyze()
Do database vacuum and analyze.
FUNCTION void deleteOrphanGold()
Delete orphaned gold files from the repository.
FUNCTION void normalizeUploadPriorities()
Normalize priority of Uploads.
FUNCTION void usage(char *name)
int main(int argc, char **argv)
Main entry point for the agent.
fo_dbManager * fo_dbManager_new(PGconn *dbConnection)
Create and initialize new fo_dbManager object.