pkgr 1.5.1 → 1.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +2 -2
  3. data/README.md +29 -19
  4. data/data/build_dependencies/debian.yml +16 -2
  5. data/data/build_dependencies/ubuntu.yml +6 -0
  6. data/data/buildpacks/amazon-2014 +2 -2
  7. data/data/buildpacks/amazon-2015 +2 -2
  8. data/data/buildpacks/centos-6 +2 -2
  9. data/data/buildpacks/centos-7 +2 -2
  10. data/data/buildpacks/centos-8 +4 -0
  11. data/data/buildpacks/debian-10 +4 -0
  12. data/data/buildpacks/debian-6 +1 -1
  13. data/data/buildpacks/debian-7 +2 -2
  14. data/data/buildpacks/debian-8 +2 -2
  15. data/data/buildpacks/debian-9 +4 -0
  16. data/data/buildpacks/fedora-20 +2 -2
  17. data/data/buildpacks/sles-11 +2 -2
  18. data/data/buildpacks/sles-12 +2 -2
  19. data/data/buildpacks/ubuntu-10.04 +1 -1
  20. data/data/buildpacks/ubuntu-12.04 +2 -2
  21. data/data/buildpacks/ubuntu-14.04 +2 -2
  22. data/data/buildpacks/ubuntu-16.04 +2 -2
  23. data/data/buildpacks/ubuntu-18.04 +4 -0
  24. data/data/buildpacks/ubuntu-20.04 +4 -0
  25. data/data/cli/cli.sh.erb +201 -59
  26. data/data/dependencies/centos.yml +6 -1
  27. data/data/dependencies/debian.yml +15 -4
  28. data/data/dependencies/sles.yml +1 -1
  29. data/data/dependencies/ubuntu.yml +23 -2
  30. data/data/hooks/postinstall.sh +2 -1
  31. data/data/hooks/postuninstall.sh +1 -1
  32. data/data/hooks/preinstall.sh +1 -1
  33. data/data/hooks/preuninstall.sh +1 -1
  34. data/data/init/systemd/default/process.service.erb +1 -1
  35. data/data/init/sysv/lsb-3.1/process.erb +3 -4
  36. data/data/init/upstart/1.5/process.conf.erb +1 -1
  37. data/data/logrotate/logrotate.erb +2 -2
  38. data/lib/pkgr/builder.rb +31 -22
  39. data/lib/pkgr/buildpack.rb +30 -8
  40. data/lib/pkgr/cli.rb +16 -3
  41. data/lib/pkgr/config.rb +20 -0
  42. data/lib/pkgr/dispatcher.rb +1 -1
  43. data/lib/pkgr/distributions/amazon.rb +38 -1
  44. data/lib/pkgr/distributions/base.rb +11 -10
  45. data/lib/pkgr/distributions/debian.rb +1 -1
  46. data/lib/pkgr/distributions/redhat.rb +0 -2
  47. data/lib/pkgr/distributions/ubuntu.rb +3 -3
  48. data/lib/pkgr/env.rb +10 -4
  49. data/lib/pkgr/env_value.rb +55 -0
  50. data/lib/pkgr/version.rb +1 -1
  51. metadata +14 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b6953d1856b4cb7378d7465a3cfb0bc8f7e21ce7
4
- data.tar.gz: 4416c2783fe73bc50d797d99e64e178e183dc04e
2
+ SHA256:
3
+ metadata.gz: e98f1b219e5532799c5127fd9796eaebe923e44446c0456157dbea92d2603047
4
+ data.tar.gz: 0e374445dac42c0e483e53e9fd9763296d7ba079c2ea1e94b7e683ef7b99e8ce
5
5
  SHA512:
