summaryrefslogtreecommitdiff
path: root/bin/bbackupd/bbackupd.cpp
blob: f709114079809a7cc1b65e4a969c36d3c8e50b9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// --------------------------------------------------------------------------
//
// File
//		Name:    bbackupd.cpp
//		Purpose: main file for backup daemon
//		Created: 2003/10/11
//
// --------------------------------------------------------------------------

#include "Box.h"
#include "BackupDaemon.h"
#include "MainHelper.h"
#include "BoxPortsAndFiles.h"
#include "BackupStoreException.h"
#include "Logging.h"

#include "MemLeakFindOn.h"

#ifdef WIN32
	#include "Win32ServiceFunctions.h"
	#include "Win32BackupService.h"

	extern Win32BackupService* gpDaemonService;
#endif

int main(int argc, const char *argv[])
{
	MAINHELPER_START

	Logging::SetProgramName("Box Backup (bbackupd)");
	Logging::ToConsole(true);
	Logging::ToSyslog (true);
	
#ifdef WIN32

	if(argc == 2 &&
		(::strcmp(argv[1], "--help") == 0 ||
		 ::strcmp(argv[1], "-h") == 0))
	{
		printf("-h help, -i install service, -r remove service,\n"
			"-c <config file> start daemon now");
		return 2;
	}
	if(argc == 2 && ::strcmp(argv[1], "-r") == 0)
	{
		return RemoveService();
	}
	if((argc == 2 || argc == 3) && ::strcmp(argv[1], "-i") == 0)
	{
		const char* config = NULL;
		if (argc == 3)
		{
			config = argv[2];
		}
		return InstallService(config);
	}

	bool runAsWin32Service = false;
	if (argc >= 2 && ::strcmp(argv[1], "--service") == 0)
	{
		runAsWin32Service = true;
	}

	gpDaemonService = new Win32BackupService();

	EnableBackupRights();

	int ExitCode = 0;

	if (runAsWin32Service)
	{
		BOX_INFO("Box Backup service starting");

		char* config = NULL;
		if (argc >= 3)
		{
			config = strdup(argv[2]);
		}

		OurService(config);

		if (config)
		{
			free(config);
		}

		BOX_INFO("Box Backup service shut down");
	}
	else
	{
		ExitCode = gpDaemonService->Main(
			BOX_FILE_BBACKUPD_DEFAULT_CONFIG, argc, argv);
	}

	delete gpDaemonService;

	return ExitCode;

#else // !WIN32

	BackupDaemon daemon;
	return daemon.Main(BOX_FILE_BBACKUPD_DEFAULT_CONFIG, argc, argv);

#endif // WIN32

	MAINHELPER_END
}