pkgr 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +2 -2
  3. data/README.md +20 -9
  4. data/data/build_dependencies/debian.yml +12 -2
  5. data/data/buildpacks/amazon-2014 +2 -2
  6. data/data/buildpacks/amazon-2015 +2 -2
  7. data/data/buildpacks/centos-6 +2 -2
  8. data/data/buildpacks/centos-7 +2 -2
  9. data/data/buildpacks/debian-6 +1 -1
  10. data/data/buildpacks/debian-7 +2 -2
  11. data/data/buildpacks/debian-8 +2 -2
  12. data/data/buildpacks/debian-9 +4 -0
  13. data/data/buildpacks/fedora-20 +2 -2
  14. data/data/buildpacks/sles-11 +2 -2
  15. data/data/buildpacks/sles-12 +2 -2
  16. data/data/buildpacks/ubuntu-10.04 +1 -1
  17. data/data/buildpacks/ubuntu-12.04 +2 -2
  18. data/data/buildpacks/ubuntu-14.04 +2 -2
  19. data/data/buildpacks/ubuntu-16.04 +2 -2
  20. data/data/cli/cli.sh.erb +176 -57
  21. data/data/dependencies/debian.yml +15 -4
  22. data/data/dependencies/sles.yml +1 -1
  23. data/data/hooks/postinstall.sh +2 -1
  24. data/data/hooks/postuninstall.sh +1 -1
  25. data/data/hooks/preinstall.sh +1 -1
  26. data/data/hooks/preuninstall.sh +1 -1
  27. data/data/init/systemd/default/process.service.erb +1 -1
  28. data/data/init/sysv/lsb-3.1/process.erb +3 -4
  29. data/data/init/upstart/1.5/process.conf.erb +1 -1
  30. data/lib/pkgr/builder.rb +31 -22
  31. data/lib/pkgr/buildpack.rb +17 -5
  32. data/lib/pkgr/cli.rb +7 -3
  33. data/lib/pkgr/config.rb +10 -0
  34. data/lib/pkgr/distributions/amazon.rb +38 -1
  35. data/lib/pkgr/distributions/base.rb +9 -9
  36. data/lib/pkgr/distributions/debian.rb +1 -1
  37. data/lib/pkgr/distributions/redhat.rb +0 -2
  38. data/lib/pkgr/env.rb +10 -4
  39. data/lib/pkgr/env_value.rb +55 -0
  40. data/lib/pkgr/version.rb +1 -1
  41. metadata +10 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6953d1856b4cb7378d7465a3cfb0bc8f7e21ce7
4
- data.tar.gz: 4416c2783fe73bc50d797d99e64e178e183dc04e
3
+ metadata.gz: 88515b775ce0780722e7b2cf547a055eb389d2b1
4
+ data.tar.gz: 90ea8f15d716c46d2a2ae12a0cfaa77b1ecd5d9c
5
5
  SHA512:
6
- metadata.gz: 4ebeee46be1c87ce49ef306362a2f2da56007a121c2eaef55300837421a145241c51468652d8353329cdd8789777565d375fcea015012972ccf802e6dac6c33b
7
- data.tar.gz: dafa9e7fc52334d49b2b536b5b0fbd253cd7ab0a5b5be6d41c190b2139ec7c05d994c1ba5a42b113e3299ef3cfebdf615d0696a049a981715c1825a7aeff268a
6
+ metadata.gz: 8574750422452b0efe2a75d4be2703ccac4a8c33c8936c0b781928d25092a1dced9e07f6eb7fc8e92765292043fa30dbb5a59ea3e60658c67573c9b64ac5be0d
7
+ data.tar.gz: 1d730a9380f3c66a79f4e596e623028fd0e7637bb559da47b22d35b81f9fea2a184c2cb98878198b6b07e32cfcfafbc91afb5fccc45950844a2ceb215a2ed89e
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Cyril Rohr
1
+ Copyright (c) 2012-2017 Cyril Rohr
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,12 +1,16 @@
1
1
  # pkgr
2
2
 