6
- metadata.gz: 4ebeee46be1c87ce49ef306362a2f2da56007a121c2eaef55300837421a145241c51468652d8353329cdd8789777565d375fcea015012972ccf802e6dac6c33b
7
- data.tar.gz: dafa9e7fc52334d49b2b536b5b0fbd253cd7ab0a5b5be6d41c190b2139ec7c05d994c1ba5a42b113e3299ef3cfebdf615d0696a049a981715c1825a7aeff268a
6
+ metadata.gz: 0e7ef7cefe654a5349b8e2ace2d42b63fc2fe71c05216d9f76235c498f80636cee4bb858c3a4afed5cf8f69c8d4a934e41fbf2cd67bb9901199aaf0afe1efaa2
7
+ data.tar.gz: f208b312bd1a128d2f755863dc1bb01b54353a727c68381a8eb62321a22d1c2e330c56abc1475900be4623443cb95ee4fb2b5b7fa0dba072e96b7c67815e1a9f
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)).
@@ -24,11 +29,16 @@ They may just work.
24
29
 
25
30
  ## Supported distributions (64bits only)
26
31
 
32
+ * Ubuntu 20.04 ("focal")
33
+ * Ubuntu 18.04 ("bionic")
27
34
  * Ubuntu 16.04 ("xenial")
28
35
  * Ubuntu 14.04 ("trusty")
29
36
  * Ubuntu 12.04 ("precise")
37
+ * Debian 10 ("buster")
38
+ * Debian 9 ("stretch")
30
39
  * Debian 8 ("jessie")
31
40
  * Debian 7 ("wheezy")
41
+ * RHEL/CentOS 8
32
42
  * RHEL/CentOS 7
33
43
  * RHEL/CentOS 6
34
44
  * Suse Linux Enterprise Server 12
@@ -38,27 +48,19 @@ They may just work.
38
48
 
39
49
  ## Examples
40
50
 
41
- See <https://packager.io/> for examples of apps packaged with `pkgr` (Gitlab, OpenProject, Discourse, etc.).
51
+ See [Packager.io][packager-io] for examples of apps packaged with `pkgr` (Gitlab, OpenProject, Discourse, etc.).
42
52
 
43
53
  ## Installation
44
54
 
45
- You can find DEB and RPM packages for a wide range of distributions on Packager.io:
46
-
47
- <https://packager.io/gh/crohr/pkgr>
48
-
49
- Or, installing as a gem, on debian-based machines:
50
-
51
- sudo apt-get update
52
- sudo apt-get install -y build-essential ruby1.9.1-full rubygems1.9.1
53
- sudo gem install pkgr
55
+ gem install pkgr
54
56
 
55
57
  ## Usage
56
58
 
57
- To package your app, you can either execute `pkgr` locally if your app repository is on the same machine:
59
+ To package your app, execute `pkgr` against your app's repository:
58
60
 
59
61
  pkgr package path/to/app/repo
60
62
 
61
- The resulting .deb package will be in your current working directory.
63
+ 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
64
 
63
65
  Full command line options are given below:
64
66
 
@@ -75,7 +77,13 @@ Full command line options are given below:
75
77
  [--architecture=ARCHITECTURE] # Target architecture for the package
76
78
  # Default: x86_64
77
79
  [--runner=RUNNER] # Force a specific runner (e.g. upstart-1.5, sysv-lsb-1.3)
78
- [--homepage=HOMEPAGE] # Project homepage
80
+ [--logrotate-frequency=FREQUENCY] # Set logrotate frequency
81
+ # Default: daily
82
+ # Possible values: daily, weekly, monthly, yearly
83
+ [--logrotate-backlog=BACKLOG] # Set logrotate backlog
84
+ # Default: 14
85
+ [--homepage=HOMEPAGE] # Project homepage (e.g. "https://pkgr.example.org")
86
+ [--home=HOME] # Project home (e.g. "/usr/share/PACKAGE_HOME")
79
87
  [--description=DESCRIPTION] # Project description
80
88
  [--category=CATEGORY] # Category this package belongs to
81
89
  # Default: none
@@ -133,7 +141,7 @@ Finally, it's a great way to share your open source software with your users and
133
141
 
134
142
  * Uses Heroku buildpacks to embed all the dependencies related to your application runtime within the debian package. For a Rails app for instance, this means that `pkgr` will embed the specific ruby runtime you asked for, along with all the gems specified in your Gemfile. However, all other dependencies you may need must be specified as additional system dependencies (see Usage). This avoids the 'packaging-the-world' approach used by other tools such as omnibus (with the pros and cons that come with it), but it still allows you to use the latest and greatest libraries for your language of choice. See this [blog post][background-pkgr] for more background.
