kanamei-keystone 0.0.26 → 0.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'keystone'
3
+ require 'pit'
4
+
5
+ ENV["EDITOR"] = "vi" unless ENV.key?("EDITOR")
6
+
7
+ config = Pit.get("keystone_test", :require => {
8
+ "smtp_addr" => "smtp_server_address",
9
+ "mailto" => "mailto",
10
+ "mailfrom" => "mailfrom"
11
+ })
12
+
13
+ @os = Keystone::Os.get()
14
+
15
+ Keystone::Mail::Send.send(
16
+ config["mailfrom"],
17
+ config["mailto"].split(","),
18
+ "件名でおま",
19
+ "本文で小間\nfrom #{@os.hostname}(#{@os.ip_address.join(" , ")})",
20
+ {:smtp_addr=>config["smtp_addr"],:retry_cnt=>3})
21
+
data/lib/keystone.rb CHANGED
@@ -11,7 +11,7 @@ autoload :Moji , 'moji'
11
11
 
12
12
  module Keystone
13
13
 
14
- VERSION = '0.0.26'
14
+ VERSION = '0.0.27'
15
15
 
16
16
  autoload :StringUtil , 'keystone/string_util'
17
17
  autoload :Batch , 'keystone/batch'
@@ -1,4 +1,3 @@
1
-
2
1
  require 'ipaddr'
3
2
 
4
3
  class IPAddr
@@ -27,4 +27,8 @@ class Object
27
27
  yield(self)
28
28
  self
29
29
  end
30
- end
30
+
31
+ def tapp
32
+ self.tap{|obj| p obj}
33
+ end
34
+ end
@@ -15,6 +15,7 @@ module Keystone
15
15
 
16
16
  def to_src
17
17
  header = ""
18
+ header += "Date: #{time2str(Time.now)}\n"
18
19
  header += create_mailfrom_header
19
20
  header += create_mailto_header
20
21
  header += create_subject_header
@@ -33,6 +34,23 @@ module Keystone
33
34
 
34
35
  private
35
36
 
37
+ # from tmail
38
+ WDAY = %w( Sun Mon Tue Wed Thu Fri Sat KeystoneBUG )
39
+ MONTH = %w( TMailBUG Jan Feb Mar Apr May Jun
40
+ Jul Aug Sep Oct Nov Dec KeystoneBUG )
41
+ def time2str( tm )
42
+ # [ruby-list:7928]
43
+ gmt = Time.at(tm.to_i)
44
+ gmt.gmtime
45
+ offset = tm.to_i - Time.local(*gmt.to_a[0,6].reverse).to_i
46
+
47
+ # DO NOT USE strftime: setlocale() breaks it
48
+ return sprintf('%s, %s %s %d %02d:%02d:%02d %+.2d%.2d',
49
+ WDAY[tm.wday], tm.mday, MONTH[tm.month],
50
+ tm.year, tm.hour, tm.min, tm.sec,
51
+ *(offset / 60).divmod(60))
52
+ end
53
+
36
54
  def create_mailfrom_header
37
55
  if @mail_from_text.blank?