3
+ [![Build Status](https://travis-ci.org/crohr/pkgr.svg?branch=master)](https://travis-ci.org/crohr/pkgr)
4
+
3
5
  ## Goal
4
6
 
5
7
  Make debian or rpm packages out of any app, including init script, crons,
6
8
  logrotate, etc. Excellent way to distribute apps or command line tools without
7
9
  complicated installation instructions.
8
10
 
9
- Hosted service available at <https://packager.io/>. Free for OpenSource apps.
11
+ Hosted service available at [Packager.io][packager-io]. Free for OpenSource apps.
12
+
13
+ [packager-io]: https://packager.io/
10
14
 
11
15
  ## Officially supported languages
12
16
 
@@ -15,8 +19,9 @@ Hosted service available at <https://packager.io/>. Free for OpenSource apps.
15
19
  * Python
16
20
  * Go
17
21
 
18
- You can also try out PHP support by specifying the following buildpack:
19
- `https://github.com/pkgr/heroku-buildpack-php#buildcurl`
22
+ In beta:
23
+
24
+ * PHP, using the following buildpack: `https://github.com/pkgr/heroku-buildpack-php#buildcurl`
20
25
 
21
26
  You can also point to other buildpacks
22
27
  ([doc](https://packager.io/documentation/customizing-the-build/#buildpack)).
@@ -27,6 +32,7 @@ They may just work.
27
32
  * Ubuntu 16.04 ("xenial")
28
33
  * Ubuntu 14.04 ("trusty")
29
34
  * Ubuntu 12.04 ("precise")
35
+ * Debian 9 ("stretch")
30
36
  * Debian 8 ("jessie")
31
37
  * Debian 7 ("wheezy")
32
38
  * RHEL/CentOS 7
@@ -38,7 +44,7 @@ They may just work.
38
44
 
39
45
  ## Examples
40
46
 
41
- See <https://packager.io/> for examples of apps packaged with `pkgr` (Gitlab, OpenProject, Discourse, etc.).
47
+ See [Packager.io][packager-io] for examples of apps packaged with `pkgr` (Gitlab, OpenProject, Discourse, etc.).
42
48
 
43
49
  ## Installation
44
50
 
@@ -54,11 +60,11 @@ Or, installing as a gem, on debian-based machines:
54
60
 
55
61
  ## Usage
56
62
 
57
- To package your app, you can either execute `pkgr` locally if your app repository is on the same machine:
63
+ To package your app, execute `pkgr` against your app's repository:
58
64
 
59
65
  pkgr package path/to/app/repo
60
66
 
61
- The resulting .deb package will be in your current working directory.
67
+ The resulting `.deb` or `.rpm` package will be in your current working directory. That is, you need to run `pkgr` on the target distribution for which you want to generate a package.
62
68
 
63
69
  Full command line options are given below:
64
70
 
@@ -75,7 +81,8 @@ Full command line options are given below:
75
81
  [--architecture=ARCHITECTURE] # Target architecture for the package
76
82
  # Default: x86_64
77
83
  [--runner=RUNNER] # Force a specific runner (e.g. upstart-1.5, sysv-lsb-1.3)
78
- [--homepage=HOMEPAGE] # Project homepage
84
+ [--homepage=HOMEPAGE] # Project homepage (e.g. "https://pkgr.example.org")
85
+ [--home=HOME] # Project home (e.g. "/usr/share/PACKAGE_HOME")
79
86
  [--description=DESCRIPTION] # Project description
80
87
  [--category=CATEGORY] # Category this package belongs to
81
88
  # Default: none
@@ -147,11 +154,13 @@ Finally, it's a great way to share your open source software with your users and
147
154
 
148
155
  * Your app will reside in `/opt/app-name`.
149
156
 
150
- * You'll also get upstart (or sysvinit) initialization scripts that you can use directly:
157
+ * You'll also get upstart, systemd, or sysvinit initialization scripts (depending on your distribution) that you can use directly:
151
158
 
152
159
  service my-app start/stop/restart/status
153
160
 
154
- * Logs will be stored in `/var/log/app-name/`, with a proper logrotate config automatically added.
161
+ Note: init scripts are generated only after you've done a `scale` command for the process type, e.g. `my-app scale web=1`.
162
+
163
+ * Logs will be stored in `/var/log/app-name/`, with a proper logrotate config automatically added. For systemd-based distributions, you will find the logs in the systemd journal.
155
164
 
156
165
  * Config files can be added in `/etc/app-name/`
157
166
 
@@ -189,3 +198,5 @@ Issue getting nokogiri to compile? Try the following based on this [comment](htt
189
198
  ## Copyright
190
199
 
191
200
  See LICENSE (MIT)
201
+
202
+
@@ -1,15 +1,25 @@
1
1
  default:
2
2
  - curl
3
- - libmysqlclient-dev
4
3
  - libpq-dev
5
4
  - libsqlite3-0
6
5
  - libevent-dev
7
- - libssl-dev
8
6
  - libxml2-dev
9
7
  - libxslt1-dev
10
8
  - libreadline-dev
11
9
  - build-essential
12
10
  debian-6:
13
11
  - libssl0.9.8
12
+ - libssl-dev
13
+ - libmysqlclient-dev
14
14
  debian-7:
15
15
  - libssl1.0.0
16
+ - libssl-dev
17
+ - libmysqlclient-dev
18
+ debian-8:
19
+ - libssl1.0.0
20
+ - libssl-dev
21
+ - libmysqlclient-dev
22
+ debian-9:
23
+ - libssl1.0.2
24
+ - libssl1.0-dev
25
+ - default-libmysqlclient-dev
@@ -1,4 +1,4 @@
1
- https://github.com/pkgr/heroku-buildpack-ruby.git#buildcurl,BUILDPACK_NODE_VERSION="0.6.8"
1
+ https://github.com/pkgr/heroku-buildpack-ruby.git#v164-1,BUILDPACK_NODE_VERSION="0.6.8"
2
2
  https://github.com/pkgr/heroku-buildpack-python.git#buildcurl
3
- https://github.com/heroku/heroku-buildpack-nodejs.git#v58
3
+ https://github.com/heroku/heroku-buildpack-nodejs.git#v106
4
4
  https://github.com/kr/heroku-buildpack-go.git
@@ -1,4 +1,4 @@
1
- https://github.com/pkgr/heroku-buildpack-ruby.git#buildcurl,BUILDPACK_NODE_VERSION="0.6.8"
1
+ https://github.com/pkgr/heroku-buildpack-ruby.git#v164-1,BUILDPACK_NODE_VERSION="0.6.8"
2
2
  https://github.com/pkgr/heroku-buildpack-python.git#buildcurl
3
- https://github.com/heroku/heroku-buildpack-nodejs.git#v58
3
+ https://github.com/heroku/heroku-buildpack-nodejs.git#v106
4
4
  https://github.com/kr/heroku-buildpack-go.git
@@ -1,4 +1,4 @@
1
- https://github.com/pkgr/heroku-buildpack-ruby.git#buildcurl,BUILDPACK_NODE_VERSION="0.6.8"
1
+ https://github.com/pkgr/heroku-buildpack-ruby.git#v164-1,BUILDPACK_NODE_VERSION="0.6.8"
2
2
  https://github.com/pkgr/heroku-buildpack-python.git#buildcurl
3
- https://github.com/heroku/heroku-buildpack-nodejs.git#v58
3
+ https://github.com/heroku/heroku-buildpack-nodejs.git#v106
4
4
  https://github.com/kr/heroku-buildpack-go.git
@@ -1,4 +1,4 @@
1
- https://github.com/pkgr/heroku-buildpack-ruby.git#buildcurl,BUILDPACK_NODE_VERSION="0.6.8"
1
+ https://github.com/pkgr/heroku-buildpack-ruby.git#v164-1,BUILDPACK_NODE_VERSION="0.6.8"
2
2
  https://github.com/pkgr/heroku-buildpack-python.git#buildcurl
3
- https://github.com/heroku/heroku-buildpack-nodejs.git#v58
3
+ https://github.com/heroku/heroku-buildpack-nodejs.git#v106
4
4
  https://github.com/kr/heroku-buildpack-go.git
@@ -1,3 +1,3 @@
1
- https://github.com/pkgr/heroku-buildpack-ruby.git#buildcurl,BUILDPACK_NODE_VERSION="0.6.8"
1
+ https://github.com/pkgr/heroku-buildpack-ruby.git#v164-1,BUILDPACK_NODE_VERSION="0.6.8"
2
2
  https://github.com/pkgr/heroku-buildpack-python.git#buildcurl
3
3
  https://github.com/heroku/heroku-buildpack-ruby.git,CURL_CONNECT_TIMEOUT=60,CURL_TIMEOUT=300
@@ -1,4 +1,4 @@
1
- https://github.com/pkgr/heroku-buildpack-ruby.git#buildcurl,BUILDPACK_NODE_VERSION="0.6.8"
1
+ https://github.com/pkgr/heroku-buildpack-ruby.git#v164-1,BUILDPACK_NODE_VERSION="0.6.8"
2
2
  https://github.com/pkgr/heroku-buildpack-python.git#buildcurl
3
- https://github.com/heroku/heroku-buildpack-nodejs.git#v58
3
+ https://github.com/heroku/heroku-buildpack-nodejs.git#v106
4
4
  https://github.com/kr/heroku-buildpack-go.git
@@ -1,4 +1,4 @@
1
- https://github.com/pkgr/heroku-buildpack-ruby.git#buildcurl,BUILDPACK_NODE_VERSION="0.6.8"
1
+ https://github.com/pkgr/heroku-buildpack-ruby.git#v164-1,BUILDPACK_NODE_VERSION="0.6.8"
2
2
  https://github.com/pkgr/heroku-buildpack-python.git#buildcurl
3
- https://github.com/heroku/heroku-buildpack-nodejs.git#v58
3
+ https://github.com/heroku/heroku-buildpack-nodejs.git#v106
4
4
  https://github.com/kr/heroku-buildpack-go.git
@@ -0,0 +1,4 @@
1
+ https://github.com/pkgr/heroku-buildpack-ruby.git#v164-1,BUILDPACK_NODE_VERSION="0.6.8"
2
+ https://github.com/pkgr/heroku-buildpack-python.git#buildcurl
3
+ https://github.com/heroku/heroku-buildpack-nodejs.git#v106
4
+ https://github.com/kr/heroku-buildpack-go.git
@@ -1,3 +1,3 @@
1
- https://github.com/pkgr/heroku-buildpack-ruby.git#buildcurl,BUILDPACK_NODE_VERSION="0.6.8"
1
+ https://github.com/pkgr/heroku-buildpack-ruby.git#v164-1,BUILDPACK_NODE_VERSION="0.6.8"
2
2
  https://github.com/pkgr/heroku-buildpack-python.git#buildcurl
3
- https://github.com/heroku/heroku-buildpack-nodejs.git#v58
3
+ https://github.com/heroku/heroku-buildpack-nodejs.git#v106
@@ -1,3 +1,3 @@
1
- https://github.com/pkgr/heroku-buildpack-ruby.git#buildcurl,BUILDPACK_NODE_VERSION="0.6.8"
1
+ https://github.com/pkgr/heroku-buildpack-ruby.git#v164-1,BUILDPACK_NODE_VERSION="0.6.8"
2
2
  https://github.com/pkgr/heroku-buildpack-python.git#buildcurl
3
- https://github.com/heroku/heroku-buildpack-nodejs.git#v58
3
+ https://github.com/heroku/heroku-buildpack-nodejs.git#v106
@@ -1,3 +1,3 @@
1
- https://github.com/pkgr/heroku-buildpack-ruby.git#buildcurl,BUILDPACK_NODE_VERSION="0.6.8"
1
+ https://github.com/pkgr/heroku-buildpack-ruby.git#v164-1,BUILDPACK_NODE_VERSION="0.6.8"
2
2
  https://github.com/pkgr/heroku-buildpack-python.git#buildcurl
3
- https://github.com/heroku/heroku-buildpack-nodejs.git#v58
3
+ https://github.com/heroku/heroku-buildpack-nodejs.git#v106
@@ -1,3 +1,3 @@
1
- https://github.com/pkgr/heroku-buildpack-ruby.git#buildcurl,BUILDPACK_NODE_VERSION="0.6.8"
1
+ https://github.com/pkgr/heroku-buildpack-ruby.git#v164-1,BUILDPACK_NODE_VERSION="0.6.8"
2
2
  https://github.com/pkgr/heroku-buildpack-python.git#buildcurl
3
3
  https://github.com/heroku/heroku-buildpack-nodejs.git
@@ -1,4 +1,4 @@
1
- https://github.com/pkgr/heroku-buildpack-ruby.git#buildcurl,BUILDPACK_NODE_VERSION="0.6.8"
1
+ https://github.com/pkgr/heroku-buildpack-ruby.git#v164-1,BUILDPACK_NODE_VERSION="0.6.8"
2
2
  https://github.com/pkgr/heroku-buildpack-python.git#buildcurl
3
- https://github.com/heroku/heroku-buildpack-nodejs.git#v58
3
+ https://github.com/heroku/heroku-buildpack-nodejs.git#v106
4
4
  https://github.com/kr/heroku-buildpack-go.git
@@ -1,4 +1,4 @@
1
- https://github.com/pkgr/heroku-buildpack-ruby.git#buildcurl,BUILDPACK_NODE_VERSION="0.6.8"
1
+ https://github.com/pkgr/heroku-buildpack-ruby.git#v164-1,BUILDPACK_NODE_VERSION="0.6.8"
2
2
  https://github.com/pkgr/heroku-buildpack-python.git#buildcurl
3
- https://github.com/heroku/heroku-buildpack-nodejs.git#v58
3
+ https://github.com/heroku/heroku-buildpack-nodejs.git#v106
4
4
  https://github.com/kr/heroku-buildpack-go.git
@@ -1,4 +1,4 @@
1
- https://github.com/pkgr/heroku-buildpack-ruby.git#buildcurl,BUILDPACK_NODE_VERSION="0.6.8"
1
+ https://github.com/pkgr/heroku-buildpack-ruby.git#v164-1,BUILDPACK_NODE_VERSION="0.6.8"
2
2
  https://github.com/pkgr/heroku-buildpack-python.git#buildcurl
3
- https://github.com/heroku/heroku-buildpack-nodejs.git#v58
3
+ https://github.com/heroku/heroku-buildpack-nodejs.git#v106
4
4
  https://github.com/kr/heroku-buildpack-go.git
@@ -12,6 +12,10 @@ export ORIGINAL_PWD=$(pwd)
12
12
  # required for chroot on fedora
13
13
  PATH="$PATH:/usr/sbin"
14
14
 
15
+ if [ -n "$PORT" ]; then
16
+ BASE_PORT=$PORT
17
+ fi
18
+
15
19
  # Helper function that returns the real path, based on the given ROOT_PATH
16
20
  _p() {
17
21
  echo "${ROOT_PATH%%/}${1}"
@@ -26,6 +30,22 @@ usage() {
26
30
  echo " $APP_NAME config:set VAR=VALUE"
27
31
  echo " $APP_NAME configure"
28
32
  echo " $APP_NAME reconfigure"
33
+ echo " $APP_NAME restart"
34
+ echo ""
35
+ echo "Details:"
36
+ echo " $APP_NAME configure [-f FILE|-]"
37
+ echo " * If using an installer:"
38
+ echo " This command will launch the installer wizard."
39
+ echo " You can pass the installer seed file as argument or on STDIN."
40
+ echo " * Without installer:"
41
+ echo " This will execute the configure script at $APP_HOME/packaging/scripts/configure (if any)."
42
+ echo " A file containing environment variables can be given as argument or on STDIN (-f -), and will be saved in the /etc/$APP_NAME/conf.d folder."
43
+ echo ""
44
+ echo " $APP_NAME reconfigure"
45
+ echo " This command allows to reconfigure the application. Only useful if using an installer."
46
+ echo ""
47
+ echo " $APP_NAME restart [process]"
48
+ echo " This will restart the application (or the given process), in a distribution-independent manner."
29
49
  }
30
50
 
31
51
  DEFAULT_FILE=$(_p "/etc/default/${APP_NAME}")
@@ -50,11 +70,18 @@ fi
50
70
 
51
71
  # Source all environment variables for the app. This must be done as
52
72
  # privileged user since the config variables are only readable by root.
53
- PORT_WAS=$PORT
54
73
  for file in $(_p "/etc/${APP_NAME}/conf.d")/*; do
55
74
  if [ -f $file ]; then . $file; fi
56
75
  done
57
76
 
77
+ if [ -z "$BASE_PORT" ]; then
78
+ BASE_PORT=$PORT
79
+ fi
80
+
81
+ if [ -z "$BASE_PORT" ]; then
82
+ BASE_PORT=6000
83
+ fi
84
+
58
85
  # Some actions require root privileges
59
86
  ensure_root() {
60
87
  if [ $(id -u) -ne 0 ]; then
@@ -69,20 +96,44 @@ show_env() {
69
96
  env -i ROOT_PATH=${ROOT_PATH} ${0} run env | sort
70
97
  }
71
98
 
72
- logs() {
73
- if [ "$1" = "" ]; then
99
+ logs_opt() {
100
+ if [ "$1" == "" ]; then
74
101
  for file in $(_p "/var/log/${APP_NAME}")/*.log ; do
75
102
  echo "==> ${file} <=="
76
103
  cat "${file}"
77
104
  done
78
105
  else
79
- tail $(_p "/var/log/${APP_NAME}")/*.log $@
106
+ tail $(_p "/var/log/${APP_NAME}")/*.log "$@"
80
107
  fi
81
108
  }
109
+ logs_systemd() {
110
+ journalctl -u "$APP_NAME-*" -e "$@"
111
+ }
82
112
 
83
- tail_logs() {
113
+ logs() {
114
+ if [ "${APP_RUNNER_TYPE}" == "systemd" ]; then
115
+ # combine output of both opt and systemd logs
116
+ # no options given to log_opt since we want to use newer options of journalctl
117
+ { logs_opt & logs_systemd "$@" ; }
118
+ else
119
+ logs_opt "$@"
120
+ fi
121
+ }
122
+
123
+ tail_logs_opt() {
84
124
  tail -f $(_p "/var/log/${APP_NAME}")/*.log
85
125
  }
126
+ tail_logs_systemd() {
127
+ journalctl -u "$APP_NAME-*" -f "$@"
128
+ }
129
+ tail_logs() {
130
+ if [ "${APP_RUNNER_TYPE}" == "systemd" ]; then
131
+ # combine output of both opt and systemd logs
132
+ { tail_logs_opt & tail_logs_systemd "$@" ; }
133
+ else
134
+ tail_logs_opt
135
+ fi
136
+ }
86
137
 
87
138
  current_number_of_processes() {
88
139
  PROCESS_NAME="$1"
@@ -97,19 +148,47 @@ current_number_of_processes() {
97
148
  return 0
98
149
  }
99
150
 
100
- update_port() {
101
- file="$1"
102
- process_name="$2"
103
- port="$3"
104
- index="$4"
105
-
106
- sed -i "s/PROCESS_NUM/${index}/g" "${file}"
107
- if [ "${process_name}" = "web" ]; then
108
- sed -i "s/PORT_NUM/${port}/g" "${file}"
151
+ # Return the process index in the Procfile, ignoring any comment lines.
152
+ process_index() {
153
+ process_name="$1"
154
+ if [ -f "$(_p "${APP_HOME}/Procfile")" ]; then
155
+ index="$(cat "$(_p "${APP_HOME}/Procfile")" | grep -ve '^#' | grep -n "$process_name:" | cut -f 1 -d ':')"
109
156
  else
110
- sed -i "s/^env .*PORT_NUM.*$//g" "${file}"
111
- sed -i "s/^export PORT=PORT_NUM$//g" "${file}"
157
+ index=0
112
158
  fi
159
+ echo $(($index - 1))
160
+ }
161
+
162
+ # Returns whether a custom PORT has been set for this process.
163
+ is_custom_port() {
164
+ test "$PORT" != "$BASE_PORT"
165
+ }
166
+
167
+ # Returns the port to be used by the process.
168
+ process_port() {
169
+ local process_name="$1"
170
+ local process_scale_index="$2"
171
+ if [ "$process_scale_index" == "" ]; then
172
+ process_scale_index=1
173
+ fi
174
+ if is_custom_port; then
175
+ # legacy: port was set in init files, not touching
176
+ echo "$BASE_PORT"
177
+ else
178
+ local process_offset=$(process_index "$process_name")
179
+ local port_with_offset=$(($PORT + $process_offset * 100 + $process_scale_index - 1))
180
+ echo "$port_with_offset"
181
+ fi
182
+ }
183
+
184
+ # Writes the process index in the init file, so that the right PORT can be set
185
+ # when running the process.
186
+ update_port() {
187
+ local file="$1"
188
+ local process_name="$2"
189
+ local index="$3"
190
+ local port_with_offset=$(process_port "$process_name" "$index")
191
+ sed -i "s/__PROCESS_INDEX__/${index}/g" "${file}"
113
192
  }
114
193
 
115
194
  sysv_enable() {
@@ -147,68 +226,66 @@ scale_up() {
147
226
  index=$((${i} + ${CURRENT_SCALE}))
148
227
  PROCESS_ID="${APP_NAME}-${PROCESS_NAME}-${index}"
149
228
  cp $(_p "${APP_HOME}/vendor/pkgr/scaling/upstart/${APP_NAME}-${PROCESS_NAME}-PROCESS_NUM.conf") $(_p "/etc/init/${PROCESS_ID}.conf")
150
- port=$((${PORT} + ${index} - 1))
151
229
 
152
- update_port $(_p "/etc/init/${PROCESS_ID}.conf") "${PROCESS_NAME}" $port $index
230
+ update_port $(_p "/etc/init/${PROCESS_ID}.conf") "${PROCESS_NAME}" $index
153
231
 
154
232
  # directly call initctl instead of service, otherwise CentOS 6.x does not understand.
155
- $APP_RUNNER_CLI start "${PROCESS_ID}"
233
+ control_process start "${PROCESS_NAME}-${index}"
156
234
  done
157
235
 
158
- $APP_RUNNER_CLI start ${APP_NAME}-${PROCESS_NAME} || true
159
- $APP_RUNNER_CLI start ${APP_NAME} || true
236
+ control_process start "${PROCESS_NAME}" || true
237
+ control_process start || true
160
238
  elif [ "$APP_RUNNER_TYPE" = "systemd" ]; then
161
239
  for i in $(seq ${SCALE_DELTA}); do
162
240
  index=$((${i} + ${CURRENT_SCALE}))
163
241
  PROCESS_ID="${APP_NAME}-${PROCESS_NAME}-${index}"
164
242
  cp ${source}/${APP_NAME}-${PROCESS_NAME}-PROCESS_NUM.service $SYSTEMD_DIR/${PROCESS_ID}.service
165
- port=$((${PORT} + ${index} - 1))
166
243
 
167
- update_port $SYSTEMD_DIR/${PROCESS_ID}.service "${PROCESS_NAME}" $port $index
244
+ update_port $SYSTEMD_DIR/${PROCESS_ID}.service "${PROCESS_NAME}" $index
168
245
 
169
246
  $APP_RUNNER_CLI enable "${PROCESS_ID}.service"
170
247
  done
171
248
 
172
249
  $APP_RUNNER_CLI daemon-reload
173
- $APP_RUNNER_CLI start ${APP_NAME}-${PROCESS_NAME}.service
174
- $APP_RUNNER_CLI start ${APP_NAME}.service
250
+ control_process start "${PROCESS_NAME}"
251
+ control_process start
175
252
  else
176
253
  for i in $(seq ${SCALE_DELTA}); do
177
254
  index=$((${i} + ${CURRENT_SCALE}))
178
255
  PROCESS_ID="${APP_NAME}-${PROCESS_NAME}-${index}"
179
256
  cp $(_p "${APP_HOME}/vendor/pkgr/scaling/sysv/${APP_NAME}-${PROCESS_NAME}-PROCESS_NUM") $(_p "/etc/init.d/${PROCESS_ID}")
180
- port=$((${PORT} + ${index} - 1))
181
257
 
182
- update_port $(_p "/etc/init.d/${PROCESS_ID}") "${PROCESS_NAME}" $port $index
258
+ update_port $(_p "/etc/init.d/${PROCESS_ID}") "${PROCESS_NAME}" $index
183
259
 
184
260
  chmod a+x $(_p "/etc/init.d/${PROCESS_ID}")
185
- sysv_enable ${PROCESS_ID}
186
- $(_p "/etc/init.d/${PROCESS_ID}") start
261
+ sysv_enable "${PROCESS_ID}"
262
+ control_process start "${PROCESS_NAME}-${index}"
187
263
  done
188
264
  fi
189
265
  echo "--> done."
190
266
  }
191
267
 
192
268
  scale_down() {
193
- PROCESS_NAME="${1}"
194
- CURRENT_SCALE=${2}
195
- NEW_SCALE=${3}
196
- SCALE_DELTA=${4}
269
+ local PROCESS_NAME="${1}"
270
+ local CURRENT_SCALE=${2}
271
+ local NEW_SCALE=${3}
272
+ local SCALE_DELTA=${4}
273
+ local index
274
+ local PROCESS_ID
197
275
 
198
276
  echo "Scaling down..."
199
277
  for i in $(seq $(($SCALE_DELTA * -1))); do
200
278
  index=$((${i} + ${NEW_SCALE}))
201
279
  PROCESS_ID="${APP_NAME}-${PROCESS_NAME}-${index}"
202
280
 
281
+ control_process stop "${PROCESS_NAME}-${index}" || true # dont fail if server stopped differently
282
+
203
283
  if [ "${APP_RUNNER_TYPE}" = "upstart" ]; then
204
- $APP_RUNNER_CLI stop "${PROCESS_ID}" || true # dont fail if server stopped differently
205
284
  rm -f $(_p "/etc/init/${PROCESS_ID}.conf")
206
285
  elif [ "${APP_RUNNER_TYPE}" = "systemd" ]; then
207
- $APP_RUNNER_CLI stop "${PROCESS_ID}.service" || true # dont fail if server stopped differently
208
286
  $APP_RUNNER_CLI disable "${PROCESS_ID}.service" || true
209
287
  rm -f $SYSTEMD_DIR/${PROCESS_ID}.service
210
288
  else
211
- $(_p "/etc/init.d/${PROCESS_ID}") stop
212
289
  sysv_disable ${PROCESS_ID}
213
290
  rm -f $(_p "/etc/init.d/${PROCESS_ID}")
214
291
  fi
@@ -262,10 +339,27 @@ scale() {
262
339
 
263
340
  configure() {
264
341
  local installer_dir="$(_p "/usr/share/${APP_NAME}/installer")"
342
+ local configure_script="$(_p "$APP_HOME/packaging/scripts/configure")"
343
+ local file=""
344
+ if [ "$1" == "-f" ]; then
345
+ file="$2"
346
+ shift 2
347
+ fi
348
+
265
349
  if [ -d "$installer_dir" ] ; then
266
- ${installer_dir}/bin/run $@
350
+ if [ "$file" != "" ]; then
351
+ cat "$file" > $(_p "/etc/$APP_NAME/installer.dat")
352
+ fi
353
+ exec ${installer_dir}/bin/run "$@"
267
354
  else
268
- echo "No installer has been configured for ${APP_NAME}"
355
+ if [ "$file" != "" ]; then
356
+ cat "$file" | grep -v '^#' | while read -r line ; do
357
+ config_set "$line"
358
+ done
359
+ fi
360
+ if [ -f "$configure_script" -a -x "$configure_script" ] ; then
361
+ exec $0 run "$configure_script" "$@"
362
+ fi
269
363
  fi
270
364
  }
271
365
 
@@ -273,6 +367,36 @@ reconfigure() {
273
367
  configure --reconfigure
274
368
  }
275
369
 
370
+ config_set() {
371
+ # http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02
372
+ local key="${1%%=*}"
373
+ local value="${1#*=}"
374
+ local file=$(_p "/etc/${APP_NAME}/conf.d/other")
375
+ touch "$file"
376
+ sed -i -r "s/^\s*export\s+${key}.*$//g" $(_p "/etc/${APP_NAME}/conf.d")/*
377
+ echo "export ${key}=\"${value}\"" >> "${file}"
378
+ sed -i '/^\s*$/d' "$file"
379
+ }
380
+
381
+ # Executes the given command (start, stop, restart, status, etc.) on the given
382
+ # process, abstracting away the differences between init systems.
383
+ control_process() {
384
+ local cmd="$1"
385
+ local process="$2"
386
+ local service="$APP_NAME"
387
+ if [ "$process" != "" ]; then
388
+ service="$service-$process"
389
+ fi
390
+
391
+ if [ "${APP_RUNNER_TYPE}" == "upstart" ]; then
392
+ $APP_RUNNER_CLI "$cmd" "${service}"
393
+ elif [ "$APP_RUNNER_TYPE" = "systemd" ]; then
394
+ $APP_RUNNER_CLI "$cmd" "${service}.service"
395
+ else
396
+ $(_p "/etc/init.d/${service}") "$cmd"
397
+ fi
398
+ }
399
+
276
400
  while : ; do
277
401
  case "$1" in
278
402
  run)
@@ -283,6 +407,7 @@ while : ; do
283
407
  runnable=$(echo -n "exec")
284
408
 
285
409
  if [ -f $(_p "${APP_HOME}/vendor/pkgr/processes/${COMMAND}") ]; then
410
+ export PORT=$(process_port "$COMMAND" "$APP_PROCESS_INDEX")
286
411
  # Command alias defined in Procfile
287
412
  runnable="${runnable}$(printf " %q" $(_p "${APP_HOME}/vendor/pkgr/processes/${COMMAND}") "$@")"
288
413
  else
@@ -294,9 +419,6 @@ while : ; do
294
419
  runnable="${runnable}$(printf " %q" ${COMMAND} "$@")"
295
420
  fi
296
421
 
297
- # fix port
298
- export PORT=$PORT_WAS
299
-
300
422
  # Do not use su, to avoid creating a new process. Note: chroot version
301
423
  # is too old on Ubuntu Lucid, so this will fail. It works on Debian
302
424
  # Squeeze though (and later).
@@ -325,12 +447,18 @@ while : ; do
325
447
  done
326
448
  break ;;
327
449
 
450
+ restart)
451
+ shift
452
+ control_process "restart" "$@"
453
+ break;;
454
+
328
455
  logs)
329
456
  shift
330
- if [ "$1" = "--tail" ]; then
457
+ if [ "$1" == "--tail" -o "$1" == "-f" ]; then
458
+ shift
331
459
  tail_logs
332
460
  else
333
- logs ${@}
461
+ logs "${@}"
334
462
  fi
335
463
  break;;
336
464
 
@@ -340,18 +468,7 @@ while : ; do
340
468
 
341
469
  config:set)
342
470
  [ $# -lt 2 ] && usage
343
-
344
- CONFIG=(${2//=/ })
345
-
346
- VAR=${CONFIG[0]:?"Invalid variable name"}
347
- VALUE="${2:$((${#VAR} + 1))}"
348
-
349
- CONFIG_FILE=$(_p "/etc/${APP_NAME}/conf.d/other")
350
- touch ${CONFIG_FILE}
351
-
352
- sed -i -r "s/^\s*export\s+${VAR}.*$//g" $(_p "/etc/${APP_NAME}/conf.d")/*
353
-
354
- echo "export ${VAR}=\"${VALUE}\"" >> "${CONFIG_FILE}"
471
+ config_set "$2"
355
472
 
356
473
  break;;
357
474
 
@@ -362,14 +479,16 @@ while : ; do
362
479
 
363
480
  configure)
364
481
  ensure_root
482
+ shift
365
483
 
366
- configure $@
484
+ configure "$@"
367
485
  break;;
368
486
 
369
487
  reconfigure)
370
488
  ensure_root
489
+ shift
371
490
 
372
- reconfigure $@
491
+ reconfigure "$@"
373
492
  break;;
374
493
 
375
494
  *)