135
143
 
136
- [background-pkgr]: http://blog.packager.io/post/81988994454/why-i-made-pkgr-io-digressions-on-software-packaging
144
+ [background-pkgr]: https://blog.packager.io/posts/1-why-i-made-packager-io-digressions-on-software-packaging
137
145
 
138
146
  * Gives you a nice executable, which closely replicates the Heroku toolbelt utility. For instance, assuming you're packaging an app called `my-app`, you can do the following:
139
147
 
@@ -147,11 +155,13 @@ Finally, it's a great way to share your open source software with your users and
147
155
 
148
156
  * Your app will reside in `/opt/app-name`.
149
157
 
150
- * You'll also get upstart (or sysvinit) initialization scripts that you can use directly:
158
+ * You'll also get upstart, systemd, or sysvinit initialization scripts (depending on your distribution) that you can use directly:
151
159
 
152
160
  service my-app start/stop/restart/status
153
161
 
154
- * Logs will be stored in `/var/log/app-name/`, with a proper logrotate config automatically added.
162
+ Note: init scripts are generated only after you've done a `scale` command for the process type, e.g. `my-app scale web=1`.
163
+
164
+ * 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
165
 
156
166
  * Config files can be added in `/etc/app-name/`
157
167
 
@@ -1,15 +1,29 @@
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
26
+ debian-10:
27
+ - libssl1.1
28
+ - libssl-dev
29
+ - default-libmysqlclient-dev
@@ -13,5 +13,11 @@ ubuntu-10.04:
13
13
  - libssl0.9.8
14
14
  ubuntu-12.04:
15
15
  - libssl1.0.0
16
+ ubuntu-14.04:
17
+ - libssl1.0.0
16
18
  ubuntu-16.04:
17
19
  - libssl1.0.0
20
+ ubuntu-18.04:
21
+ - libssl1.0.0
22
+ ubuntu-20.04:
23
+ - libssl1.1
@@ -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#v212-1
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#v212-1
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#v212-1
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#v212-1
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#v212-1
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
@@ -0,0 +1,4 @@
1
+ https://github.com/pkgr/heroku-buildpack-ruby.git#v212-1
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#v212-1
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#v212-1
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#v212-1
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#v212-1
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#v212-1
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#v212-1
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#v212-1
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#v212-1
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#v212-1
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#v212-1
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#v212-1
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#v212-1
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
@@ -0,0 +1,4 @@
1
+ https://github.com/pkgr/heroku-buildpack-ruby.git#v212-1
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
@@ -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}"
@@ -24,8 +28,26 @@ usage() {
24
28
  echo " $APP_NAME logs [--tail|-n NUMBER]"
25
29
  echo " $APP_NAME config:get VAR"
26
30
  echo " $APP_NAME config:set VAR=VALUE"
31
+ echo " $APP_NAME config:unset VAR"
27
32
  echo " $APP_NAME configure"
28
33
  echo " $APP_NAME reconfigure"
34
+ echo " $APP_NAME restart"
35
+ echo ""
36
+ echo "Details:"
37
+ echo " $APP_NAME configure [-f FILE|-]"
38
+ echo " * If using an installer:"
39
+ echo " This command will launch the installer wizard."
40
+ echo " You can pass the installer seed file as argument or on STDIN."
41
+ echo " * Without installer:"
42
+ echo " This will execute the configure script at $APP_HOME/packaging/scripts/configure (if any)."
43
+ 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."
44
+ echo ""
45
+ echo " $APP_NAME reconfigure"
46
+ echo " This command allows to reconfigure the application. Only useful if using an installer."
47
+ echo ""
48
+ echo " $APP_NAME restart [process]"
49
+ echo " This will restart the application (or the given process), in a distribution-independent manner."
50
+ exit 64
29
51
  }
30
52
 
31
53
  DEFAULT_FILE=$(_p "/etc/default/${APP_NAME}")
