blib/lib/Narada.pm

filter: Statementstmt 100% 16 / 16 Branchbran 100% 8 / 8 Conditioncond 88.8% 8 / 9 MC/DCmcdc 83.3% 5 / 6 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 93.1% 41 / 44 CC 8 SCAR 18.1
CC
8
Cov
97%
detect
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 6.1
« blib/script/narada-install ↑ Summary blib/script/narada-setup-cron »
1 package Narada;
2  
3 41 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 41 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 41 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 41 our $VERSION = 'v2.3.4';
8  
9  
10 # Possible types of current directory:
11 # - narada-1
12 # config/patch/
13 # config/version
14 # var/backup/
15 # var/patch/
16 # - narada
17 # VERSION (except when migrating from 0.0.0)
18 # .backup/
19 # - narada-1 and narada
20 # config/backup/
21 # config/log/
22 # var/log/
23 sub detect {
24 84 ▶ my %need = map {$_=>1} @_ ? @_ : qw( narada narada-1 );
Subroutine detect: called CC=8 SCAR=20.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 39 45 84
25 84 ▶ my $type
Branch: 2 branches
BranchTrueFalseTotal
-d 'config/backup' && -d '.backup' ? : 63 21 84
-d 'config/backup' && -d 'var/backup' ? : 18 3 21
Condition83%5/6
-d "config/backup" and -d ".backup"
!ll&&!rl&&r
31863
-d "config/backup" and -d "var/backup"
!ll&&!rl&&r
3018
MC/DC100%2/2
-d "config/backup" and -d ".backup"
-d "config/backup" -d ".backup"
MC/DC50%1/2
-d "config/backup" and -d "var/backup"
-d "config/backup" -d "var/backup"
Truth table100%3/3
A and B
A= -d "config/backup"B= -d ".backup"
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= -d "config/backup"B= -d "var/backup"
ABresult
0X0
100
111
26 = -d 'config/backup' && -d '.backup' ? 'narada'
27 : -d 'config/backup' && -d 'var/backup' ? 'narada-1'
28 : undef
29 ;
30 84 ▶ return $type if $type && $need{$type};
Branch: 1 branch
BranchTrueFalseTotal
if $type and $need{$type} 69 15 84
Condition100%3/3
$type and $need{$type}
!ll&&!rl&&r
31269
MC/DC100%2/2
$type and $need{$type}
$type $need{$type}
Truth table100%3/3
A and B
A= $typeB= $need{$type}
ABresult
0X0
100
111
31 15 die 'This is not '.join(' or ', keys %need)." directory\n";
32 }
33  
34  
35 41 1; # Magic true value required at end of module
36 __END__
37  
38 =encoding utf8
39  
40 =head1 NAME
41  
42 Narada - framework for ease deploy and support microservice projects
43  
44  
45 =head1 VERSION
46  
47 This document describes Narada version v2.3.4
48  
49  
50 =head1 SYNOPSIS
51  
52 #--- Create new project
53 ~ $ narada-new my_proj
54 ... New project will be created using template (from git repo).
55  
56 #--- Develop project as usually, until it's ready to run
57 ~ $ cd my_proj
58 ~/my_proj $
59 ... Now you in project's source dir with git repo.
60 ... You can develop this project in any way and language.
61  
62 #--- Make release and deploy it to check how it works
63 ... NOTE: This operation is usually automated by script(s) provided
64 ... by "project template" used while creating new project.
65 ... Create file 0.1.0.migrate with instructions how to migrate between
66 ... empty directory and version 0.1.0 of your project plus any related
67 ... 0.1.0.{patch,tgz,etc.} files if you need them.
68 ... Copy these files into .release/ subdirectory of directory where
69 ... you want to deploy this version of project, for ex. in _live/.
70 ~/my_proj $ cp 0.1.0.* _live/.release/
71 ~/my_proj $ cd _live
72 ~/my_proj/_live $ narada-install 0.1.0
73 ... Now you in project's deploy directory, with config files, logs,
74 ... running services, data files, etc. and you can check how it works.
75  
76 #--- Upgrade or downgrade project
77 ... Repeat same steps to prepare 0.2.0.migrate and save into .release/.
78 ~/my_proj/_live $ narada-install 0.2.0
79 ... You can downgrade if something goes wrong.
80 ~/my_proj/_live $ narada-install 0.1.0
81  
82 #--- You may need to update project's external configuration/data
83 ~/my_proj/_live $ narada-setup-cron
84 ~/my_proj/_live $ narada-setup-mysql
85 ~/my_proj/_live $ narada-setup-qmail
86 ~/my_proj/_live $ narada-start-services
87  
88 #--- You may need to backup this version and restore another one
89 ~/my_proj/_live $ narada-backup
90 ~/my_proj/_live $ cp .backup/full.tar .backup/full-0.2.0.tar
91 ~/my_proj/_live $ narada-restore .backup/full-0.1.0.tar
92  
93 #--- You may need to lock project while manual maintenance
94 ~/my_proj/_live $ narada-lock-exclusive
95 [LOCKED] ~/my_proj/_live $
96 ... Now all project applications will be blocked on next attempt
97 ... to read/write any file or database, so you can safely change
98 ... project files or databases, etc.
99 [LOCKED] ~/my_proj/_live $ exit
100 ~/my_proj/_live $
101 ... Now project applications will be unblocked and continue to work.
102  
103 #--- Manage project
104 ... View/monitor project's log.
105 ~/my_proj/_live $ narada-viewlog
106 ... Get console access to project's database.
107 ~/my_proj/_live $ narada-mysql
108  
109 #--- Stop and uninstall this project.
110 ... Cleanup related external configurations.
111 ~/my_proj/_live $ narada-setup-cron --clean
112 ~/my_proj/_live $ narada-setup-mysql --clean
113 ~/my_proj/_live $ narada-setup-qmail --clean
114 ... Kill all related background processes.
115 ~/my_proj/_live $ narada-shutdown-services
116 ~/my_proj/_live $ narada-bg-killall
117 ... Then just remove it.
118 ~/my_proj/_live $ cd ..
119 ~/my_proj $ rm -rf _live/
120  
121  
122 =head1 DESCRIPTION
123  
124 Narada was designed for ease development, deploy and support for medium/big
125 server-side project or large amount of small projects (used in microservice
126 architecture). It's a framework which define B<the way to manage> your
127 project (which doesn't really depend on your project's nature), and
128 doesn't restrict your project's implementation in any way. With Narada you
129 can create any projects using any programming languages as long as your
130 project conform to Narada interface and work in *NIX.
131  
132 Typical example of project which wins a lot when managed by Narada is web
133 site backend or network service, which consists of several applications
134 (even written in different programming languages) with different entry
135 points (HTTP, RPC, cron, email), which all should have common runtime
136 environment, logs, etc.
137  
138 In short, Narada dictates where your project should keep and how it should
139 work with: config files, logs, locks, temporary and persistent data files,
140 required external configuration for cron, qmail, databases. All of this is
141 called "Narada interface", and if your project conform to it then you can
142 also use a lot of handy command-line tools provided by Narada to deploy,
143 backup and manage your project.
144  
145 There are few helper Narada::* modules for Perl which helps you to conform
146 Narada interface in your Perl modules/scripts; for other languages you may
147 want to create similar helpers, but this isn't required - Narada interface
148 is simple and can be easily conformed without using special helpers (it
149 was designed that way to make it ease to conform to Narada interface even
150 in shell scripts).
151  
152 To use Narada you'll also need to learn format of C<.migrate> files used
153 to describe project's upgrade/downgrade operations (see
154 L<App::migrate/"SYNTAX">) and choose which "project template" to use for
155 your new project (for ex. see default template
156 L<narada-base|https://github.com/powerman/narada-base>; you can modify it
157 with plugins or develop your own template from scratch).
158  
159 =head2 Main features
160  
161 =over
162  
163 =item Templates and plugins for project source.
164  
165 You can choose one of existing templates when starting new project, and
166 even modify some of them using plugins - or made your own templates or
167 plugins if you often develop similar projects. Both templates and plugins
168 are implemented by merging remote repositories, so if they will change
169 after you've started your project you can easily update it by fetching and
170 merging them again.
171  
172 =item You can continue using your favorite workflow.
173  
174 While L<narada-new> tool and existing project templates/plugins use Git,
175 you may opt out and don't use them. This is only Narada tool which do
176 something with your B<project's source directory> (all other tools work
177 only with B<project's deploy directory>) and it's completely optional. You
178 can create new project using Mercurial or even without using any VCS, and
179 use any workflow you like. All you need is produce C<.migrate> and related
180 files as result of releasing every version of your project, including
181 ephemeral development versions which you may release many times per day.
182  
183 =item Provide file/directory structure for deployed project.
184  
185 Some choices are already made for you: where and how to store project
186 configuration, temporary and persistent data files, logs, locks, backups,
187 current version number. This file/directory structure was designed to make
188 it ease to use from any programming language (including shell scripts) and
189 provide several valuable features like reliable upgrades and backups.
190  
191 =item Reliable project upgrade and downgrade.
192  
193 Narada use C<.migrate> files to describe operations needed to upgrade and
194 (required!) downgrade project. While usual development process you'll run
195 these operations each time you wanna check how your changes work, i.e.
196 this will happens dozens (if not hundreds) of times while you're
197 developing next version, so both upgrade and downgrade operations are
198 usually guaranteed to be well-tested before releasing each next version.
199  
200 =item Different project installations have different configurations.
201  
202 Changes in your local configuration won't be occasionally sent with next
203 update to production server. And you won't have any issues because of
204 config files added into your repo with project sources because in Narada
205 projects config files exists only in B<project's deploy directory>.
206  
207 =item Ease project setup after installation/update.
208  
209 Narada provide tools to update project's external setup (cron tasks, qmail
210 handlers for incoming emails, MySQL scheme) according to current project's
211 configuration.
212  
213 =item Reliable services.
214  
215 Run your FastCGI or RPC daemons with guaranteed restart after crash.
216 Narada project may have own services, always running in background.
217 By default we use L<runit|http://smarden.org/runit/> for supervising
218 project's services, but other similar supervisors like daemontools or s6
219 also can be used.
220  
221 =item All project's applications have common log(s).
222  
223 When your project consists of many applications/scripts or run many
224 processes of same application it's important to have single common log for
225 all of them. To implement this each Narada project usually run own log
226 service. By default we use L<socklog|http://smarden.org/socklog/>
227 (syslog-compatible daemon) to receive logs from all project's applications
228 and C<svlogd> tool from L<runit|http://smarden.org/runit/> to manage logs
229 (rotate, filter, group records in separate files, etc.).
230  
231 =item All project's applications have common lock.
232  
233 This guarantee live project's consistency while backup, update or manual
234 maintenance. NOTE: While Narada provide and use this lock file in it's own
235 tools B<it's your responsibility to always get shared lock on that lock
236 file before doing read/write of any project's files or databases> - if you
237 won't do this you'll break mentioned above consistency guarantee.
238  
239 =item Consistent and fast project backup.
240  
241 Narada interface include shared/exclusive project locking, which let us
242 guarantee backup consistency between project files and databases.
243  
244 Narada backup tool support incremental backups both for files and
245 database, which makes it possible to backup most projects in few seconds -
246 your website visitors won't even notice your daily/hourly backup!
247  
248 =item Backward compatibility.
249  
250 Whenever possible, projects created using previous Narada versions will be
251 supported by latest Narada (but newly added tools may not work with such
252 an old projects).
253  
254 =back
255  
256 =head2 Important changes since previous versions
257  
258 =head3 Narada 1.x
259  
260 Narada 1 was created when Git and Mercurial wasn't exists yet, so it
261 doesn't use repository for project sources. Also it doesn't separate
262 project's source vs deploy directories and run project's applications in
263 directory with it sources - this was perfectly fine for projects developed
264 in script languages like Perl without using VCS. The C<narada-new> tool
265 used to create Narada 1 projects is still available but it was renamed to
266 L<narada-new-1>.
267  
268 Also Narada 1 provide several tools used to generate, email/upload and
269 apply patches for project's directory - this was the way to both deploy
270 new version to server and distribute changes to other developers in team.
271 These tools has no use in current Narada, but they still exists for
272 compatibility with Narada 1 projects: L<narada-diff>, L<narada-release>,
273 L<narada-patch-remote>, L<narada-patch-send>, L<narada-patch-pull>,
274 L<narada-patch>.
275  
276 Files&directories structure also was changed since Narada 1.x, see
277 L<Changes|https://metacpan.org/changes/distribution/Narada> in version
278 2.0.0 for more details.
279  
280 This documentation describe current Narada, check documentation for
281 L<latest Narada 1|https://metacpan.org/pod/release/POWERMAN/Narada-v1.4.5/lib/Narada.pm>
282 if you're still using Narada 1 projects.
283  
284  
285 =head1 EXAMPLE
286  
287 Create new project:
288  
289 ~ $ narada-new hello_world
290 ... a lot of Git output skipped
291 ~ $ cd hello_world/
292 ~/hello_world $ ls -AF
293 build* deploy* doc/ .git/ .gitignore migrate release* t/
294  
295 This is B<project's source directory> initialized using default template.
296 It provide basic C<migrate> files with all commands needed to create all
297 files/directories needed by every deployed Narada project plus few
298 scripts: C<./release> for releasing new versions (both development
299 ephemeral versions and tagged final versions) and C<./deploy> for
300 installing them into C<_live/> subdirectory.
301  
302 Cool, we already can release something!
303  
304 ~/hello_world $ ./release
305 t/build/migrate.t .. 1/1 # Checking migrate
306 t/build/migrate.t .. ok
307 All tests successful.
308 Files=1, Tests=1, 0 wallclock secs ( ... )
309 Result: PASS
310 ~/hello_world $ ls -AF
311 build* deploy* doc/ .git/ .gitignore migrate release* .release/
312 t/ VERSION
313 ~/hello_world $ ls -AF .release/
314 0.0.0+b4ff31c.migrate 0.0.0+b4ff31c.patch
315 ~/hello_world $ cat VERSION
316 0.0.0+b4ff31c
317  
318 As you see, your project get unique ephemeral version number in file
319 C<VERSION> and this version was released as two files in C<.release/>.
320 Now, let's deploy it!
321  
322 ~/hello_world $ ./deploy
323 Loading .release/0.0.0+b4ff31c.migrate
324 ... a lot of executed commands output skipped
325 Migration to 0.0.0+b4ff31c completed
326 ~/hello_world $ ls -AF
327 build* deploy* doc/ .git/ .gitignore _live/ migrate release*
328 .release/ t/ VERSION
329 ~/hello_world $ ls -AF _live/
330 .backup/ config/ doc/ .lock .release/ t/ tmp/ var/ VERSION
331  
332 The C<_live/> is B<project's deploy directory>. There are may be many of
333 them, even on same development machine in case you develop in several
334 branches and wanna have each branch deployed to separate directory, or
335 just wanna install simultaneously old and new versions of project and
336 compare how they work.
337  
338 Okay, we get Narada files&directories structure in C<_live/>, but it
339 doesn't have much use for now. Let's add something to our project.
340  
341 ~/hello_world $ cat >hello <<EOF
342 > #!/usr/bin/perl
343 > print "Hello, World!\n";
344 > EOF
345 ~/hello_world $ chmod +x hello
346 ~/hello_world $ git add hello
347 ~/hello_world $ ./release && ./deploy
348 t/build/migrate.t .. 1/1 # Checking migrate
349 t/build/migrate.t .. ok
350 All tests successful.
351 Files=1, Tests=1, 0 wallclock secs ( ... )
352 Result: PASS
353 Loading .release/0.0.0+b4ff31c.dirty-1428492362.migrate
354 Loading .release/0.0.0+b4ff31c.migrate
355 Backuping to .backup/full-0.0.0+b4ff31c.tar
356 ...
357 Migration to 0.0.0 completed
358 ...
359 Migration to 0.0.0+b4ff31c.dirty-1428492362 completed
360  
361 What just happens? New ephemeral version "0.0.0+b4ff31c.dirty-1428492362"
362 was released (it have such a name because we didn't committed our changes
363 to the repo yet); then previous version "0.0.0+b4ff31c" installed in
364 C<_live/> was saved in the backup and downgraded to version "0.0.0" (which
365 is initial version meaning "empty directory"); then that empty directory
366 was upgraded to current version "0.0.0+b4ff31c.dirty-1428492362". Look:
367  
368 ~/hello_world $ cat VERSION
369 0.0.0+b4ff31c.dirty-1428492362
370 ~/hello_world $ ls -AF .release/
371 0.0.0+b4ff31c.dirty-1428492362.migrate 0.0.0+b4ff31c.migrate
372 0.0.0+b4ff31c.dirty-1428492362.patch 0.0.0+b4ff31c.patch
373 ~/hello_world $ ls -AF _live/
374 .backup/ config/ doc/ hello* .lock .release/ t/ tmp/ var/
375 VERSION
376 ~/hello_world $ cd _live/
377 ~/hello_world/_live $ ./hello
378 Hello, World!
379 ~/hello_world/_live $ cd -
380 ~/hello_world $
381  
382 Next, let's start using some Narada features, like config files.
383 We'll also add migration operation to C<migrate> file to create new config
384 file on upgrading to this version and remove it on downgrading from this
385 version.
386  
387 ~/hello_world $ echo 'add_config my_name Powerman' >> migrate
388 ~/hello_world $ cat >hello <<EOF
389 > #!/usr/bin/perl
390 > use Narada::Config qw( get_config_line );
391 > printf "Hello, %s!\n", get_config_line('my_name');
392 > EOF
393 ~/hello_world $ ./release && ./deploy
394 ...
395 Loading .release/0.0.0+b4ff31c.dirty-1428493197.migrate
396 Loading .release/0.0.0+b4ff31c.dirty-1428492362.migrate
397 Backuping to .backup/full-0.0.0+b4ff31c.dirty-1428492362.tar
398 ...
399 Migration to 0.0.0 completed
400 ...
401 Migration to 0.0.0+b4ff31c.dirty-1428493197 completed
402 ~/hello_world $ cd _live/
403 ~/hello_world/_live $ ./hello
404 Hello, Powerman!
405  
406 In deploy directory we can safely modify config or data files - these
407 changes will affect only project deployed in this directory.
408  
409 ~/hello_world/_live $ ls -AF config/
410 backup/ crontab/ log/ my_name mysql/ qmail/
411 ~/hello_world/_live $ echo Anonymous > config/my_name
412 ~/hello_world/_live $ ./hello
413 Hello, Anonymous!
414 ~/hello_world/_live $ cd -
415 ~/hello_world $
416  
417 Now, let's release current version tagged with own version number.
418  
419 ~/hello_world $ git add migrate
420 ~/hello_world $ git commit -m 'add hello'
421 ~/hello_world $ ./release --minor
422 t/build/migrate.t .. 1/1 # Checking migrate
423 t/build/migrate.t .. ok
424 All tests successful.
425 Files=1, Tests=1, 0 wallclock secs ( ... )
426 Result: PASS
427 [master 8338faa] Release 0.1.0
428 1 file changed, 4 insertions(+)
429 ~/hello_world $ cat VERSION
430 0.1.0
431 ~/hello_world $ ls -AF .release/
432 0.0.0+b4ff31c.dirty-1428492362.migrate 0.0.0+b4ff31c.migrate
433 0.0.0+b4ff31c.dirty-1428492362.patch 0.0.0+b4ff31c.patch
434 0.0.0+b4ff31c.dirty-1428493197.migrate 0.1.0.migrate
435 0.0.0+b4ff31c.dirty-1428493197.patch 0.1.0.patch
436 ~/hello_world $
437  
438 And deploy it on server:
439  
440 ~/hello_world $ ssh localhost 'mkdir -p hello_project/.release'
441 ~/hello_world $ scp .release/0.1.0.* localhost:hello_project/.release/
442 0.1.0.migrate 100% 7105 6.9KB/s 6.9KB/s 00:00
443 0.1.0.patch 100% 5223 5.1KB/s 6.9KB/s 00:00
444 ~/hello_world $ ssh localhost
445 ~ $ cd hello_project/
446 ~/hello_project $ ls -AF
447 .release/
448 ~/hello_project $ ls -AF .release/
449 0.1.0.migrate 0.1.0.patch
450 ~/hello_project $ narada-install 0.1.0
451 Loading .release/0.1.0.migrate
452 ...
453 Migration to 0.1.0 completed
454 ~/hello_project $ ls -AF
455 .backup/ config/ doc/ hello* .lock .release/ t/ tmp/ var/
456 VERSION
457 ~/hello_project $ ./hello
458 Hello, Powerman!
459 ~/hello_project $
460  
461 Finally, let's cleanup and uninstall all projects.
462  
463 Template used to create this project include some basic cron configuration
464 to make daily project backups. And these settings was already added to
465 your user's crontab while installing the project. So, before removing
466 project directories we should remove this cron setup.
467  
468 ~/hello_project $ narada-setup-cron --clean
469 ~/hello_project $ cd ..
470 ~ $ rm -rf hello_project/
471 ~ $ exit
472 ~/hello_world $ cd _live/
473 ~/hello_world/_live $ narada-setup-cron --clean
474 ~/hello_world/_live $ cd ../..
475 ~ $ rm -rf hello_world/
476  
477  
478 =head1 INTERFACE
479  
480 The "Narada interface" is described here files&directories structure for
481 B<project's deploy directory> and some conventions about how they should
482 be used. Your project must conform to this interface.
483  
484 =over
485  
486 For example, let's review part of Narada interface related to
487 L</"Consistent and fast project backup."> feature.
488  
489 "Consistent" require using shared/exclusive file locking on file
490 C<.lock>. All Narada does is create that file while installing new
491 project and acquire exclusive lock on it while executing L<narada-backup>.
492 But to really have consistent backups B<you> must acquire shared lock on
493 that file when accessing any project files or database in any of your
494 applications! In Perl scripts you can use helper module L<Narada::Lock>, and
495 it's not a big deal to manually use flock(2) in any other language. If you
496 fail to do this, you backups won't be guaranteed to be consistent anymore!
497  
498 "Fast" consists of two parts: files and database. To backup project files
499 fast you should keep large junk files according to Narada's interface -
500 in directories listed in C<config/backup/exclude>, for ex. in C<tmp/>.
501 To backup MySQL database fast you should try hard to store large amount of
502 data in append-only tables with "auto_increment primary key", and add
503 names of these tables to C<config/mysql/dump/incremental>.
504  
505 All of this will let L<narada-backup> to hold exclusive lock (and thus
506 freeze your project while backup) shortest possible time, complete safe
507 part of backup task after releasing the lock, and use incremental backups
508 to save both time and disk space.
509  
510 =back
511  
512 =head2 Directory types
513  
514 There are two types of "root" directories in your project:
515 B<source directory> and B<deploy directory>.
516  
517 The B<project's source directory> isn't part of Narada interface.
518 Only tool which work with it is L<narada-new> (which helps you to create
519 new project), but you're not required to use it, and even if you use it no
520 Narada tools will touch your B<project's source directory> after it will
521 be created.
522  
523 The B<project's deploy directory> is the one where all files&directories
524 defined by Narada interface should exists. Also B<it's the directory where
525 you should run all Narada tools and your project's applications> - this is
526 required to allow them to find all Narada files&directories using paths
527 relative to current directory.
528  
529 It's ok to have many source directories (as repo clones for your team) and
530 to have many deploy directories (as different installations on same or
531 different computers) - for ex. it may be very useful to deploy different
532 versions from different Git branches to different deploy directories on
533 same development machine.
534  
535 =head2 Overview of deploy directory structure
536  
537 Project templates often include typical directories like C<doc/> or C<t/>
538 but they isn't part of Narada interface and thus you're free to rename or
539 remove them if you like.
540  
541 =over
542  
543 =item C<.release/>
544  
545 Contain C<.migrate> and related files used to upgrade and downgrade
546 project while migrating to another version.
547  
548 =item C<.backup/>
549  
550 Contain project backups. You can create and manage them yourself, but they
551 also will be automatically created before migrating to another version and
552 may be automatically used when only way to downgrade project is restore
553 previous version from backup. In general it's safe to remove backups when
554 you like, but absence of some backups may make it impossible to downgrade
555 to some previous version.
556  
557 =item C<VERSION>
558  
559 Contain current project version. Required for upgrade and downgrade, and
560 will be automatically updated after migration or restoring from backup.
561 May be useful for your applications (read-only).
562  
563 =item C<.lock*>
564  
565 Several lock files used mostly internally by Narada tools, except for
566 the C<.lock> file which should be shared-locked by all your applications
567 while they read or write any project's files or databases.
568  
569 =item C<config/>
570  
571 Project's configuration (both defined by Narada interface and custom
572 settings of your project). May differ in different project's deploy
573 directories. While it's possible to modify configuration in all deploy
574 directories while project migration, usually most of config files modified
575 either manually or by your applications in one deploy directory.
576  
577 =item C<service/>
578  
579 Used to setup project's services (daemons) and run them using service
580 supervisor (runit, daemontools, etc.). Most projects usually have just one
581 (log) or a couple (log and fastcgi/http/rpc) services.
582  
583 =item C<tmp/>
584  
585 Used for temporary data files. Contents of this directory won't be
586 included in backups.
587  
588 =item C<var/>
589  
590 Used for persistent data files.
591  
592 =back
593  
594 =head2 Deploy
595  
596 In L</EXAMPLE> above you've seen scripts C<./release>, C<./deploy>, files
597 C<migrate> and C<VERSION>, directories C<.release/> and C<_live/> while
598 working with Narada, but all of them was in B<project's source directory>
599 and isn't part of Narada interface! All of them was provided by used
600 project template, and different templates may implement these tasks in
601 different ways - read documentation for chosen project template. Also
602 you're free to modify these paths and scripts in any way - template
603 provide only starting point, but it's your project's sources and you have
604 freedom to do anything you like.
605  
606 What is actually part of Narada interface is result of running these
607 C<./release && ./deploy> scripts: file C<< .release/<version>.migrate >>
608 and optional related files (usually named C<< .release/<version>.patch >>
609 or C<< .release/<version>.tgz >>) in B<project's deploy directory>.
610 No matter how you develop, build, compile, release and copy/upload new
611 version to deploy directory, the final result should be such file/files.
612  
613 =over
614  
615 =item C<< .release/<version>.migrate >>
616  
617 These files must contain upgrade and downgrade operations between version
618 previous to C<< <version> >> and C<< <version> >>, but usually they also
619 contain operations for all previous versions up to initial version "0.0.0"
620 (meaning "empty directory").
621  
622 It's recommended to use L<semantic versions|http://semver.org/>, but
623 except for predefined initial version "0.0.0" you're free to use for your
624 project any version numbering scheme you like.
625  
626 Files&directories structure conforming to Narada interface must be created
627 using upgrade operations in this file when describing upgrade from version
628 "0.0.0".
629  
630 Narada uses L<App::migrate> to implement project migrations, format of
631 C<.migrate> files is documented in L<App::migrate/"SYNTAX">.
632  
633 =over
634  
635 B<When you need to convert some data in files or database when installing
636 new version you should use> C<.migrate> B<file to run scripts which will
637 do this.>
638  
639 You should not try to do these data migrations automatically on first time
640 new version of your project's application starts - both because this will
641 make impossible to downgrade quickly and without losing data (if you'll
642 provide script which does backward data conversion, of course) and you'll
643 have to restore from backup instead, and because project migration may
644 include many upgrades at once and your application as it was at one of
645 intermediate versions wasn't get a chance to run at all.
646  
647 =back
648  
649 =back
650  
651 =head2 Backup
652  
653 =over
654  
655 =item C<config/backup/exclude>
656  
657 Shell patterns (one per line) for files/dirs which shouldn't be included
658 in backup. Must contain at least these lines:
659  
660 ./.backup/* to avoid recursively including old backups in new
661 ./.lock* to avoid unlocking while restoring from backup
662 ./tmp/* to conform to Narada interface and not include
663 temporary files in backups
664  
665 =item C<config/mysql/dump/incremental>
666  
667 List of database tables (one per line) which can be dumped incrementally
668 (according to their "auto_increment primary key" field). C<narada-backup>
669 will dump only new records in these tables (dumps for older records will
670 be available in existing files in C<.backup/> or C<var/mysql/>).
671  
672 =item C<config/mysql/dump/empty>
673  
674 List of database tables (one per line) which records shouldn't be included in
675 backup, only scheme.
676  
677 =item C<config/mysql/dump/ignore>
678  
679 List of database tables (one per line) which shouldn't be included in
680 backup at all (even scheme).
681  
682 =item C<var/mysql/>
683  
684 Contain files with last database dump (usually made while last backup).
685  
686 =item C<var/use/>
687  
688 Keeps current used/unused state recorded by last run of C<narada-setup-*>
689 and C<narada-*-services> tools. It will be used by L<narada-restore> to
690 setup project after full restore.
691  
692 =item C<.backup/full.tar>
693  
694 =item C<.backup/incr.tar>
695  
696 Latest full and incremental backups. To force full backup next time just
697 remove C<.backup/full.tar>. See L<narada-backup> for more details.
698  
699 =back
700  
701 =head2 Logging
702  
703 =over
704  
705 =item C<config/log/type>
706  
707 Define type of logging: C<syslog> (default if this file not exists) or
708 C<file>. If set to C<syslog> then C<config/log/output> should contain path
709 to syslog's UNIX socket (like C<var/log.sock> or C</dev/log>).
710  
711 It's recommended to use C<syslog> type and run syslog-compatible log
712 service for each project, because it's very hard to correctly implement
713 concurrent writes to common log file.
714  
715 If set to C<file> then each application in your project must open this
716 file in append-only mode, avoid writing single log record using more than
717 one write syscall (may happens because of buffered I/O), don't use NFS for
718 C<var/log/>… and you anyway may have some issues. One possible issue is
719 performance: if you'll conform to Narada interface and acquire shared lock
720 on C<.lock> before writing each one line to log this may result in
721 noticeable slowdown. Another possible issue happens if you avoid locking
722 because of performance issue, but without locks it may be impossible to
723 ensure log consistency in backups or reliably implement log rotation.
724  
725 =item C<config/log/output>
726  
727 File name where project applications should write their logs: either UNIX
728 socket (to syslog-compatible daemon) or usual file (or C</dev/stdout>).
729  
730 =item C<config/log/level>
731  
732 Current log level, should be one of these strings:
733  
734 ERR WARN NOTICE INFO DEBUG DUMP
735  
736 =item C<var/log/>
737  
738 This directory contains project log files.
739  
740 =back
741  
742 =head2 Cron tasks
743  
744 =over
745  
746 =item C<config/crontab/*>
747  
748 Settings for project's cron tasks, in crontab format.
749  
750 When these settings will be installed to system's cron, each command will
751 be automatically prefixed by:
752  
753 cd /path/to/project/deploy/dir || exit;
754  
755 C<narada-setup-cron> update system's cron using settings from these files.
756  
757 =back
758  
759 =head2 Processing incoming emails
760  
761 Only qmail supported at this time.
762  
763 =over
764  
765 =item C<config/qmail/*>
766  
767 Files with qmail configuration (in .qmail format).
768 Commands listed in these files (lines beginning with C<|>) will be
769 executed in B<project's deploy directory> instead of user's home directory
770 (qmail's default behaviour).
771  
772 =item C<var/qmail/*>
773  
774 Internally used by C<narada-setup-qmail>.
775  
776 =back
777  
778 =head2 Database
779  
780 Only MySQL supported at this time.
781  
782 =over
783  
784 =item C<config/mysql/db>
785  
786 Contains one line - name of MySQL database. If this file doesn't exists or
787 empty - Narada won't use database.
788  
789 =item C<config/mysql/login>
790  
791 =item C<config/mysql/pass>
792  
793 Login/pass for database.
794  
795 =item C<config/mysql/host>
796  
797 Host name of database server. if this file doesn't exists or empty then
798 usual UNIX socket will be used to connect to MySQL server.
799  
800 =item C<config/mysql/port>
801  
802 TCP port of database server.
803  
804 =back
805  
806 =head2 Locking
807  
808 =over
809  
810 =item C<.lock>
811  
812 This file should be shared-locked using flock(2) or L<Narada::Lock> or
813 L<narada-lock> before accessing any project's files or database by usual
814 applications, and exclusive-locked while project's backup, update or
815 manual maintenance.
816  
817 =item C<.lock.new>
818  
819 This file will be created before trying to acquire exclusive lock on
820 C<.lock>. All applications wanted to acquire shared lock on C<.lock> must
821 check before that is C<.lock.new> exists and if yes then delay/avoid
822 locking C<.lock>. This is needed to guarantee exclusive lock will be
823 acquired as soon as possible.
824  
825 After exclusive lock will be acquired and critical operations requiring it
826 will be completed - C<.lock.new> will be removed.
827  
828 If server will be rebooted while waiting for exclusive lock or in the
829 middle of critical operations requiring it then file C<.lock.new>
830 won't be removed and project applications won't continue to work after
831 server reboot until this file will be removed manually or another
832 operation requiring exclusive lock will be started and successfully
833 finished.
834  
835 =item C<.lock.bg>
836  
837 Each project's background process (running as service, or started by cron,
838 qmail, etc.) should acquire shared lock on this file. This can be easily
839 done using L<narada-bg> tool. This will make possible to reliably detect
840 and kill all project's background processes while upgrade or downgrade
841 using L<narada-bg-killall> tool.
842  
843 =back
844  
845 =head2 Services
846  
847 There are several ways to start project's services: manually by running
848 L<narada-start-services> - this way they wasn't start automatically after
849 server reboot, try to start them every 1 minute from cron if they wasn't
850 running yet (usually using C<config/crontab/service> but this file isn't
851 part of Narada interface) - this way it may took about 1 minute before
852 project services will be started after deploy or server reboot, run them
853 as one of system-wide service based on similar (runit/daemontools/s6/etc.)
854 supervisor - fastest and most reliable way but require root permissions to
855 add new system-wide service.
856  
857 =over
858  
859 =item C<config/service/type>
860  
861 Type of used service supervisor. For now only supported type is C<runit>.
862  
863 =item C<.lock.service>
864  
865 This lock file is used by L<narada-start-services> to check is services
866 already running.
867  
868 =back
869  
870  
871 =head1 TOOLS
872  
873 All tools (except L<narada-new>) must be executed in
874 B<project's deploy directory>. Read man pages of these tools for details.
875  
876 =head2 Create new project
877  
878 =over
879  
880 =item L<narada-new>
881  
882 =back
883  
884 =head2 Deploy & uninstall
885  
886 =over
887  
888 =item L<narada-install>
889  
890 =item L<narada-setup-cron>
891  
892 =item L<narada-setup-mysql>
893  
894 =item L<narada-setup-qmail>
895  
896 =item L<narada-shutdown-services>
897  
898 =item L<narada-start-services>
899  
900 =back
901  
902 =head2 Backup & restore
903  
904 =over
905  
906 =item L<narada-backup>
907  
908 =item L<narada-mysqldump>
909  
910 =item L<narada-restore>
911  
912 =back
913  
914 =head2 Background processes
915  
916 =over
917  
918 =item L<narada-bg>
919  
920 =item L<narada-bg-killall>
921  
922 =item L<narada-lock>
923  
924 =item L<narada-lock-exclusive>
925  
926 =back
927  
928 =head2 Misc tools
929  
930 =over
931  
932 =item L<narada-viewlog>
933  
934 =item L<narada-mysql>
935  
936 =item L<narada-emu>
937  
938 =back
939  
940 =head2 SSH tools
941  
942 These tools make it easier to copy files between local and remote
943 project's deploy directories. If you're doing things in right way - you
944 won't need these tools.
945  
946 =over
947  
948 =item L<narada-remote>
949  
950 =item L<narada-upload>
951  
952 =item L<narada-download>
953  
954 =back
955  
956 =head2 Perl modules
957  
958 =over
959  
960 =item L<Narada::Config>
961  
962 =item L<Narada::Lock>
963  
964 =item L<Narada::Log>
965  
966 =back
967  
968  
969 =head1 SUPPORT
970  
971 =head2 Bugs / Feature Requests
972  
973 Please report any bugs or feature requests through the issue tracker
974 at L<https://github.com/powerman/Narada/issues>.
975 You will be notified automatically of any progress on your issue.
976  
977 =head2 Source Code
978  
979 This is open source software. The code repository is available for
980 public review and contribution under the terms of the license.
981 Feel free to fork the repository and submit pull requests.
982  
983 L<https://github.com/powerman/Narada>
984  
985 git clone https://github.com/powerman/Narada.git
986  
987 =head2 Resources
988  
989 =over
990  
991 =item * MetaCPAN Search
992  
993 L<https://metacpan.org/search?q=Narada>
994  
995 =item * CPAN Ratings
996  
997 L<http://cpanratings.perl.org/dist/Narada>
998  
999 =item * AnnoCPAN: Annotated CPAN documentation
1000  
1001 L<http://annocpan.org/dist/Narada>
1002  
1003 =item * CPAN Testers Matrix
1004  
1005 L<http://matrix.cpantesters.org/?dist=Narada>
1006  
1007 =item * CPANTS: A CPAN Testing Service (Kwalitee)
1008  
1009 L<http://cpants.cpanauthors.org/dist/Narada>
1010  
1011 =back
1012  
1013  
1014 =head1 AUTHOR
1015  
1016 Alex Efros E<lt>powerman@cpan.orgE<gt>
1017  
1018  
1019 =head1 CONTRIBUTORS
1020  
1021 Nikita Savin E<lt>asdfgroup@gmail.comE<gt>
1022  
1023 Nick Levchenko E<lt>project129@yandex.ruE<gt>
1024  
1025  
1026 =head1 COPYRIGHT AND LICENSE
1027  
1028 This software is Copyright (c) 2008-2016 by Alex Efros E<lt>powerman@cpan.orgE<gt>.
1029  
1030 This is free software, licensed under:
1031  
1032 The MIT (X11) License
1033  
1034  
1035 =cut
« blib/script/narada-install ↑ Summary blib/script/narada-setup-cron »