38
56
  return "From: #{@mail_from}\n"
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'keystone'
5
+
6
+ include Keystone::Batch::Base
7
+
8
+ ####################################################################
9
+ VEIDS = ["170161"]
10
+ PRIVATE_DIR = "/vz/private"
11
+ BACKUP_DIR = "/cluster/dsk0/backup/vz"
12
+ # replace string __VEID__
13
+ EXCLUDES = ["/vz/private/__VEID__/usr/local/rails/tubebox/shared/movie"]
14
+ # replace string __VEID__
15
+ TAR_FILE_NAME = "__VEID__-#{Time.now.strftime("%Y%m%d")}.tar.gz"
16
+ ####################################################################
17
+
18
+ execute do
19
+ raise "PRIVATE_DIR not set" if PRIVATE_DIR.blank?
20
+ raise "BACKUP_DIR not set" if BACKUP_DIR.blank?
21
+
22
+ VEIDS.each do |veid|
23
+ vedir = "#{PRIVATE_DIR}/#{veid}"
24
+ backupdir = "#{BACKUP_DIR}/#{veid}/"
25
+ backupfile = "#{BACKUP_DIR}/#{veid}/#{TAR_FILE_NAME}".gsub(/__VEID__/,veid)
26
+ FileUtils.mkdir_p(backupdir)
27
+ (error "#{backupdir} not found";next) unless File.directory?(backupdir)
28
+ (error "veid #{veid} not found";next) unless File.exists?("#{PRIVATE_DIR}/#{veid}")
29
+ #(error "veid #{veid} still running";next) if ` /usr/sbin/vzlist #{veid}|/bin/grep running -c`.strip != "1"
30
+
31
+ exclude = ""
32
+ EXCLUDES.each{|exc| exclude += " --exclude=#{exc.gsub(/__VEID__/,veid)} "}
33
+
34
+ cmds = ["/usr/sbin/vzctl stop #{veid}",
35
+ "/bin/tar #{exclude} -cvzf #{backupfile} #{vedir} /etc/vz/conf/#{veid}.conf",
36
+ "/usr/sbin/vzctl start #{veid}"]
37
+
38
+ cmds.each do |cmd|
39
+ puts cmd
40
+ `#{cmd}` unless $DEBUG
41
+ end
42
+ end
43
+ end
44
+
45
+ __END__
46
+
47
+ original
48
+
49
+ VEID=$1
50
+ VEPRIVATEDIR=$2
51
+ TARFILENAME=$3
52
+
53
+ if [ "${VEID}" = "" ]; then
54
+ echo "usage: $0 <VEID> <VEPRIVATEDIR> <TAR FILE NAME>"
55
+ exit
56
+ fi
57
+ if [ "${VEPRIVATEDIR}" = "" ]; then
58
+ echo "usage: $0 <VEID> <VEPRIVATEDIR> <TAR FILE NAME>"
59
+ exit
60
+ fi
61
+ if [ "${TARFILENAME}" = "" ]; then
62
+ echo "usage: $0 <VEID> <VEPRIVATEDIR> <TAR FILE NAME>"
63
+ exit
64
+ fi
65
+
66
+ if [ ! -d ${VEPRIVATEDIR}/${VEID} ]; then
67
+ echo "error: VEID is not exist"
68
+ exit
69
+ fi
70
+
71
+ if [ ` /usr/sbin/vzlist ${VEID}|/bin/grep running -c` -gt 0 ]; then
72
+ echo "you must stop ve "
73
+ echo `/usr/sbin/vzlist ${VEID}|/bin/grep running`
74
+ exit
75
+ fi
76
+
77
+ #/bin/tar --ignore-failed-read --exclude=./mnt --exclude=./u01/mydata --exclude=./u01/mytmp --exclude=./u01/myarclog --exclude=./u01/mybackup --exclude=./u02/mydata --exclude=./u02/mytmp --exclude=./u02/myarclog --exclude=./u02/mybackup --exclude=./d01 --exclude=./var/spool/upgrade --exclude=./proc --exclude=./lost+found --exclude=./sys --exclude=./usr/local/vlmail/logs/history -cvzf ${TARFILENAME} /cluster/dsk0/vz/private/${VEID} /etc/vz/conf/${VEID}.conf
78
+ /bin/tar -cvzf ${TARFILENAME} ${VEPRIVATEDIR}/${VEID} /etc/vz/conf/${VEID}.conf
79
+
80
+ exit
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kanamei-keystone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.26
4
+ version: 0.0.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - kanamei
@@ -26,9 +26,11 @@ files:
26
26
  - util/bin/command_broadcast.rb
27
27
  - util/bin/disk_size_check.rb
28
28
  - util/bin/notice
29
+ - util/bin/ve2tar.rb
29
30
  - util/README
30
31
  - example/batch_sample.rb
31
32
  - example/os.rb
33
+ - example/sendmail.rb
32
34
  - example/string_util.rb
33
35
  - test/test_core_ext.rb
34
36
  - test/test_string_util.rb
@@ -67,6 +69,7 @@ files:
67
69
  - vendor/moji.rb
68
70
  has_rdoc: false
69
71
  homepage: http://github.com/kanamei/keystone/tree/master
72
+ licenses:
70
73
  post_install_message:
71
74
  rdoc_options: []
72
75
 
@@ -90,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
93
  requirements: []
91
94
 
92
95
  rubyforge_project:
93
- rubygems_version: 1.2.0
96
+ rubygems_version: 1.3.5
94
97
  signing_key:
95
98
  specification_version: 2
96
99
  summary: extention's for ruby(and rails?)