topkit 0.1.0 → 1.0.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/{LICENSE.txt → LICENSE.md} +1 -1
- data/README.md +10 -24
- data/Rakefile +1 -0
- data/bin/ripen +248 -0
- data/bin/topkit +111 -7
- data/lib/templates/database.yml +9 -0
- data/lib/templates/developer/database.yml +7 -0
- data/lib/templates/developer/topkit.yml +3 -0
- data/lib/templates/nginx.conf +27 -0
- data/lib/templates/topkit.yml +14 -0
- data/lib/templates/unicorn.rb +8 -0
- data/lib/templates/unicorn_init +84 -0
- data/lib/topkit/developer/base.rb +156 -0
- data/lib/topkit/developer/database.rb +17 -0
- data/lib/topkit/developer/installer.rb +46 -0
- data/lib/topkit/developer/site.rb +193 -0
- data/lib/topkit/developer/symlinks.rb +53 -0
- data/lib/topkit/developer/user.rb +53 -0
- data/lib/topkit/server/base.rb +84 -0
- data/lib/topkit/server/console.rb +11 -0
- data/lib/topkit/server/installer.rb +117 -0
- data/lib/topkit/server/symlinks.rb +53 -0
- data/lib/topkit/server/updater.rb +21 -0
- data/lib/topkit/version.rb +1 -1
- data/lib/topkit.rb +23 -2
- data/topkit.gemspec +10 -10
- metadata +50 -46
- data/lib/topkit/actions.rb +0 -41
- data/lib/topkit/app_builder.rb +0 -112
- data/lib/topkit/generators/app_generator.rb +0 -109
- data/templates/Gemfile_clean +0 -41
- data/templates/_footer.html.erb +0 -2
- data/templates/_header.html.erb +0 -2
- data/templates/_status.html.erb +0 -6
- data/templates/application_layout.html.erb +0 -35
- data/templates/database.pg.yml.erb +0 -55
- data/templates/database_cleaner_rspec.rb +0 -21
- data/templates/topkit_gitignore +0 -2
- data/test/lib/topkit/version_test.rb +0 -7
- data/test/test_helper.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54c4caa53d4d49110bde966aca88e606bcab4224
|
4
|
+
data.tar.gz: f4e918dfcf39aa70d76b7524dab2dd551679d98a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b04889d38d64f96c02542d8d27a50ccc6b1806c914d5851fc63dfdfcbdf3c0c4ea2da97f9e9789439bfc89a77d5ee398dce6517f810df19b59a470dd360fd93
|
7
|
+
data.tar.gz: feb43d7ed28dcd81d7ca2a4d15091201901f7dfde66573f2909da3999500287ffa3b3ed8b8fbc3cda5898360895a8c6d5d991611247dbe5f0a1612aefbda2012
|
data/Gemfile
CHANGED
data/{LICENSE.txt → LICENSE.md}
RENAMED
data/README.md
CHANGED
@@ -1,27 +1,13 @@
|
|
1
|
-
|
1
|
+
topkit CLI
|
2
|
+
==========
|
2
3
|
|
3
|
-
|
4
|
+
topkit CLI is the command-line interface for working with [topkit
|
5
|
+
Server](https://github.com/topicdesign/topkit) and [topkit
|
6
|
+
Developer](https://github.com/topicdesign/topkit-developer).
|
4
7
|
|
5
|
-
|
8
|
+
We are in a pre-release phase right now and will have documentation ready
|
9
|
+
before v1.0.
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
## Usage
|
12
|
-
|
13
|
-
Currently no extra command line options, so simply:
|
14
|
-
|
15
|
-
$ topkit APP_NAME
|
16
|
-
|
17
|
-
## Contributing
|
18
|
-
|
19
|
-
1. Fork it
|
20
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
21
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
22
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
23
|
-
5. Create new Pull Request
|
24
|
-
|
25
|
-
## License
|
26
|
-
|
27
|
-
topkit is Copyright © 2008-2013 Topic Design. It is free software, and may be redistributed under the terms specified in the LICENSE file.
|
11
|
+
_Note: The original use of this gem was to bootstrap Ruby on Rails
|
12
|
+
applications. That functionality is no longer the focus of this gem, nor is it
|
13
|
+
supported._
|
data/Rakefile
CHANGED
data/bin/ripen
ADDED
@@ -0,0 +1,248 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# -------------------------------------- Configuration
|
4
|
+
|
5
|
+
# Load the configuration file. All of these values are
|
6
|
+
# brought into this file automatically.
|
7
|
+
#
|
8
|
+
# There is no security around this because we already assume
|
9
|
+
# a root user is running this script.
|
10
|
+
#
|
11
|
+
# Declare all associative arrays (vars in ripen.conf)
|
12
|
+
#
|
13
|
+
declare -A user
|
14
|
+
declare -A git
|
15
|
+
declare -A mysql
|
16
|
+
declare -A swapfile
|
17
|
+
declare -A colors
|
18
|
+
|
19
|
+
# These are the variables usually shown in the config file
|
20
|
+
update_system=true
|
21
|
+
|
22
|
+
reboot=false
|
23
|
+
|
24
|
+
dev_libs=(
|
25
|
+
build-essential
|
26
|
+
zlib1g-dev
|
27
|
+
libssl-dev
|
28
|
+
libreadline-gplv2-dev
|
29
|
+
python-software-properties
|
30
|
+
make
|
31
|
+
libxml2
|
32
|
+
libxml2-dev
|
33
|
+
libxslt1-dev
|
34
|
+
imagemagick
|
35
|
+
libmagickwand-dev
|
36
|
+
libmagic-dev
|
37
|
+
nodejs
|
38
|
+
)
|
39
|
+
|
40
|
+
add_user=true
|
41
|
+
username='topkit'
|
42
|
+
user=(
|
43
|
+
['username']='topkit'
|
44
|
+
['password']='password'
|
45
|
+
['options']='--create-home --user-group --shell /bin/bash'
|
46
|
+
['sudo']=true
|
47
|
+
)
|
48
|
+
|
49
|
+
bash_config_file='bashrc'
|
50
|
+
adjust_bash_config=true
|
51
|
+
bash_config_url='https://raw.githubusercontent.com/seancdavis/ripen/master/dotfiles/bashrc'
|
52
|
+
add_bash_profile=true
|
53
|
+
bash_profile_url='https://raw.githubusercontent.com/seancdavis/ripen/master/dotfiles/profile'
|
54
|
+
|
55
|
+
install_git=true
|
56
|
+
git=(
|
57
|
+
['name']='topkit'
|
58
|
+
['email']='topkit@topicdesign.com'
|
59
|
+
['colors']=true
|
60
|
+
)
|
61
|
+
|
62
|
+
install_nginx=true
|
63
|
+
|
64
|
+
install_mysql=false
|
65
|
+
|
66
|
+
install_postgresql=true
|
67
|
+
|
68
|
+
install_rbenv=true
|
69
|
+
ruby_version='2.1.4'
|
70
|
+
install_bundler=true
|
71
|
+
|
72
|
+
add_swapfile=true
|
73
|
+
swapfile=(
|
74
|
+
['size']='4G'
|
75
|
+
['swappiness']='10'
|
76
|
+
['vfs_cache_pressure']='50'
|
77
|
+
)
|
78
|
+
|
79
|
+
# -------------------------------------- Helpers
|
80
|
+
|
81
|
+
colors=(
|
82
|
+
["black"]="\033[33;30m"
|
83
|
+
["red"]="\033[33;31m"
|
84
|
+
["green"]="\033[33;32m"
|
85
|
+
["yellow"]="\033[33;33m"
|
86
|
+
["blue"]="\033[33;34m"
|
87
|
+
["purple"]="\033[33;35m"
|
88
|
+
["cyan"]="\033[33;36m"
|
89
|
+
["white"]="\033[33;37m"
|
90
|
+
)
|
91
|
+
|
92
|
+
# puts -> echo content with an optional color
|
93
|
+
#
|
94
|
+
puts () {
|
95
|
+
if [ $2 ]; then
|
96
|
+
echo -e "${colors[$2]}$1${colors[white]}"
|
97
|
+
else
|
98
|
+
echo -e $1
|
99
|
+
fi
|
100
|
+
}
|
101
|
+
|
102
|
+
# cmd -> use `puts` to execute and output a command
|
103
|
+
#
|
104
|
+
cmd () {
|
105
|
+
puts "\n[EXEC] $1" "yellow"
|
106
|
+
$1
|
107
|
+
}
|
108
|
+
|
109
|
+
# cmd_as_user -> run cmd as another user
|
110
|
+
#
|
111
|
+
cmd_as_user () {
|
112
|
+
cmd "sudo -H -u $username $1"
|
113
|
+
}
|
114
|
+
|
115
|
+
# append_to_file -> add a line to the end of a file
|
116
|
+
append_to_file () {
|
117
|
+
puts "\n[EXEC] echo '$1' >> $2" "yellow"
|
118
|
+
echo $1 >> $2
|
119
|
+
}
|
120
|
+
|
121
|
+
# -------------------------------------- Update System
|
122
|
+
|
123
|
+
if [ $update_system = true ]; then
|
124
|
+
cmd "apt-get -y update --fix-missing"
|
125
|
+
cmd "apt-get -y upgrade"
|
126
|
+
fi
|
127
|
+
|
128
|
+
# -------------------------------------- Development Libraries
|
129
|
+
|
130
|
+
for i in "${dev_libs[@]}"
|
131
|
+
do
|
132
|
+
cmd "apt-get -y install $i"
|
133
|
+
done
|
134
|
+
|
135
|
+
# -------------------------------------- Add User
|
136
|
+
|
137
|
+
if [ $add_user = true ]; then
|
138
|
+
password="print crypt(${user[password]}, \"aa\")"
|
139
|
+
password=$(perl -e "$password")
|
140
|
+
cmd "useradd --password $password ${user[options]} ${user[username]}"
|
141
|
+
|
142
|
+
# Add to the sudoers file if necessary
|
143
|
+
if [ ${user[sudo]} = true ]; then
|
144
|
+
cmd "cp /etc/sudoers /etc/sudoers.bak"
|
145
|
+
append_to_file "${user[username]} ALL=(ALL:ALL) ALL" /etc/sudoers
|
146
|
+
fi
|
147
|
+
fi
|
148
|
+
|
149
|
+
home="/home/$username"
|
150
|
+
export HOME=$home
|
151
|
+
|
152
|
+
# -------------------------------------- Add Bash Config
|
153
|
+
|
154
|
+
if [ $adjust_bash_config = true ]; then
|
155
|
+
cmd "rm $home/.$bash_config_file"
|
156
|
+
cmd "curl $bash_config_url --output $home/.$bash_config_file"
|
157
|
+
|
158
|
+
if [ $add_bash_profile = true ]; then
|
159
|
+
cmd "rm $home/.profile"
|
160
|
+
cmd "curl $bash_profile_url --output $home/.profile"
|
161
|
+
fi
|
162
|
+
fi
|
163
|
+
|
164
|
+
# -------------------------------------- Install Git
|
165
|
+
|
166
|
+
if [ $install_git = true ]; then
|
167
|
+
cmd "apt-get -y install git-core"
|
168
|
+
# need the double quotes to make it all the way through,
|
169
|
+
# so we have to break this one out
|
170
|
+
puts "\n[EXEC] git config --global user.name \"${git[name]}\"" "yellow"
|
171
|
+
git config --global user.name "${git[name]}"
|
172
|
+
cmd "git config --global user.email ${git[email]}"
|
173
|
+
cmd "git config --global color.ui ${git[colors]}"
|
174
|
+
cmd "mv .gitconfig /home/$username/"
|
175
|
+
fi
|
176
|
+
|
177
|
+
# -------------------------------------- Install Nginx
|
178
|
+
|
179
|
+
if [ $install_nginx = true ]; then
|
180
|
+
cmd "apt-get -y install nginx"
|
181
|
+
fi
|
182
|
+
|
183
|
+
# -------------------------------------- Install MySQL
|
184
|
+
|
185
|
+
if [ $install_mysql = true ]; then
|
186
|
+
cmd "apt-get -y install libmysqlclient-dev"
|
187
|
+
debconf-set-selections <<< "mysql-server mysql-server/root_password password ${mysql[root_password]}"
|
188
|
+
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${mysql[root_password]}"
|
189
|
+
cmd "apt-get -y install mysql-server"
|
190
|
+
fi
|
191
|
+
|
192
|
+
# -------------------------------------- Install PostgreSQL
|
193
|
+
|
194
|
+
if [ $install_postgresql = true ]; then
|
195
|
+
cmd "apt-get -y install postgresql libpq-dev postgresql-contrib"
|
196
|
+
fi
|
197
|
+
|
198
|
+
# -------------------------------------- Install Ruby
|
199
|
+
|
200
|
+
if [ $install_rbenv = true ]; then
|
201
|
+
|
202
|
+
cmd "git clone https://github.com/sstephenson/rbenv.git $home/.rbenv"
|
203
|
+
|
204
|
+
cmd "mv $home/.$bash_config_file $home/.$bash_config_file.tmp"
|
205
|
+
cmd "rm $home/.$bash_config_file"
|
206
|
+
append_to_file 'export PATH="$HOME/.rbenv/bin:$PATH"' "$home/.$bash_config_file"
|
207
|
+
append_to_file 'eval "$(rbenv init -)"' "$home/.$bash_config_file"
|
208
|
+
puts "\n[EXEC] cat $home/.$bash_config_file.tmp >> $home/.$bash_config_file" "yellow"
|
209
|
+
echo "$(cat $home/.$bash_config_file.tmp)" >> $home/.$bash_config_file
|
210
|
+
cmd "rm $home/.$bash_config_file.tmp"
|
211
|
+
|
212
|
+
cmd "source $home/.$bash_config_file"
|
213
|
+
cmd "git clone https://github.com/sstephenson/ruby-build.git $home/.rbenv/plugins/ruby-build"
|
214
|
+
|
215
|
+
cmd "rbenv install $ruby_version"
|
216
|
+
cmd "rbenv global $ruby_version"
|
217
|
+
|
218
|
+
if [ $install_bundler = true ]; then
|
219
|
+
cmd "gem install bundler --no-ri --no-rdoc"
|
220
|
+
cmd "rbenv rehash"
|
221
|
+
fi
|
222
|
+
|
223
|
+
cmd "chown -R $username:$username $home"
|
224
|
+
fi
|
225
|
+
|
226
|
+
# -------------------------------------- Swapfile
|
227
|
+
|
228
|
+
if [ $add_swapfile = true ]; then
|
229
|
+
cmd "fallocate -l ${swapfile[size]} /swapfile"
|
230
|
+
cmd "chmod 600 /swapfile"
|
231
|
+
cmd "mkswap /swapfile"
|
232
|
+
cmd "swapon /swapfile"
|
233
|
+
append_to_file "/swapfile none swap sw 0 0" "/etc/fstab"
|
234
|
+
cmd "sysctl vm.swappiness=${swapfile[swappiness]}"
|
235
|
+
append_to_file "vm.swappiness=${swapfile[swappiness]}" "/etc/sysctl.conf"
|
236
|
+
cmd "sysctl vm.vfs_cache_pressure=${swapfile[vfs_cache_pressure]}"
|
237
|
+
append_to_file "vm.vfs_cache_pressure = ${swapfile[vfs_cache_pressure]}" "/etc/sysctl.conf"
|
238
|
+
fi
|
239
|
+
|
240
|
+
# -------------------------------------- Reboot
|
241
|
+
|
242
|
+
if [ $reboot = true ]; then
|
243
|
+
cmd "reboot"
|
244
|
+
fi
|
245
|
+
|
246
|
+
# -------------------------------------- Change Password For User
|
247
|
+
|
248
|
+
cmd "passwd $username"
|
data/bin/topkit
CHANGED
@@ -1,11 +1,115 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require File.expand_path(File.join('..', 'lib', 'topkit', 'actions'), File.dirname(__FILE__))
|
5
|
-
require File.expand_path(File.join('..', 'lib', 'topkit', 'app_builder'), File.dirname(__FILE__))
|
3
|
+
require 'topkit'
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
action = ARGV[0].nil? ? nil : ARGV[0].downcase
|
6
|
+
object = ARGV[1].nil? ? nil : ARGV[1].downcase
|
7
|
+
env = ARGV[2].nil? ? nil : ARGV[2].downcase
|
10
8
|
|
11
|
-
|
9
|
+
if [nil, ''].include?(action) || [nil, ''].include?(object)
|
10
|
+
puts "Usage: topkit [ACTION] [OBJECT]"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
|
14
|
+
methods = [
|
15
|
+
'add_user',
|
16
|
+
'clean_symlinks',
|
17
|
+
# 'deploy_site',
|
18
|
+
# 'generate_site',
|
19
|
+
'generate_symlinks',
|
20
|
+
'get_site',
|
21
|
+
'get_user',
|
22
|
+
'create_user',
|
23
|
+
# 'import_site',
|
24
|
+
'install_developer',
|
25
|
+
'install_server',
|
26
|
+
'create_site',
|
27
|
+
'rails_console',
|
28
|
+
# 'subl_site',
|
29
|
+
'update_database',
|
30
|
+
'update_server',
|
31
|
+
'update_site'
|
32
|
+
]
|
33
|
+
|
34
|
+
unless methods.include?("#{action}_#{object}")
|
35
|
+
puts 'ERROR: That action/object combination does not exist.'
|
36
|
+
exit
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_user
|
40
|
+
Topkit::Developer::User.new.add
|
41
|
+
end
|
42
|
+
|
43
|
+
def clean_symlinks
|
44
|
+
if env == 'server'
|
45
|
+
Topkit::Server::Symlinks.new.clean
|
46
|
+
else
|
47
|
+
Topkit::Developer::Symlinks.new.clean
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_site
|
52
|
+
Topkit::Developer::Site.new.create
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_user
|
56
|
+
Topkit::Developer::User.new.create
|
57
|
+
end
|
58
|
+
|
59
|
+
# def deploy_site
|
60
|
+
# Topkit::Developer::Site.new.deploy
|
61
|
+
# end
|
62
|
+
|
63
|
+
# def generate_site
|
64
|
+
# Topkit::Developer::Site.new.generate
|
65
|
+
# end
|
66
|
+
|
67
|
+
def generate_symlinks
|
68
|
+
if env == 'server'
|
69
|
+
Topkit::Server::Symlinks.new.generate
|
70
|
+
else
|
71
|
+
Topkit::Developer::Symlinks.new.generate
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_site
|
76
|
+
Topkit::Developer::Site.new.get
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_user
|
80
|
+
Topkit::Developer::User.new.get
|
81
|
+
end
|
82
|
+
|
83
|
+
# def import_site
|
84
|
+
# Topkit::Developer::Site.new.import
|
85
|
+
# end
|
86
|
+
|
87
|
+
def install_developer
|
88
|
+
Topkit::Developer::Installer.new
|
89
|
+
end
|
90
|
+
|
91
|
+
def install_server
|
92
|
+
Topkit::Server::Installer.new
|
93
|
+
end
|
94
|
+
|
95
|
+
def rails_console
|
96
|
+
Topkit::Server::Console.new
|
97
|
+
end
|
98
|
+
|
99
|
+
# def subl_site
|
100
|
+
# Topkit::Developer::Site.new.subl
|
101
|
+
# end
|
102
|
+
|
103
|
+
def update_database
|
104
|
+
Topkit::Developer::Database.new.update
|
105
|
+
end
|
106
|
+
|
107
|
+
def update_server
|
108
|
+
Topkit::Server::Updater.new
|
109
|
+
end
|
110
|
+
|
111
|
+
def update_site
|
112
|
+
Topkit::Developer::Site.new.update
|
113
|
+
end
|
114
|
+
|
115
|
+
send("#{action}_#{object}")
|
@@ -0,0 +1,27 @@
|
|
1
|
+
upstream unicorn_[app_name] {
|
2
|
+
server unix:/tmp/unicorn.[app_name].sock fail_timeout=0;
|
3
|
+
}
|
4
|
+
|
5
|
+
server {
|
6
|
+
listen 80;
|
7
|
+
server_name [server_name];
|
8
|
+
root /home/topkit/[app_name]/public;
|
9
|
+
|
10
|
+
location ^~ /assets/ {
|
11
|
+
gzip_static on;
|
12
|
+
expires max;
|
13
|
+
add_header Cache-Control public;
|
14
|
+
}
|
15
|
+
|
16
|
+
try_files $uri/index.html $uri @unicorn_[app_name];
|
17
|
+
location @unicorn_[app_name] {
|
18
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
19
|
+
proxy_set_header Host $http_host;
|
20
|
+
proxy_redirect off;
|
21
|
+
proxy_pass http://unicorn_[app_name];
|
22
|
+
}
|
23
|
+
|
24
|
+
error_page 500 502 503 504 /500.html;
|
25
|
+
client_max_body_size 4G;
|
26
|
+
keepalive_timeout 10;
|
27
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
production:
|
2
|
+
url: [url]
|
3
|
+
google_analytics_id: [google_analytics_id]
|
4
|
+
mailer:
|
5
|
+
user_name: [mailer_user_name]
|
6
|
+
password: [mailer_password]
|
7
|
+
domain: [mailer_domain]
|
8
|
+
address: [mailer_address]
|
9
|
+
port: [mailer_port]
|
10
|
+
default_from: [mailer_default_from]
|
11
|
+
errors:
|
12
|
+
email_prefix: [errors_subject]
|
13
|
+
sender: [errors_from]
|
14
|
+
recipient: [errors_to]
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
### BEGIN INIT INFO
|
3
|
+
# Provides: unicorn
|
4
|
+
# Required-Start: $remote_fs $syslog
|
5
|
+
# Required-Stop: $remote_fs $syslog
|
6
|
+
# Default-Start: 2 3 4 5
|
7
|
+
# Default-Stop: 0 1 6
|
8
|
+
# Short-Description: Manage unicorn server
|
9
|
+
# Description: Start, stop, restart unicorn server for a specific application.
|
10
|
+
### END INIT INFO
|
11
|
+
set -e
|
12
|
+
|
13
|
+
# Feel free to change any of the following variables for your app:
|
14
|
+
TIMEOUT=${TIMEOUT-60}
|
15
|
+
APP_ROOT=[root]
|
16
|
+
PID=[root]/tmp/pids/unicorn.pid
|
17
|
+
CMD="cd [root]; bundle exec unicorn -D -c [root]/config/unicorn.rb -E production"
|
18
|
+
AS_USER=[user]
|
19
|
+
set -u
|
20
|
+
|
21
|
+
OLD_PIN="$PID.oldbin"
|
22
|
+
|
23
|
+
sig () {
|
24
|
+
test -s "$PID" && kill -$1 `cat $PID`
|
25
|
+
}
|
26
|
+
|
27
|
+
oldsig () {
|
28
|
+
test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
|
29
|
+
}
|
30
|
+
|
31
|
+
run () {
|
32
|
+
if [ "$(id -un)" = "$AS_USER" ]; then
|
33
|
+
eval $1
|
34
|
+
else
|
35
|
+
su -c "$1" - $AS_USER
|
36
|
+
fi
|
37
|
+
}
|
38
|
+
|
39
|
+
case "$1" in
|
40
|
+
start)
|
41
|
+
sig 0 && echo >&2 "Already running" && exit 0
|
42
|
+
run "$CMD"
|
43
|
+
;;
|
44
|
+
stop)
|
45
|
+
sig QUIT && exit 0
|
46
|
+
echo >&2 "Not running"
|
47
|
+
;;
|
48
|
+
force-stop)
|
49
|
+
sig TERM && exit 0
|
50
|
+
echo >&2 "Not running"
|
51
|
+
;;
|
52
|
+
restart|reload)
|
53
|
+
sig HUP && echo reloaded OK && exit 0
|
54
|
+
echo >&2 "Couldn't reload, starting '$CMD' instead"
|
55
|
+
run "$CMD"
|
56
|
+
;;
|
57
|
+
upgrade)
|
58
|
+
if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
|
59
|
+
then
|
60
|
+
n=$TIMEOUT
|
61
|
+
while test -s $OLD_PIN && test $n -ge 0
|
62
|
+
do
|
63
|
+
printf '.' && sleep 1 && n=$(( $n - 1 ))
|
64
|
+
done
|
65
|
+
echo
|
66
|
+
|
67
|
+
if test $n -lt 0 && test -s $OLD_PIN
|
68
|
+
then
|
69
|
+
echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
|
70
|
+
exit 1
|
71
|
+
fi
|
72
|
+
exit 0
|
73
|
+
fi
|
74
|
+
echo >&2 "Couldn't upgrade, starting '$CMD' instead"
|
75
|
+
run "$CMD"
|
76
|
+
;;
|
77
|
+
reopen-logs)
|
78
|
+
sig USR1
|
79
|
+
;;
|
80
|
+
*)
|
81
|
+
echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
|
82
|
+
exit 1
|
83
|
+
;;
|
84
|
+
esac
|