-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rexfile
106 lines (83 loc) · 2.7 KB
/
Rexfile
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
use Rex -feature => ['1.3'];
# this file contains real test/stage/live environments
require("Rexfile.local");
environment example => sub {
set host_name => 'frfbot.example.com';
set daemon_port => 8046;
set account => 'frfbot';
};
my $host_name = get 'host_name';
my $root_dir = "/site/$host_name";
my $account = get 'account';
group bot_servers => $host_name;
use Rex::Lang::Perl::Cpanm;
task "prepare", group => "bot_servers", sub {
my $ssh_key;
LOCAL {
$ssh_key = cat "$ENV{HOME}/.ssh/id_rsa.pub";
};
create_group $account;
account $account,
create_home => 1,
crypt_password => '*',
groups => [$account],
home => "/home/$account",
ssh_key => $ssh_key;
file [map "$root_dir/$_", qw{www conf daemon lib lib/FrfBot lib/FrfBot/Controller log}],
ensure => 'directory',
owner => $account,
group => $account;
pkg [qw/nginx libxml2-dev zlib1g-dev redis-server/],
ensure => 'present';
symlink "$root_dir/conf/nginx-site.conf", "/etc/nginx/sites-enabled/$host_name.conf";
file "$root_dir/daemon/cpanfile",
source => 'cpanfile',
owner => $account,
group => $account;
cpanm -install();
cpanm -installdeps => "$root_dir/daemon";
run 'ubic-admin --batch-mode',
unless 'test -d /etc/ubic/service';
chmod 1777, '/var/lib/ubic';
symlink "$root_dir/conf/ubic-service", "/etc/ubic/service/$account";
};
task "deploy", group => "bot_servers", sub {
file "$root_dir/www/index.html",
content => "Dünya merhaba!";
run "openssl req -newkey rsa:2048 -sha256 -nodes -keyout $root_dir/conf/https_priv.key -x509 -days 365 -out $root_dir/conf/https_public_cert.pem -subj '/C=US/ST=New York/L=Brooklyn/O=Example Brooklyn Company/CN=$host_name'";
chmod 600, "$root_dir/conf/https_priv.key";
file "$root_dir/conf/frfbot.conf",
no_overwrite => TRUE,
content => template("conf/frfbot.conf.tmpl");
file "$root_dir/conf/nginx-site.conf",
content => template("conf/nginx-site.conf.tmpl");
file "$root_dir/conf/ubic-service",
content => template("conf/ubic-service.tmpl");
needs main "code";
};
task "start", group => "bot_servers", sub {
run "ubic restart $account";
service "redis",
ensure => "started";
service "nginx",
ensure => "started";
};
task "code", group => "bot_servers", sub {
file "$root_dir/daemon/frfbot.pl",
source => "script/frfbot.pl";
file "$root_dir/lib/FrfBot.pm",
source => "lib/FrfBot.pm";
file "$root_dir/lib/FrfBot/Dialog.pm",
source => "lib/FrfBot/Dialog.pm";
file "$root_dir/lib/FrfBot/Controller/Telegram.pm",
source => "lib/FrfBot/Controller/Telegram.pm";
do_task "start";
};
auth for => 'prepare',
user => 'root';
auth for => 'start',
user => 'root';
auth for => 'deploy',
user => $account;
auth for => 'code',
user => $account;