Commit | Line | Data |
---|---|---|
7e738616 S |
1 | # trap "SIGHUP" do |
2 | # STDERR.puts "Trapped SIGHUP" | |
3 | # STDERR.flush | |
4 | # exit | |
5 | # end | |
6 | # | |
7 | # trap "SIGINT" do | |
8 | # STDERR.puts "Trapped SIGINT" | |
9 | # STDERR.flush | |
10 | # exit | |
11 | # end | |
12 | # | |
13 | # trap "SIGTERM" do | |
14 | # STDERR.puts "Trapped SIGTERM" | |
15 | # STDERR.flush | |
16 | # exit | |
17 | # end | |
18 | ||
19 | STDERR.puts "Started #{Process.pid}" | |
20 | STDERR.puts `ps aux` | |
21 | ||
22 | while true | |
23 | gets | |
24 | STDERR.puts "HERE" | |
25 | sleep 1 | |
26 | end | |
27 | ||
28 | STDERR.puts "HERE" | |
29 | ||
30 | exit | |
31 | ||
32 | require 'yaml' | |
33 | require 'open3' | |
34 | require 'readline' | |
35 | ||
36 | @host = ARGV[0] | |
37 | ||
38 | STDERR.puts "Started bootloader for #{@host} at: #{Time.now}" | |
39 | ||
40 | module Discourse; end | |
41 | ||
42 | class Discourse::Config | |
43 | def initialize(config, discourse_root=nil) | |
44 | @config = YAML.load_file(config) | |
45 | @discourse_root = discourse_root || "/var/www/discourse" | |
46 | end | |
47 | ||
48 | def startup | |
49 | load_env | |
50 | ensure_git_version | |
51 | ensure_database_config | |
52 | start_roles | |
53 | end | |
54 | ||
55 | def load_env | |
56 | @config["env"].each do |k,v| | |
57 | ENV[k.to_s] = v.to_s | |
58 | end if @config["env"] | |
59 | end | |
60 | ||
61 | def ensure_database_config | |
62 | current = YAML.load_file("#{@discourse_root}/config/database.yml.production-sample") | |
63 | current = current.merge(@config["databases"]) | |
64 | File.open("#{@discourse_root}/config/database.yml", "w"){|f| f.write current.to_yaml } | |
65 | end | |
66 | ||
67 | def ensure_git_version | |
68 | STDERR.puts `cd #{@discourse_root} && git pull` | |
69 | end | |
70 | ||
71 | def start_roles | |
72 | @config["roles"].each do |role| | |
73 | case role | |
74 | when "unicorn" | |
75 | start_unicorn | |
76 | end | |
77 | end | |
78 | end | |
79 | ||
80 | def start_unicorn | |
81 | STDERR.puts `cd #{@discourse_root} && RAILS_ENV=production bundle exec rake db:migrate` | |
82 | end | |
83 | ||
84 | end | |
85 | ||
86 | class Discourse::Process | |
87 | def self.pids | |
88 | @@pids ||= [] | |
89 | end | |
90 | ||
91 | def self.spawn(*args) | |
92 | pid = Process.spawn(*args) | |
93 | STDERR.puts "Spawned #{args.inspect} pid: #{pid}" | |
94 | pids << pid | |
95 | ||
96 | Thread.start do | |
97 | Process.wait(pid) | |
98 | pids.delete(pid) | |
99 | end | |
100 | ||
101 | pid | |
102 | end | |
103 | ||
104 | def spawn(*args) | |
105 | self.class.spawn(*args) | |
106 | end | |
107 | ||
108 | # trap "HUP" do | |
109 | # STDERR.puts "Trapped SIGHUP" | |
110 | # end | |
111 | ||
112 | # trap "INT" do | |
113 | # STDERR.puts "Trapped SIGINT" | |
114 | # end | |
115 | ||
116 | # trap "TERM" do | |
117 | # STDERR.puts "Trapped SIGTERM" | |
118 | # pids.dup.each do |pid| | |
119 | # STDERR.puts "Sending TERM to #{pid}" | |
120 | # # no such process | |
121 | # Process.kill("TERM", pid) rescue nil | |
122 | # end | |
123 | ||
124 | # pids.dup.each do |pid| | |
125 | # # no such process | |
126 | # Process.wait(pid) rescue nil | |
127 | # end | |
128 | ||
129 | # STDERR.puts "Exiting" | |
130 | # exit 1 | |
131 | # end | |
132 | end | |
133 | ||
134 | class Discourse::Postgres | |
135 | attr_accessor :data_dir | |
136 | def start | |
137 | end | |
138 | end | |
139 | ||
140 | class Discourse::Sshd < Discourse::Process | |
141 | def start | |
142 | # we need this dir to run sshd | |
143 | `mkdir /var/run/sshd` unless File.directory? "/var/run/sshd" | |
144 | spawn("/usr/sbin/sshd") | |
145 | end | |
146 | end | |
147 | ||
148 | # tmp = "/home/sam/Source/discourse_docker/shared/config/web1/conf.yml" | |
149 | tmp = "/shared/config/web1/conf.yml" | |
150 | conf = Discourse::Config.new(tmp) | |
151 | #conf.startup | |
152 | ||
153 | ||
154 | #Discourse::Sshd.new.start | |
155 |