forked from lsyncd/lsyncd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.lua
199 lines (183 loc) · 4.62 KB
/
default.lua
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
--============================================================================
-- default.lua Live (Mirror) Syncing Demon
--
-- The default table for the user to access.
-- This default layer 1 functions provide the higher layer functionality.
--
-- License: GPLv2 (see COPYING) or any later version
-- Authors: Axel Kittenberger <[email protected]>
--============================================================================
if default then error('default already loaded'); end
default = {
-----
-- Default action calls user scripts on**** functions.
--
action = function(inlet)
-- in case of moves getEvent returns the origin and dest of the move
local event, event2 = inlet.getEvent()
local config = inlet.getConfig()
local func = config['on'.. event.etype]
if func then
func(event, event2)
end
-- if function didnt change the wait status its not interested
-- in this event -> drop it.
if event.status == 'wait' then
inlet.discardEvent(event)
end
end,
-----
-- Default collector.
--
-- Called when collecting a finished child process
--
collect = function(agent, exitcode)
local config = agent.config
local rc
if config.exitcodes then
rc = config.exitcodes[exitcode]
elseif exitcode == 0 then
rc = 'ok'
else
rc = 'die'
end
-- TODO synchronize with similar code before
if not agent.isList and agent.etype == 'Init' then
if rc == 'ok' then
log('Normal', 'Startup of "',agent.source,'" finished.')
return 'ok'
elseif rc == 'again' then
if settings.insist then
log(
'Normal',
'Retrying startup of "',
agent.source,
'": ',
exitcode
)
return 'again'
else
log(
'Error',
'Temporary or permanent failure on startup of "',
agent.source,
'". Terminating since "insist" is not set.'
)
terminate(-1) -- ERRNO
end
elseif rc == 'die' then
log(
'Error',
'Failure on startup of "',
agent.source,
'".'
)
terminate(-1) -- ERRNO
else
log(
'Error',
'Unknown exitcode "',
exitcode,
'" on startup of "',
agent.source,
'".'
)
return 'die'
end
end
if agent.isList then
if rc == 'ok' then
log('Normal', 'Finished a list = ',exitcode)
elseif rc == 'again' then
log('Normal', 'Retrying a list on exitcode = ',exitcode)
elseif rc == 'die' then
log('Error', 'Failure with a list on exitcode = ',exitcode)
else
log('Error', 'Unknown exitcode "',exitcode,'" with a list')
rc = 'die'
end
else
if rc == 'ok' then
log('Normal', 'Retrying ',agent.etype,' on ',agent.sourcePath,' = ',exitcode)
elseif rc == 'again' then
log('Normal', 'Finished ',agent.etype,' on ',agent.sourcePath,' = ',exitcode)
elseif rc == 'die' then
log('Error', 'Failure with ',agent.etype,' on ',agent.sourcePath,' = ',exitcode)
else
log('Normal', 'Unknown exitcode "',exitcode,'" with ', agent.etype,
' on ',agent.sourcePath,' = ',exitcode)
rc = 'die'
end
end
return rc
end,
-----
-- called on (re)initialization of Lsyncd.
--
init = function(event)
local config = event.config
local inlet = event.inlet
-- user functions
-- calls a startup if given by user script.
if type(config.onStartup) == 'function' then
local startup = config.onStartup(event)
-- TODO honor some return codes of startup like "warmstart".
end
if event.status == 'wait' then
-- user script did not spawn anything
-- thus the blanket event is deleted again.
inlet.discardEvent(event)
end
end,
-----
-- The maximum number of processes Lsyncd will spawn simultanously for
-- one sync.
--
maxProcesses = 1,
-----
-- Try not to have more than these delays.
-- not too large, since total calculation for stacking
-- events is n*log(n) or so..
--
maxDelays = 1000,
-----
-- a default configuration using /bin/cp|rm|mv.
--
direct = default_direct,
------
-- Exitcodes of rsync and what to do.
--
rsyncExitCodes = {
[ 0] = 'ok',
[ 1] = 'die',
[ 2] = 'die',
[ 3] = 'again',
[ 4] = 'die',
[ 5] = 'again',
[ 6] = 'again',
[ 10] = 'again',
[ 11] = 'again',
[ 12] = 'again',
[ 14] = 'again',
[ 20] = 'again',
[ 21] = 'again',
[ 22] = 'again',
[ 23] = 'ok', -- partial transfers are ok, since Lsyncd has registered the event that
[ 24] = 'ok', -- caused the transfer to be partial and will recall rsync.
[ 25] = 'die',
[ 30] = 'again',
[ 35] = 'again',
[255] = 'again',
},
-----
-- Exitcodes of ssh and what to do.
--
sshExitCodes = {
[0] = 'ok',
[255] = 'again',
},
-----
-- Minimum seconds between two writes of a status file.
--
statusInterval = 10,
}