@@ -39,7 +61,19 @@ for file in $(_p "${APP_HOME}/.profile.d")/*.sh; do
39
61
  done
40
62
 
41
63
  if [ "$APP_CLI" != "" ] ; then
42
- exec $APP_HOME/bin/$APP_CLI "$@"
64
+ cli_path="$APP_CLI"
65
+ if [ ! -e "$cli_path" ]; then
66
+ cli_path="$APP_HOME/$APP_CLI"
67
+ fi
68
+ if [ ! -e "$cli_path" ]; then
69
+ cli_path="$APP_HOME/bin/$APP_CLI"
70
+ fi
71
+ if [ -e "$cli_path" ]; then
72
+ exec "$cli_path" "$@"
73
+ else
74
+ echo "Error: the given CLI ($APP_CLI) does not point to any valid executable"
75
+ exit 1
76
+ fi
43
77
  fi
44
78
 
45
79
  if [ ! -w "$(_p "/etc/${APP_NAME}/conf.d")" ] ; then
@@ -50,11 +84,18 @@ fi
50
84
 
51
85
  # Source all environment variables for the app. This must be done as
52
86
  # privileged user since the config variables are only readable by root.
53
- PORT_WAS=$PORT
54
87
  for file in $(_p "/etc/${APP_NAME}/conf.d")/*; do
55
88
  if [ -f $file ]; then . $file; fi
56
89
  done
57
90
 
91
+ if [ -z "$BASE_PORT" ]; then
92
+ BASE_PORT=$PORT
93
+ fi
94
+
95
+ if [ -z "$BASE_PORT" ]; then
96
+ BASE_PORT=6000
97
+ fi
98
+
58
99
  # Some actions require root privileges
59
100
  ensure_root() {
60
101
  if [ $(id -u) -ne 0 ]; then
@@ -69,20 +110,44 @@ show_env() {
69
110
  env -i ROOT_PATH=${ROOT_PATH} ${0} run env | sort
70
111
  }
71
112
 
72
- logs() {
73
- if [ "$1" = "" ]; then
113
+ logs_opt() {
114
+ if [ "$1" == "" ]; then
74
115
  for file in $(_p "/var/log/${APP_NAME}")/*.log ; do
75
116
  echo "==> ${file} <=="
76
117
  cat "${file}"
77
118
  done
78
119
  else
79
- tail $(_p "/var/log/${APP_NAME}")/*.log $@
120
+ tail $(_p "/var/log/${APP_NAME}")/*.log "$@"
80
121
  fi
81
122
  }
123
+ logs_systemd() {
124
+ journalctl -u "$APP_NAME-*" -e "$@"
125
+ }
82
126
 
83
- tail_logs() {
127
+ logs() {
128
+ if [ "${APP_RUNNER_TYPE}" == "systemd" ]; then
129
+ # combine output of both opt and systemd logs
130
+ # no options given to log_opt since we want to use newer options of journalctl
131
+ { logs_opt & logs_systemd "$@" ; }
132
+ else
133
+ logs_opt "$@"
134
+ fi
135
+ }
136
+
137
+ tail_logs_opt() {
84
138
  tail -f $(_p "/var/log/${APP_NAME}")/*.log
85
139
  }
140
+ tail_logs_systemd() {
141
+ journalctl -u "$APP_NAME-*" -f "$@"
142
+ }
143
+ tail_logs() {
144
+ if [ "${APP_RUNNER_TYPE}" == "systemd" ]; then
145
+ # combine output of both opt and systemd logs
146
+ { tail_logs_opt & tail_logs_systemd "$@" ; }
147
+ else
148
+ tail_logs_opt
149
+ fi
150
+ }
86
151
 
87
152
  current_number_of_processes() {
88
153
  PROCESS_NAME="$1"
@@ -97,21 +162,49 @@ current_number_of_processes() {
97
162
  return 0
98
163
  }
99
164
 
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}"
165
+ # Return the process index in the Procfile, ignoring any comment lines.
166
+ process_index() {
167
+ process_name="$1"
168
+ if [ -f "$(_p "${APP_HOME}/Procfile")" ]; then
169
+ index="$(cat "$(_p "${APP_HOME}/Procfile")" | grep -ve '^#' | grep -n "$process_name:" | cut -f 1 -d ':')"
170
+ else
171
+ index=0
172
+ fi
173
+ echo $(($index - 1))
174
+ }
175
+
176
+ # Returns whether a custom PORT has been set for this process.
177
+ is_custom_port() {
178
+ test "$PORT" != "$BASE_PORT"
179
+ }
180
+
181
+ # Returns the port to be used by the process.
182
+ process_port() {
183
+ local process_name="$1"
184
+ local process_scale_index="$2"
185
+ if [ "$process_scale_index" == "" ]; then
186
+ process_scale_index=1
187
+ fi
188
+ if is_custom_port; then
189
+ # legacy: port was set in init files, not touching
190
+ echo "$BASE_PORT"
109
191
  else
110
- sed -i "s/^env .*PORT_NUM.*$//g" "${file}"
111
- sed -i "s/^export PORT=PORT_NUM$//g" "${file}"
192
+ local process_offset=$(process_index "$process_name")
193
+ local port_with_offset=$(($PORT + $process_offset * 100 + $process_scale_index - 1))
194
+ echo "$port_with_offset"
112
195
  fi
113
196
  }
114
197
 
198
+ # Writes the process index in the init file, so that the right PORT can be set
199
+ # when running the process.
200
+ update_port() {
201
+ local file="$1"
202
+ local process_name="$2"
203
+ local index="$3"
204
+ local port_with_offset=$(process_port "$process_name" "$index")
205
+ sed -i "s/__PROCESS_INDEX__/${index}/g" "${file}"
206
+ }
207
+
115
208
  sysv_enable() {
116
209
  local name="$1"
117
210
  if [ "$APP_RUNNER_CLI" = "chkconfig" ] ; then
@@ -147,68 +240,66 @@ scale_up() {
147
240
  index=$((${i} + ${CURRENT_SCALE}))
148
241
  PROCESS_ID="${APP_NAME}-${PROCESS_NAME}-${index}"
149
242
  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
243
 
152
- update_port $(_p "/etc/init/${PROCESS_ID}.conf") "${PROCESS_NAME}" $port $index
244
+ update_port $(_p "/etc/init/${PROCESS_ID}.conf") "${PROCESS_NAME}" $index
153
245
 
154
246
  # directly call initctl instead of service, otherwise CentOS 6.x does not understand.
155
- $APP_RUNNER_CLI start "${PROCESS_ID}"
247
+ control_process start "${PROCESS_NAME}-${index}"
156
248
  done
157
249
 
158
- $APP_RUNNER_CLI start ${APP_NAME}-${PROCESS_NAME} || true
159
- $APP_RUNNER_CLI start ${APP_NAME} || true
250
+ control_process start "${PROCESS_NAME}" || true
251
+ control_process start || true
160
252
  elif [ "$APP_RUNNER_TYPE" = "systemd" ]; then
161
253
  for i in $(seq ${SCALE_DELTA}); do
162
254
  index=$((${i} + ${CURRENT_SCALE}))
163
255
  PROCESS_ID="${APP_NAME}-${PROCESS_NAME}-${index}"
164
256
  cp ${source}/${APP_NAME}-${PROCESS_NAME}-PROCESS_NUM.service $SYSTEMD_DIR/${PROCESS_ID}.service
165
- port=$((${PORT} + ${index} - 1))
166
257
 
167
- update_port $SYSTEMD_DIR/${PROCESS_ID}.service "${PROCESS_NAME}" $port $index
258
+ update_port $SYSTEMD_DIR/${PROCESS_ID}.service "${PROCESS_NAME}" $index
168
259
 
169
260
  $APP_RUNNER_CLI enable "${PROCESS_ID}.service"
170
261
  done
171
262
 
172
263
  $APP_RUNNER_CLI daemon-reload
173
- $APP_RUNNER_CLI start ${APP_NAME}-${PROCESS_NAME}.service
174
- $APP_RUNNER_CLI start ${APP_NAME}.service
264
+ control_process start "${PROCESS_NAME}"
265
+ control_process start
175
266
  else
176
267
  for i in $(seq ${SCALE_DELTA}); do
177
268
  index=$((${i} + ${CURRENT_SCALE}))
178
269
  PROCESS_ID="${APP_NAME}-${PROCESS_NAME}-${index}"
179
270
  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
271
 
182
- update_port $(_p "/etc/init.d/${PROCESS_ID}") "${PROCESS_NAME}" $port $index
272
+ update_port $(_p "/etc/init.d/${PROCESS_ID}") "${PROCESS_NAME}" $index
183
273
 
184
274
  chmod a+x $(_p "/etc/init.d/${PROCESS_ID}")
185
- sysv_enable ${PROCESS_ID}
186
- $(_p "/etc/init.d/${PROCESS_ID}") start
275
+ sysv_enable "${PROCESS_ID}"
276
+ control_process start "${PROCESS_NAME}-${index}"
187
277
  done
188
278
  fi
189
279
  echo "--> done."
190
280
  }
191
281
 
192
282
  scale_down() {
193
- PROCESS_NAME="${1}"
194
- CURRENT_SCALE=${2}
195
- NEW_SCALE=${3}
196
- SCALE_DELTA=${4}
283
+ local PROCESS_NAME="${1}"
284
+ local CURRENT_SCALE=${2}
285
+ local NEW_SCALE=${3}
286
+ local SCALE_DELTA=${4}
287
+ local index
288
+ local PROCESS_ID
197
289
 
198
290
  echo "Scaling down..."
199
291
  for i in $(seq $(($SCALE_DELTA * -1))); do
200
292
  index=$((${i} + ${NEW_SCALE}))
201
293
  PROCESS_ID="${APP_NAME}-${PROCESS_NAME}-${index}"
202
294
 
295
+ control_process stop "${PROCESS_NAME}-${index}" || true # dont fail if server stopped differently
296
+
203
297
  if [ "${APP_RUNNER_TYPE}" = "upstart" ]; then
204
- $APP_RUNNER_CLI stop "${PROCESS_ID}" || true # dont fail if server stopped differently
205
298
  rm -f $(_p "/etc/init/${PROCESS_ID}.conf")
206
299
  elif [ "${APP_RUNNER_TYPE}" = "systemd" ]; then
207
- $APP_RUNNER_CLI stop "${PROCESS_ID}.service" || true # dont fail if server stopped differently
208
300
  $APP_RUNNER_CLI disable "${PROCESS_ID}.service" || true
209
301
  rm -f $SYSTEMD_DIR/${PROCESS_ID}.service
210
302
  else
211
- $(_p "/etc/init.d/${PROCESS_ID}") stop
212
303
  sysv_disable ${PROCESS_ID}
213
304
  rm -f $(_p "/etc/init.d/${PROCESS_ID}")
214
305
  fi
@@ -262,10 +353,27 @@ scale() {
262
353
 
263
354
  configure() {
264
355
  local installer_dir="$(_p "/usr/share/${APP_NAME}/installer")"
356
+ local configure_script="$(_p "$APP_HOME/packaging/scripts/configure")"
357
+ local file=""
358
+ if [ "$1" == "-f" ]; then
359
+ file="$2"
360
+ shift 2
361
+ fi
362
+
265
363
  if [ -d "$installer_dir" ] ; then
266
- ${installer_dir}/bin/run $@
364
+ if [ "$file" != "" ]; then
365
+ cat "$file" > $(_p "/etc/$APP_NAME/installer.dat")
366
+ fi
367
+ exec ${installer_dir}/bin/run "$@"
267
368
  else
268
- echo "No installer has been configured for ${APP_NAME}"
369
+ if [ "$file" != "" ]; then
370
+ cat "$file" | grep -v '^#' | while read -r line ; do
371
+ config_set "$line"
372
+ done
373
+ fi
374
+ if [ -f "$configure_script" -a -x "$configure_script" ] ; then
375
+ exec $0 run "$configure_script" "$@"
376
+ fi
269
377
  fi
270
378
  }
271
379
 
@@ -273,6 +381,41 @@ reconfigure() {
273
381
  configure --reconfigure
274
382
  }
275
383
 
384
+ config_unset() {
385
+ local key="${1}"
386
+ sed -i -r "s/^\s*export\s+${key}.*$//g" $(_p "/etc/${APP_NAME}/conf.d")/*
387
+ }
388
+
389
+ config_set() {
390
+ # http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02
391
+ local key="${1%%=*}"
392
+ local value="${1#*=}"
393
+ local file=$(_p "/etc/${APP_NAME}/conf.d/other")
394
+ touch "$file"
395
+ config_unset "$key"
396
+ echo "export ${key}=\"${value}\"" >> "${file}"
397
+ sed -i '/^\s*$/d' "$file"
398
+ }
399
+
400
+ # Executes the given command (start, stop, restart, status, etc.) on the given
401
+ # process, abstracting away the differences between init systems.
402
+ control_process() {
403
+ local cmd="$1"
404
+ local process="$2"
405
+ local service="$APP_NAME"
406
+ if [ "$process" != "" ]; then
407
+ service="$service-$process"
408
+ fi
409
+
410
+ if [ "${APP_RUNNER_TYPE}" == "upstart" ]; then
411
+ $APP_RUNNER_CLI "$cmd" "${service}"
412
+ elif [ "$APP_RUNNER_TYPE" = "systemd" ]; then
413
+ $APP_RUNNER_CLI "$cmd" "${service}.service"
414
+ else
415
+ $(_p "/etc/init.d/${service}") "$cmd"
416
+ fi
417
+ }
418
+
276
419
  while : ; do
277
420
  case "$1" in
278
421
  run)
@@ -283,6 +426,7 @@ while : ; do
283
426
  runnable=$(echo -n "exec")
284
427
 
285
428
  if [ -f $(_p "${APP_HOME}/vendor/pkgr/processes/${COMMAND}") ]; then
429
+ export PORT=$(process_port "$COMMAND" "$APP_PROCESS_INDEX")
286
430
  # Command alias defined in Procfile
287
431
  runnable="${runnable}$(printf " %q" $(_p "${APP_HOME}/vendor/pkgr/processes/${COMMAND}") "$@")"
288
432
  else
@@ -294,9 +438,6 @@ while : ; do
294
438
  runnable="${runnable}$(printf " %q" ${COMMAND} "$@")"
295
439
  fi
296
440
 
297
- # fix port
298
- export PORT=$PORT_WAS
299
-
300
441
  # Do not use su, to avoid creating a new process. Note: chroot version
301
442
  # is too old on Ubuntu Lucid, so this will fail. It works on Debian
302
443
  # Squeeze though (and later).
@@ -325,12 +466,18 @@ while : ; do
325
466
  done
326
467
  break ;;
327
468
 
469
+ restart)
470
+ shift
471
+ control_process "restart" "$@"
472
+ break;;
473
+
328
474
  logs)
329
475
  shift
330
- if [ "$1" = "--tail" ]; then
476
+ if [ "$1" == "--tail" -o "$1" == "-f" ]; then
477
+ shift
331
478
  tail_logs
332
479
  else
333
- logs ${@}
480
+ logs "${@}"
334
481
  fi
335
482
  break;;
336
483
 
@@ -338,21 +485,14 @@ while : ; do
338
485
  show_env
339
486
  break;;
340
487
 
341
- config:set)
488
+ config:unset)
342
489
  [ $# -lt 2 ] && usage
490
+ config_unset "$2"
491
+ break;;
343
492
 
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}"
355
-
493
+ config:set)
494
+ [ $# -lt 2 ] && usage
495
+ config_set "$2"
356
496
  break;;
357
497
 
358
498
  config:get)
@@ -362,14 +502,16 @@ while : ; do
362
502
 
363
503
  configure)
364
504
  ensure_root
505
+ shift
365
506
 
366
- configure $@
507
+ configure "$@"
367
508
  break;;
368
509
 
369
510
  reconfigure)
370
511
  ensure_root
512
+ shift
371
513
 
372
- reconfigure $@
514
+ reconfigure "$@"
373
515
  break;;
374
516
 
375
517
  *)