Skip to content

Commit

Permalink
Merge pull request #1515
Browse files Browse the repository at this point in the history
daemons: set CLI11 error exit code to `41` and bareos config parsing error exit code to `42`
  • Loading branch information
BareosBot committed Sep 20, 2023
2 parents ec19197 + cc4f425 commit 3432b47
Show file tree
Hide file tree
Showing 41 changed files with 345 additions and 242 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -96,6 +96,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
- devtools: Update python dependencies [PR #1531]
- webui: upgrade bootstrap to version 3.4.1 [PR #1550]
- bareos-check-sources: ignore bootstrap*.css [PR #1556]
- daemons: set CLI11 error exit code to `41` and bareos config parsing error exit code to `42` [PR #1515]

### Removed
- remove no longer used pkglists [PR #1335]
Expand Down Expand Up @@ -237,6 +238,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
[PR #1508]: https://github.com/bareos/bareos/pull/1508
[PR #1511]: https://github.com/bareos/bareos/pull/1511
[PR #1512]: https://github.com/bareos/bareos/pull/1512
[PR #1515]: https://github.com/bareos/bareos/pull/1515
[PR #1516]: https://github.com/bareos/bareos/pull/1516
[PR #1520]: https://github.com/bareos/bareos/pull/1520
[PR #1521]: https://github.com/bareos/bareos/pull/1521
Expand Down
9 changes: 5 additions & 4 deletions core/platforms/systemd/bareos-dir.service.in
Expand Up @@ -6,15 +6,14 @@
Description=Bareos Director Daemon service
Documentation=man:bareos-dir(8)
Requires=network.target nss-lookup.target time-sync.target
After=network-online.target nss-lookup.target remote-fs.target time-sync.target postgresql.service
After=network-online.target nss-lookup.target local-fs.target remote-fs.target time-sync.target postgresql.service
# Dependency about the database
# We let administrators decide if they need it (if local db instance)
# Wants=@DEFAULT_DB_TYPE@.service
# Check if working dir exist
ConditionPathExists=@working_dir@
# Limit the number of restart per day to 10
# Limit the number of restart per day
StartLimitIntervalSec=1d
StartLimitBurst=10

[Service]
Type=simple
Expand All @@ -30,8 +29,10 @@ LimitNOFILE=8192:524288
# Restart on failure, wait 30 seconds
Restart=on-failure
RestartSec=30
# Limit the number of restart to 10. to reset counter use systemctl reset-failed bareos-dir
StartLimitBurst=10
# Don't restart on wrong exec arguments and configuration errors.
RestartPreventExitStatus=109 1
RestartPreventExitStatus=41 42


[Install]
Expand Down
9 changes: 5 additions & 4 deletions core/platforms/systemd/bareos-fd.service.in
Expand Up @@ -6,12 +6,11 @@
Description=Bareos File Daemon service
Documentation=man:bareos-fd(8)
Requires=network.target nss-lookup.target time-sync.target
After=network-online.target nss-lookup.target remote-fs.target time-sync.target
After=network-online.target nss-lookup.target local-fs.target remote-fs.target time-sync.target
# Check if working dir exist
ConditionPathExists=@working_dir@
# Limit the number of restart per day to 10
# Limit the number of restart per day
StartLimitIntervalSec=1d
StartLimitBurst=10

[Service]
Type=simple
Expand All @@ -26,8 +25,10 @@ LimitNOFILE=8192:524288
# Restart on failure, wait 30 seconds
Restart=on-failure
RestartSec=30
# Limit the number of restart to 10. to reset counter use systemctl reset-failed bareos-fd
StartLimitBurst=10
# Don't restart on wrong exec arguments and configuration errors.
RestartPreventExitStatus=109 1
RestartPreventExitStatus=41 42


[Install]
Expand Down
11 changes: 6 additions & 5 deletions core/platforms/systemd/bareos-sd.service.in
Expand Up @@ -6,12 +6,11 @@
Description=Bareos Storage Daemon service
Documentation=man:bareos-sd(8)
Requires=network.target nss-lookup.target time-sync.target
After=network-online.target nss-lookup.target remote-fs.target time-sync.target
After=network-online.target nss-lookup.target local-fs.target remote-fs.target time-sync.target
# Check if working dir exist
ConditionPathExists=@working_dir@
# Limit the number of restart per day to 10
# Limit the number of restart per day
StartLimitIntervalSec=1d
StartLimitBurst=10

[Service]
Type=simple
Expand All @@ -20,13 +19,15 @@ Group=@sd_group@
WorkingDirectory=@working_dir@
ExecStart=@sbindir@/bareos-sd -f
SuccessExitStatus=0 15
# Increase the the maximum number of open file descriptors
# Increase the maximum number of open file descriptors
LimitNOFILE=8192:524288
# Restart on failure, wait 30 seconds
Restart=on-failure
RestartSec=30
# Limit the number of restart to 10. to reset counter use systemctl reset-failed bareos-fd
StartLimitBurst=10
# Don't restart on wrong exec arguments and configuration errors.
RestartPreventExitStatus=109 1
RestartPreventExitStatus=41 42


[Install]
Expand Down
27 changes: 14 additions & 13 deletions core/src/console/console.cc
Expand Up @@ -27,6 +27,7 @@
*/

#include "include/bareos.h"
#include "include/exit_codes.h"
#include "console/console_conf.h"
#include "console/console_globals.h"
#include "console/auth_pam.h"
Expand Down Expand Up @@ -917,7 +918,7 @@ int main(int argc, char* argv[])

AddDeprecatedExportOptionsHelp(console_app);

CLI11_PARSE(console_app, argc, argv);
ParseBareosApp(console_app, argc, argv);

if (!no_signals) { InitSignals(TerminateConsole); }

Expand All @@ -936,19 +937,19 @@ int main(int argc, char* argv[])
if (export_config_schema) {
PoolMem buffer;

my_config = InitConsConfig(configfile, M_ERROR_TERM);
my_config = InitConsConfig(configfile, M_CONFIG_ERROR);
PrintConfigSchemaJson(buffer);
printf("%s\n", buffer.c_str());
exit(0);
exit(BEXIT_SUCCESS);
}

my_config = InitConsConfig(configfile, M_ERROR_TERM);
my_config->ParseConfig();
my_config = InitConsConfig(configfile, M_CONFIG_ERROR);
my_config->ParseConfigOrExit();

if (export_config) {
my_config->DumpResources(PrintMessage, NULL);
TerminateConsole(0);
exit(0);
TerminateConsole(BEXIT_SUCCESS);
exit(BEXIT_SUCCESS);
}

if (InitCrypto() != 0) {
Expand All @@ -969,8 +970,8 @@ int main(int argc, char* argv[])
}

if (test_config) {
TerminateConsole(0);
exit(0);
TerminateConsole(BEXIT_SUCCESS);
exit(BEXIT_SUCCESS);
}

(void)WSA_Init(); /* Initialize Windows sockets */
Expand Down Expand Up @@ -1097,16 +1098,16 @@ int main(int argc, char* argv[])

if (history_file.size()) { ConsoleUpdateHistory(history_file.c_str()); }

TerminateConsole(0);
return 0;
TerminateConsole(BEXIT_SUCCESS);
return BEXIT_SUCCESS;
}

static void TerminateConsole(int sig)
{
static bool already_here = false;

if (already_here) { /* avoid recursive temination problems */
exit(1);
exit(BEXIT_FAILURE);
}
already_here = true;
StopWatchdog();
Expand All @@ -1117,7 +1118,7 @@ static void TerminateConsole(int sig)
ConTerm();
WSACleanup(); /* Cleanup Windows sockets */

if (sig != 0) { exit(1); }
if (sig != 0) { exit(BEXIT_FAILURE); }
return;
}

Expand Down
45 changes: 23 additions & 22 deletions core/src/dird/dbcheck.cc
Expand Up @@ -24,6 +24,7 @@
// Program to check a BAREOS database for consistency and to make repairs

#include "include/bareos.h"
#include "include/exit_codes.h"
#include "cats/cats.h"
#include "lib/runscript.h"
#include "lib/cli.h"
Expand Down Expand Up @@ -229,7 +230,7 @@ static void eliminate_duplicate_paths()
= "SELECT Path, count(Path) as Count FROM Path "
"GROUP BY Path HAVING count(Path) > 1";

if (!MakeNameList(db, query, &name_list)) { exit(1); }
if (!MakeNameList(db, query, &name_list)) { exit(BEXIT_FAILURE); }
printf(_("Found %d duplicate Path records.\n"), name_list.num_ids);
fflush(stdout);
if (name_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
Expand All @@ -245,7 +246,7 @@ static void eliminate_duplicate_paths()
Bsnprintf(buf, sizeof(buf), "SELECT PathId FROM Path WHERE Path='%s'",
esc_name);
if (verbose > 1) { printf("%s\n", buf); }
if (!MakeIdList(db, buf, &id_list)) { exit(1); }
if (!MakeIdList(db, buf, &id_list)) { exit(BEXIT_FAILURE); }
if (verbose) {
printf(_("Found %d for: %s\n"), id_list.num_ids, name_list.name[i]);
}
Expand Down Expand Up @@ -278,7 +279,7 @@ static void eliminate_orphaned_jobmedia_records()

printf(_("Checking for orphaned JobMedia entries.\n"));
fflush(stdout);
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
// Loop doing 300000 at a time
while (id_list.num_ids != 0) {
printf(_("Found %d orphaned JobMedia records.\n"), id_list.num_ids);
Expand All @@ -304,7 +305,7 @@ static void eliminate_orphaned_jobmedia_records()
} else {
break; /* get out if not updating db */
}
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
}
fflush(stdout);
}
Expand All @@ -319,7 +320,7 @@ static void eliminate_orphaned_file_records()
printf(_("Checking for orphaned File entries. This may take some time!\n"));
if (verbose > 1) { printf("%s\n", query); }
fflush(stdout);
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
// Loop doing 300000 at a time
while (id_list.num_ids != 0) {
printf(_("Found %d orphaned File records.\n"), id_list.num_ids);
Expand All @@ -342,7 +343,7 @@ static void eliminate_orphaned_file_records()
} else {
break; /* get out if not updating db */
}
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
}
fflush(stdout);
}
Expand All @@ -360,7 +361,7 @@ static void eliminate_orphaned_path_records()
printf(_("Checking for orphaned Path entries. This may take some time!\n"));
if (verbose > 1) { printf("%s\n", query.c_str()); }
fflush(stdout);
if (!MakeIdList(db, query.c_str(), &id_list)) { exit(1); }
if (!MakeIdList(db, query.c_str(), &id_list)) { exit(BEXIT_FAILURE); }
// Loop doing 300000 at a time
while (id_list.num_ids != 0) {
printf(_("Found %d orphaned Path records.\n"), id_list.num_ids);
Expand All @@ -382,7 +383,7 @@ static void eliminate_orphaned_path_records()
} else {
break; /* get out if not updating db */
}
if (!MakeIdList(db, query.c_str(), &id_list)) { exit(1); }
if (!MakeIdList(db, query.c_str(), &id_list)) { exit(BEXIT_FAILURE); }
}
}

Expand All @@ -397,7 +398,7 @@ static void eliminate_orphaned_fileset_records()
"WHERE Job.FileSetId IS NULL";
if (verbose > 1) { printf("%s\n", query); }
fflush(stdout);
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
printf(_("Found %d orphaned FileSet records.\n"), id_list.num_ids);
fflush(stdout);
if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
Expand Down Expand Up @@ -438,7 +439,7 @@ static void eliminate_orphaned_client_records()
"WHERE Job.ClientId IS NULL";
if (verbose > 1) { printf("%s\n", query); }
fflush(stdout);
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
printf(_("Found %d orphaned Client records.\n"), id_list.num_ids);
if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
for (int i = 0; i < id_list.num_ids; i++) {
Expand Down Expand Up @@ -478,7 +479,7 @@ static void eliminate_orphaned_job_records()
"WHERE Client.Name IS NULL";
if (verbose > 1) { printf("%s\n", query); }
fflush(stdout);
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
printf(_("Found %d orphaned Job records.\n"), id_list.num_ids);
fflush(stdout);
if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
Expand Down Expand Up @@ -551,7 +552,7 @@ static void eliminate_admin_records()
"WHERE Job.Type='D'";
if (verbose > 1) { printf("%s\n", query); }
fflush(stdout);
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
printf(_("Found %d Admin Job records.\n"), id_list.num_ids);
if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
for (int i = 0; i < id_list.num_ids; i++) {
Expand Down Expand Up @@ -584,7 +585,7 @@ static void eliminate_restore_records()
"WHERE Job.Type='R'";
if (verbose > 1) { printf("%s\n", query); }
fflush(stdout);
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
printf(_("Found %d Restore Job records.\n"), id_list.num_ids);
if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
for (int i = 0; i < id_list.num_ids; i++) {
Expand Down Expand Up @@ -618,7 +619,7 @@ static void repair_bad_filenames()
"WHERE Name LIKE '%/'";
if (verbose > 1) { printf("%s\n", query); }
fflush(stdout);
if (!MakeIdList(db, query, &id_list)) { exit(1); }
if (!MakeIdList(db, query, &id_list)) { exit(BEXIT_FAILURE); }
printf(_("Found %d bad Filename records.\n"), id_list.num_ids);
if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
for (i = 0; i < id_list.num_ids; i++) {
Expand Down Expand Up @@ -675,7 +676,7 @@ static void repair_bad_paths()
db->FillQuery(query, BareosDb::SQL_QUERY::get_bad_paths_0);
if (verbose > 1) { printf("%s\n", query.c_str()); }
fflush(stdout);
if (!MakeIdList(db, query.c_str(), &id_list)) { exit(1); }
if (!MakeIdList(db, query.c_str(), &id_list)) { exit(BEXIT_FAILURE); }
printf(_("Found %d bad Path records.\n"), id_list.num_ids);
fflush(stdout);
if (id_list.num_ids && verbose && yes_no(_("Print them? (yes/no): "))) {
Expand Down Expand Up @@ -854,16 +855,16 @@ int main(int argc, char* argv[])
manual_args->add_option("port", dbport, "Database port")
->check(CLI::PositiveNumber);

CLI11_PARSE(dbcheck_app, argc, argv);
ParseBareosApp(dbcheck_app, argc, argv);

const char* db_driver = "postgresql";

if (!configfile.empty() || manual_args->count_all() == 0) {
CatalogResource* catalog = nullptr;
int found = 0;

my_config = InitDirConfig(configfile.c_str(), M_ERROR_TERM);
my_config->ParseConfig();
my_config = InitDirConfig(configfile.c_str(), M_CONFIG_ERROR);
my_config->ParseConfigOrExit();

foreach_res (catalog, R_CATALOG) {
if (!catalogname.empty()
Expand All @@ -889,7 +890,7 @@ int main(int argc, char* argv[])
"[%s]\n"),
configfile.c_str());
}
exit(1);
exit(BEXIT_FAILURE);
} else {
{
ResLocker _{my_config};
Expand All @@ -898,15 +899,15 @@ int main(int argc, char* argv[])
}
if (!me) {
Pmsg0(0, _("Error no Director resource defined.\n"));
exit(1);
exit(BEXIT_FAILURE);
}

SetWorkingDirectory(me->working_directory);

// Print catalog information and exit (-B)
if (print_catalog) {
PrintCatalogDetails(catalog);
exit(0);
exit(BEXIT_SUCCESS);
}

db_name = catalog->db_name;
Expand Down Expand Up @@ -946,5 +947,5 @@ int main(int argc, char* argv[])
CloseMsg(nullptr);
TermMsg();

return 0;
return BEXIT_SUCCESS;
}

0 comments on commit 3432b47

Please sign in to comment.