├── .gitignore ├── CHANGES.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── index.js ├── package.json ├── systemd.service.jst └── test ├── common.js ├── fixtures └── strong-pm.service ├── test-async.js ├── test-date.js ├── test-env.js └── test-simple.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.tgz 3 | .nyc_output 4 | coverage 5 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | 2016-05-06, Version 1.2.3 2 | ========================= 3 | 4 | * update copyright notices and license (Ryan Graham) 5 | 6 | 7 | 2016-04-11, Version 1.2.2 8 | ========================= 9 | 10 | * Refer to licenses with a link (Sam Roberts) 11 | 12 | 13 | 2015-10-01, Version 1.2.1 14 | ========================= 15 | 16 | * Use strongloop conventions for licensing (Sam Roberts) 17 | 18 | * test: generate cobertura coverage reports (Ryan Graham) 19 | 20 | * test: upgrade to tap@1 (Ryan Graham) 21 | 22 | 23 | 2015-05-28, Version 1.2.0 24 | ========================= 25 | 26 | * deps: upgrad lodash to lodash@3 (Ryan Graham) 27 | 28 | 29 | 2015-03-12, Version 1.1.0 30 | ========================= 31 | 32 | * Remove After/Wants options and allow service to be enabled/disabled. (braincomb) 33 | 34 | * test: use official tap (Ryan Graham) 35 | 36 | 37 | 2015-01-12, Version 1.0.1 38 | ========================= 39 | 40 | * Fix bad CLA URL in CONTRIBUTING.md (Ryan Graham) 41 | 42 | 43 | 2014-11-07, Version 1.0.0 44 | ========================= 45 | 46 | * First release! 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ### Contributing ### 2 | 3 | Thank you for your interest in `strong-service-systemd`, an open source project 4 | administered by StrongLoop. 5 | 6 | Contributing to `strong-service-systemd` is easy. In a few simple steps: 7 | 8 | * Ensure that your effort is aligned with the project's roadmap by 9 | talking to the maintainers, especially if you are going to spend a 10 | lot of time on it. 11 | 12 | * Make something better or fix a bug. 13 | 14 | * Adhere to code style outlined in the [Google C++ Style Guide][] and 15 | [Google Javascript Style Guide][]. 16 | 17 | * Sign the [Contributor License Agreement](https://cla.strongloop.com/agreements/strongloop/strong-service-systemd) 18 | 19 | * Submit a pull request through Github. 20 | 21 | 22 | ### Contributor License Agreement ### 23 | 24 | ``` 25 | Individual Contributor License Agreement 26 | 27 | By signing this Individual Contributor License Agreement 28 | ("Agreement"), and making a Contribution (as defined below) to 29 | StrongLoop, Inc. ("StrongLoop"), You (as defined below) accept and 30 | agree to the following terms and conditions for Your present and 31 | future Contributions submitted to StrongLoop. Except for the license 32 | granted in this Agreement to StrongLoop and recipients of software 33 | distributed by StrongLoop, You reserve all right, title, and interest 34 | in and to Your Contributions. 35 | 36 | 1. Definitions 37 | 38 | "You" or "Your" shall mean the copyright owner or the individual 39 | authorized by the copyright owner that is entering into this 40 | Agreement with StrongLoop. 41 | 42 | "Contribution" shall mean any original work of authorship, 43 | including any modifications or additions to an existing work, that 44 | is intentionally submitted by You to StrongLoop for inclusion in, 45 | or documentation of, any of the products owned or managed by 46 | StrongLoop ("Work"). For purposes of this definition, "submitted" 47 | means any form of electronic, verbal, or written communication 48 | sent to StrongLoop or its representatives, including but not 49 | limited to communication or electronic mailing lists, source code 50 | control systems, and issue tracking systems that are managed by, 51 | or on behalf of, StrongLoop for the purpose of discussing and 52 | improving the Work, but excluding communication that is 53 | conspicuously marked or otherwise designated in writing by You as 54 | "Not a Contribution." 55 | 56 | 2. You Grant a Copyright License to StrongLoop 57 | 58 | Subject to the terms and conditions of this Agreement, You hereby 59 | grant to StrongLoop and recipients of software distributed by 60 | StrongLoop, a perpetual, worldwide, non-exclusive, no-charge, 61 | royalty-free, irrevocable copyright license to reproduce, prepare 62 | derivative works of, publicly display, publicly perform, 63 | sublicense, and distribute Your Contributions and such derivative 64 | works under any license and without any restrictions. 65 | 66 | 3. You Grant a Patent License to StrongLoop 67 | 68 | Subject to the terms and conditions of this Agreement, You hereby 69 | grant to StrongLoop and to recipients of software distributed by 70 | StrongLoop a perpetual, worldwide, non-exclusive, no-charge, 71 | royalty-free, irrevocable (except as stated in this Section) 72 | patent license to make, have made, use, offer to sell, sell, 73 | import, and otherwise transfer the Work under any license and 74 | without any restrictions. The patent license You grant to 75 | StrongLoop under this Section applies only to those patent claims 76 | licensable by You that are necessarily infringed by Your 77 | Contributions(s) alone or by combination of Your Contributions(s) 78 | with the Work to which such Contribution(s) was submitted. If any 79 | entity institutes a patent litigation against You or any other 80 | entity (including a cross-claim or counterclaim in a lawsuit) 81 | alleging that Your Contribution, or the Work to which You have 82 | contributed, constitutes direct or contributory patent 83 | infringement, any patent licenses granted to that entity under 84 | this Agreement for that Contribution or Work shall terminate as 85 | of the date such litigation is filed. 86 | 87 | 4. You Have the Right to Grant Licenses to StrongLoop 88 | 89 | You represent that You are legally entitled to grant the licenses 90 | in this Agreement. 91 | 92 | If Your employer(s) has rights to intellectual property that You 93 | create, You represent that You have received permission to make 94 | the Contributions on behalf of that employer, that Your employer 95 | has waived such rights for Your Contributions, or that Your 96 | employer has executed a separate Corporate Contributor License 97 | Agreement with StrongLoop. 98 | 99 | 5. The Contributions Are Your Original Work 100 | 101 | You represent that each of Your Contributions are Your original 102 | works of authorship (see Section 8 (Submissions on Behalf of 103 | Others) for submission on behalf of others). You represent that to 104 | Your knowledge, no other person claims, or has the right to claim, 105 | any right in any intellectual property right related to Your 106 | Contributions. 107 | 108 | You also represent that You are not legally obligated, whether by 109 | entering into an agreement or otherwise, in any way that conflicts 110 | with the terms of this Agreement. 111 | 112 | You represent that Your Contribution submissions include complete 113 | details of any third-party license or other restriction (including, 114 | but not limited to, related patents and trademarks) of which You 115 | are personally aware and which are associated with any part of 116 | Your Contributions. 117 | 118 | 6. You Don't Have an Obligation to Provide Support for Your Contributions 119 | 120 | You are not expected to provide support for Your Contributions, 121 | except to the extent You desire to provide support. You may provide 122 | support for free, for a fee, or not at all. 123 | 124 | 6. No Warranties or Conditions 125 | 126 | StrongLoop acknowledges that unless required by applicable law or 127 | agreed to in writing, You provide Your Contributions on an "AS IS" 128 | BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER 129 | EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES 130 | OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, OR 131 | FITNESS FOR A PARTICULAR PURPOSE. 132 | 133 | 7. Submission on Behalf of Others 134 | 135 | If You wish to submit work that is not Your original creation, You 136 | may submit it to StrongLoop separately from any Contribution, 137 | identifying the complete details of its source and of any license 138 | or other restriction (including, but not limited to, related 139 | patents, trademarks, and license agreements) of which You are 140 | personally aware, and conspicuously marking the work as 141 | "Submitted on Behalf of a Third-Party: [named here]". 142 | 143 | 8. Agree to Notify of Change of Circumstances 144 | 145 | You agree to notify StrongLoop of any facts or circumstances of 146 | which You become aware that would make these representations 147 | inaccurate in any respect. Email us at callback@strongloop.com. 148 | ``` 149 | 150 | [Google C++ Style Guide]: https://google.github.io/styleguide/cppguide.html 151 | [Google Javascript Style Guide]: https://google.github.io/styleguide/javascriptguide.xml 152 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) IBM Corp. 2014,2016. All Rights Reserved. 2 | Node module: strong-service-systemd 3 | This project is licensed under the Artistic License 2.0, full text below. 4 | 5 | -------- 6 | 7 | The Artistic License 2.0 8 | 9 | Copyright (c) 2000-2006, The Perl Foundation. 10 | 11 | Everyone is permitted to copy and distribute verbatim copies 12 | of this license document, but changing it is not allowed. 13 | 14 | Preamble 15 | 16 | This license establishes the terms under which a given free software 17 | Package may be copied, modified, distributed, and/or redistributed. 18 | The intent is that the Copyright Holder maintains some artistic 19 | control over the development of that Package while still keeping the 20 | Package available as open source and free software. 21 | 22 | You are always permitted to make arrangements wholly outside of this 23 | license directly with the Copyright Holder of a given Package. If the 24 | terms of this license do not permit the full use that you propose to 25 | make of the Package, you should contact the Copyright Holder and seek 26 | a different licensing arrangement. 27 | 28 | Definitions 29 | 30 | "Copyright Holder" means the individual(s) or organization(s) 31 | named in the copyright notice for the entire Package. 32 | 33 | "Contributor" means any party that has contributed code or other 34 | material to the Package, in accordance with the Copyright Holder's 35 | procedures. 36 | 37 | "You" and "your" means any person who would like to copy, 38 | distribute, or modify the Package. 39 | 40 | "Package" means the collection of files distributed by the 41 | Copyright Holder, and derivatives of that collection and/or of 42 | those files. A given Package may consist of either the Standard 43 | Version, or a Modified Version. 44 | 45 | "Distribute" means providing a copy of the Package or making it 46 | accessible to anyone else, or in the case of a company or 47 | organization, to others outside of your company or organization. 48 | 49 | "Distributor Fee" means any fee that you charge for Distributing 50 | this Package or providing support for this Package to another 51 | party. It does not mean licensing fees. 52 | 53 | "Standard Version" refers to the Package if it has not been 54 | modified, or has been modified only in ways explicitly requested 55 | by the Copyright Holder. 56 | 57 | "Modified Version" means the Package, if it has been changed, and 58 | such changes were not explicitly requested by the Copyright 59 | Holder. 60 | 61 | "Original License" means this Artistic License as Distributed with 62 | the Standard Version of the Package, in its current version or as 63 | it may be modified by The Perl Foundation in the future. 64 | 65 | "Source" form means the source code, documentation source, and 66 | configuration files for the Package. 67 | 68 | "Compiled" form means the compiled bytecode, object code, binary, 69 | or any other form resulting from mechanical transformation or 70 | translation of the Source form. 71 | 72 | 73 | Permission for Use and Modification Without Distribution 74 | 75 | (1) You are permitted to use the Standard Version and create and use 76 | Modified Versions for any purpose without restriction, provided that 77 | you do not Distribute the Modified Version. 78 | 79 | 80 | Permissions for Redistribution of the Standard Version 81 | 82 | (2) You may Distribute verbatim copies of the Source form of the 83 | Standard Version of this Package in any medium without restriction, 84 | either gratis or for a Distributor Fee, provided that you duplicate 85 | all of the original copyright notices and associated disclaimers. At 86 | your discretion, such verbatim copies may or may not include a 87 | Compiled form of the Package. 88 | 89 | (3) You may apply any bug fixes, portability changes, and other 90 | modifications made available from the Copyright Holder. The resulting 91 | Package will still be considered the Standard Version, and as such 92 | will be subject to the Original License. 93 | 94 | 95 | Distribution of Modified Versions of the Package as Source 96 | 97 | (4) You may Distribute your Modified Version as Source (either gratis 98 | or for a Distributor Fee, and with or without a Compiled form of the 99 | Modified Version) provided that you clearly document how it differs 100 | from the Standard Version, including, but not limited to, documenting 101 | any non-standard features, executables, or modules, and provided that 102 | you do at least ONE of the following: 103 | 104 | (a) make the Modified Version available to the Copyright Holder 105 | of the Standard Version, under the Original License, so that the 106 | Copyright Holder may include your modifications in the Standard 107 | Version. 108 | 109 | (b) ensure that installation of your Modified Version does not 110 | prevent the user installing or running the Standard Version. In 111 | addition, the Modified Version must bear a name that is different 112 | from the name of the Standard Version. 113 | 114 | (c) allow anyone who receives a copy of the Modified Version to 115 | make the Source form of the Modified Version available to others 116 | under 117 | 118 | (i) the Original License or 119 | 120 | (ii) a license that permits the licensee to freely copy, 121 | modify and redistribute the Modified Version using the same 122 | licensing terms that apply to the copy that the licensee 123 | received, and requires that the Source form of the Modified 124 | Version, and of any works derived from it, be made freely 125 | available in that license fees are prohibited but Distributor 126 | Fees are allowed. 127 | 128 | 129 | Distribution of Compiled Forms of the Standard Version 130 | or Modified Versions without the Source 131 | 132 | (5) You may Distribute Compiled forms of the Standard Version without 133 | the Source, provided that you include complete instructions on how to 134 | get the Source of the Standard Version. Such instructions must be 135 | valid at the time of your distribution. If these instructions, at any 136 | time while you are carrying out such distribution, become invalid, you 137 | must provide new instructions on demand or cease further distribution. 138 | If you provide valid instructions or cease distribution within thirty 139 | days after you become aware that the instructions are invalid, then 140 | you do not forfeit any of your rights under this license. 141 | 142 | (6) You may Distribute a Modified Version in Compiled form without 143 | the Source, provided that you comply with Section 4 with respect to 144 | the Source of the Modified Version. 145 | 146 | 147 | Aggregating or Linking the Package 148 | 149 | (7) You may aggregate the Package (either the Standard Version or 150 | Modified Version) with other packages and Distribute the resulting 151 | aggregation provided that you do not charge a licensing fee for the 152 | Package. Distributor Fees are permitted, and licensing fees for other 153 | components in the aggregation are permitted. The terms of this license 154 | apply to the use and Distribution of the Standard or Modified Versions 155 | as included in the aggregation. 156 | 157 | (8) You are permitted to link Modified and Standard Versions with 158 | other works, to embed the Package in a larger work of your own, or to 159 | build stand-alone binary or bytecode versions of applications that 160 | include the Package, and Distribute the result without restriction, 161 | provided the result does not expose a direct interface to the Package. 162 | 163 | 164 | Items That are Not Considered Part of a Modified Version 165 | 166 | (9) Works (including, but not limited to, modules and scripts) that 167 | merely extend or make use of the Package, do not, by themselves, cause 168 | the Package to be a Modified Version. In addition, such works are not 169 | considered parts of the Package itself, and are not subject to the 170 | terms of this license. 171 | 172 | 173 | General Provisions 174 | 175 | (10) Any use, modification, and distribution of the Standard or 176 | Modified Versions is governed by this Artistic License. By using, 177 | modifying or distributing the Package, you accept this license. Do not 178 | use, modify, or distribute the Package, if you do not accept this 179 | license. 180 | 181 | (11) If your Modified Version has been derived from a Modified 182 | Version made by someone other than you, you are nevertheless required 183 | to ensure that your Modified Version complies with the requirements of 184 | this license. 185 | 186 | (12) This license does not grant you the right to use any trademark, 187 | service mark, tradename, or logo of the Copyright Holder. 188 | 189 | (13) This license includes the non-exclusive, worldwide, 190 | free-of-charge patent license to make, have made, use, offer to sell, 191 | sell, import and otherwise transfer the Package with respect to any 192 | patent claims licensable by the Copyright Holder that are necessarily 193 | infringed by the Package. If you institute patent litigation 194 | (including a cross-claim or counterclaim) against any party alleging 195 | that the Package constitutes direct or contributory patent 196 | infringement, then this Artistic License to you shall terminate on the 197 | date that such litigation is filed. 198 | 199 | (14) Disclaimer of Warranty: 200 | THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS 201 | IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED 202 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR 203 | NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL 204 | LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL 205 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 206 | DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF 207 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 208 | 209 | 210 | -------- 211 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # strong-service-systemd 2 | 3 | Generate an systemd service using the provided parameters. 4 | 5 | ## Install 6 | 7 | `npm install strong-service-systemd` 8 | 9 | ## Basic Usage 10 | 11 | ```js 12 | var fs = require('fs'); 13 | var systemd = require('strong-service-systemd'); 14 | 15 | // Generate systemd service for my-app 16 | systemd({name: 'my-app'}, function(err, service) { 17 | fs.writeFile('/etc/systemd/system/my-app.service', service, function(err) { 18 | if (err) return console.error(err); 19 | }); 20 | }); 21 | 22 | // Also supports synchronous mode 23 | fs.writeFileSync('/etc/systemd/system/my-app.service', systemd({name: 'my-app'})); 24 | ``` 25 | 26 | ## Options 27 | 28 | This module supports a subset of those used in the node-linux templates: 29 | 30 | * `name` - name of service. 31 | `name` is an alias for `label` and `servicesummary`. 32 | * `description` - multi-word description of service. `description` is an 33 | alias for `servicedescription`. 34 | * `author` - sets author field of systemd job (defaults to current user) 35 | * `cwd` - working directory to run service from (defaults to `/`) 36 | * `user` - user to run service as (defaults to `nodbody`) 37 | * `group` - group to run service as (defaults to `nogroup`) 38 | * `execpath` - path to binary to executable 39 | * `script` - arguments to execpath (such as a script) 40 | * `created` - timestamp used in generated job (defaults to current time) 41 | * `env` - environment variables to set in systemd job 42 | * `template` - override internal template 43 | 44 | ## Template Format 45 | 46 | Templates use [_.template](http://lodash.com/docs#template) from Lodash using 47 | EJS style syntax: `<%= option %>`. 48 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2014,2015. All Rights Reserved. 2 | // Node module: strong-service-systemd 3 | // This file is licensed under the Artistic License 2.0. 4 | // License text available at https://opensource.org/licenses/Artistic-2.0 5 | 6 | var fs = require('fs'); 7 | var _ = require('lodash'); 8 | var env = process.env; 9 | 10 | // In the interest of reusability, these options are the same as in node-linux 11 | // https://github.com/coreybutler/node-linux/blob/ef307b/lib/systemv.js#L99-L152 12 | 13 | var DEFAULTS = { 14 | label: 'node-app', 15 | servicesummary: 'node-app', 16 | servicedescription: 'A node app', 17 | author: env.LOGNAME || env.USER || env.LNAME || env.USERNAME || 'Unknown', 18 | script: __filename, 19 | user: 'nobody', 20 | group: 'nogroup', 21 | pidroot: '/var/run', 22 | logroot: '/var/log', 23 | created: new Date(), 24 | execpath: process.execPath, 25 | cwd: '/', 26 | env: {}, 27 | } 28 | 29 | module.exports = renderSystemdService; 30 | 31 | function renderSystemdService(opts, cb) { 32 | opts = ensureOptions(opts); 33 | if (typeof cb === 'function') { 34 | return asyncRenderSystemdService(opts, cb); 35 | } else { 36 | return syncRenderSystemdService(opts); 37 | } 38 | } 39 | 40 | function syncRenderSystemdService(opts) { 41 | var jst = fs.readFileSync(opts.template, 'utf8'); 42 | return _.template(jst)(opts); 43 | } 44 | 45 | function asyncRenderSystemdService(opts, cb) { 46 | fs.readFile(opts.template, 'utf8', function(err, jst) { 47 | var job = err ? null : _.template(jst)(opts); 48 | return cb(err, job); 49 | }); 50 | } 51 | 52 | function ensureOptions(input) { 53 | var opts = handleOptionAliases(input); 54 | opts = _.extend({}, DEFAULTS, opts); 55 | if (!opts.template) 56 | opts.template = require.resolve('./systemd.service.jst'); 57 | opts = flattenOptions(opts); 58 | return opts; 59 | } 60 | 61 | function handleOptionAliases(input) { 62 | var opts = _.extend({}, input); 63 | if (opts.name) { 64 | opts.label = opts.servicesummary = opts.name; 65 | } 66 | if (opts.user && !opts.group) { 67 | opts.group = opts.user; 68 | } 69 | if (opts.description) { 70 | opts.servicedescription = opts.description; 71 | } 72 | return opts; 73 | } 74 | 75 | function flattenOptions(opts) { 76 | opts = _.cloneDeep(opts); 77 | // env rendering assumgs an array of k/v pairs: [[k1,v1],[k2,v2],...] 78 | if (!Array.isArray(opts.env)) { 79 | opts.env = _.pairs(opts.env); 80 | } 81 | if (opts.created instanceof Date) { 82 | opts.created = opts.created.toJSON(); 83 | } 84 | return opts; 85 | } 86 | 87 | if (require.main === module) { 88 | var opts = require('minimist')(process.argv.slice(2)); 89 | if (opts.help) { 90 | console.log('Usage: %s [options]\n', process.title); 91 | console.log('Options (and defaults)'); 92 | var max = _.max(Object.keys(DEFAULTS), 'length'); 93 | var pad = max.replace(/./g, ' '); 94 | _.forEach(DEFAULTS, function(def, opt) { 95 | opt = opt + pad; 96 | console.log(' --%s %s', 97 | opt.slice(0, max.length), 98 | def); 99 | }); 100 | } else { 101 | process.stdout.write(renderSystemdService(opts)); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "strong-service-systemd", 3 | "version": "1.2.3", 4 | "description": "Generate an systemd job using the provided parameters.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "tap --coverage --coverage-report=cobertura test/test-*" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/strongloop/strong-service-systemd.git" 12 | }, 13 | "keywords": [ 14 | "systemd" 15 | ], 16 | "author": "Ryan Graham ", 17 | "license": "Artistic-2.0", 18 | "bugs": { 19 | "url": "https://github.com/strongloop/strong-service-systemd/issues" 20 | }, 21 | "homepage": "https://github.com/strongloop/strong-service-systemd", 22 | "dependencies": { 23 | "lodash": "^3.9.3", 24 | "minimist": "^0.2.0" 25 | }, 26 | "devDependencies": { 27 | "tap": "^1.3.2" 28 | }, 29 | "directories": { 30 | "test": "test" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /systemd.service.jst: -------------------------------------------------------------------------------- 1 | # <%= label %> 2 | # Generated by strong-service-systemd on <%= created %> 3 | 4 | [Unit] 5 | Description=<%= servicedescription %> 6 | 7 | # To start/stop <%= label %> service manually, run: 8 | # 9 | # systemctl start <%= label %> 10 | # systemctl stop <%= label %> 11 | 12 | [Service] 13 | Type=simple 14 | ExecStart=<%= execpath %> <%= script %> 15 | <% if (cwd) { %>WorkingDirectory=<%= cwd %><% } else { %># No working directory specifed<% } %> 16 | 17 | User=<%= user %> 18 | Group=<%= group %> 19 | 20 | # Environment variables: 21 | <% if (env && env.length > 0) { 22 | _.forEach(env, function(pair) { 23 | %>Environment=<%- pair[0] %>=<%- pair[1] %> 24 | <%}) } else { 25 | %># no environment variables set<% 26 | } %> 27 | 28 | # Allow many incoming connections 29 | LimitNOFILE=infinity 30 | # Allow core dumps for debugging 31 | LimitCORE=infinity 32 | 33 | StandardInput=null 34 | StandardOutput=syslog 35 | StandardError=syslog 36 | Restart=always 37 | 38 | [Install] 39 | WantedBy=multi-user.target 40 | -------------------------------------------------------------------------------- /test/common.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2014. All Rights Reserved. 2 | // Node module: strong-service-systemd 3 | // This file is licensed under the Artistic License 2.0. 4 | // License text available at https://opensource.org/licenses/Artistic-2.0 5 | 6 | var fs = require('fs'); 7 | 8 | module.exports = { 9 | fixture: readFixture 10 | } 11 | 12 | function readFixture(name) { 13 | var path = require.resolve('./fixtures/' + name); 14 | return fs.readFileSync(path, 'utf8'); 15 | } 16 | -------------------------------------------------------------------------------- /test/fixtures/strong-pm.service: -------------------------------------------------------------------------------- 1 | # strong-pm 2 | # Generated by strong-service-systemd on 2014-08-22T00:00:00.000Z 3 | 4 | [Unit] 5 | Description=Node application server 6 | 7 | # To start/stop strong-pm service manually, run: 8 | # 9 | # systemctl start strong-pm 10 | # systemctl stop strong-pm 11 | 12 | [Service] 13 | Type=simple 14 | ExecStart=/custom/path/to/node /custom/path/to/my/script.js 15 | WorkingDirectory=/ 16 | 17 | User=nobody 18 | Group=nogroup 19 | 20 | # Environment variables: 21 | # no environment variables set 22 | 23 | # Allow many incoming connections 24 | LimitNOFILE=infinity 25 | # Allow core dumps for debugging 26 | LimitCORE=infinity 27 | 28 | StandardInput=null 29 | StandardOutput=syslog 30 | StandardError=syslog 31 | Restart=always 32 | 33 | [Install] 34 | WantedBy=multi-user.target 35 | -------------------------------------------------------------------------------- /test/test-async.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2014,2015. All Rights Reserved. 2 | // Node module: strong-service-systemd 3 | // This file is licensed under the Artistic License 2.0. 4 | // License text available at https://opensource.org/licenses/Artistic-2.0 5 | 6 | var common = require('./common'); 7 | var render = require('../'); 8 | var tap = require('tap'); 9 | 10 | var expected = common.fixture('strong-pm.service'); 11 | var options = { 12 | name: 'strong-pm', 13 | author: 'Current User', 14 | description: 'Node application server', 15 | execpath: '/custom/path/to/node', 16 | script: '/custom/path/to/my/script.js', 17 | created: '2014-08-22T00:00:00.000Z', 18 | }; 19 | 20 | tap.test('async mode', function(t) { 21 | render(options, function(err, job) { 22 | t.ifError(err, 'should not error'); 23 | t.equal(job, expected, 'renders correctly'); 24 | t.end(); 25 | }); 26 | }); 27 | 28 | -------------------------------------------------------------------------------- /test/test-date.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2014,2015. All Rights Reserved. 2 | // Node module: strong-service-systemd 3 | // This file is licensed under the Artistic License 2.0. 4 | // License text available at https://opensource.org/licenses/Artistic-2.0 5 | 6 | var common = require('./common'); 7 | var render = require('../'); 8 | var tap = require('tap'); 9 | 10 | var options = { 11 | name: 'strong-pm', 12 | author: 'Current User', 13 | description: 'Node application server', 14 | execpath: '/custom/path/to/node', 15 | script: '/custom/path/to/my/script.js', 16 | created: new Date(Date.UTC(2014, 7, 22)), 17 | }; 18 | 19 | var expected = common.fixture('strong-pm.service'); 20 | 21 | tap.test('sync mode', function(t) { 22 | var result = render(options); 23 | t.equal(result, expected, 'should render correctly in sync mode'); 24 | t.end(); 25 | }); 26 | -------------------------------------------------------------------------------- /test/test-env.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2014,2015. All Rights Reserved. 2 | // Node module: strong-service-systemd 3 | // This file is licensed under the Artistic License 2.0. 4 | // License text available at https://opensource.org/licenses/Artistic-2.0 5 | 6 | var render = require('../'); 7 | var tap = require('tap'); 8 | 9 | var options = { 10 | name: 'strong-pm', 11 | author: 'Current User', 12 | description: 'Node application server', 13 | execpath: '/custom/path/to/node', 14 | script: '/custom/path/to/my/script.js', 15 | created: '2014-08-22T00:00:00.000Z', 16 | env: { 17 | FOO: 'foo', 18 | BAR: 'bar', 19 | }, 20 | }; 21 | 22 | var ENV_FOO = /^Environment=FOO=foo$/m; 23 | var ENV_BAR = /^Environment=BAR=bar$/m; 24 | 25 | var result = render(options); 26 | 27 | tap.test('environment options', function(t) { 28 | t.match(result, ENV_FOO, 'should contain env var'); 29 | t.match(result, ENV_BAR, 'should contain env var'); 30 | t.end(); 31 | }); 32 | -------------------------------------------------------------------------------- /test/test-simple.js: -------------------------------------------------------------------------------- 1 | // Copyright IBM Corp. 2014,2015. All Rights Reserved. 2 | // Node module: strong-service-systemd 3 | // This file is licensed under the Artistic License 2.0. 4 | // License text available at https://opensource.org/licenses/Artistic-2.0 5 | 6 | var common = require('./common'); 7 | var render = require('../'); 8 | var tap = require('tap'); 9 | 10 | var options = { 11 | name: 'strong-pm', 12 | author: 'Current User', 13 | description: 'Node application server', 14 | execpath: '/custom/path/to/node', 15 | script: '/custom/path/to/my/script.js', 16 | created: '2014-08-22T00:00:00.000Z', 17 | }; 18 | 19 | var expected = common.fixture('strong-pm.service'); 20 | 21 | tap.test('simple render', function(t) { 22 | var result = render(options); 23 | t.equal(result, expected, 'should render correctly'); 24 | t.end(); 25 | }); 26 | --------------------------------------------------------------------------------