Skip to content

Commit

Permalink
Support for script command line parameters (scriptOptions)
Browse files Browse the repository at this point in the history
  • Loading branch information
arvind-agarwal committed Dec 24, 2014
1 parent 1014402 commit c293937
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ forever-service version 0.x.x
-h, --help output usage information
-s, --script [script] Script to run as service e.g. app.js, defaults to app.js
-o --scriptOptions [options] Command line options for the script
--minUptime [value] Minimum uptime (millis) for a script to not be considered "spinning", default 5000
--spinSleepTime [value] Time to wait (millis) between launches of a spinning script., default 2000
Expand Down Expand Up @@ -141,7 +143,16 @@ $ sudo forever-service install test --script main.js
* Custom options for forever

```
$ sudo forever-service install test -f " -watchDirectory /your/watch/directoyr -w"
$ sudo forever-service install test -f " -watchDirectory /your/watch/directory -w"
```




* Command line parameters for the script

```
$ sudo forever-service install test --script main.js -o " param1 param2"
```


Expand All @@ -154,6 +165,14 @@ $ sudo forever-service delete test
This command will stop service if running, clean up all provisioned files and service




* Get list of running services (Remember all forever command line options are available since we use forever internally)
```
$ sudo forever list
```


Known Issue(s)
--------------
"restart service" command works like stop in Ubuntu due to bug in upstart https://bugs.launchpad.net/upstart/+bug/703800
Expand Down
4 changes: 4 additions & 0 deletions bin/forever-service
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ platforms.get(function(err, platform){
.command('install [service]')
.option('-s, --script [script]','Script to run as service e.g. app.js, defaults to app.js')
.option('','')
.option('-o --scriptOptions [options]','Command line options for the script')
.option('','')
.option('--minUptime [value]','Minimum uptime (millis) for a script to not be considered "spinning", default 5000')
.option('','')
.option('--spinSleepTime [value]','Time to wait (millis) between launches of a spinning script., default 2000')
Expand Down Expand Up @@ -69,6 +71,8 @@ platforms.get(function(err, platform){
else
ctx.script = 'app.js';


if(options.scriptOptions) ctx.scriptOptions = options.scriptOptions;
if(options.minUptime) ctx.minUptime = options.minUptime;
if(options.spinSleepTime) ctx.spinSleepTime = options.spinSleepTime;
if(options.noGracefulShutdown) ctx.killSignal = 'SIGKILL'; //Default is SIGTERM so non graceful shutdown makes it SIGKILL
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "forever-service",
"version": "0.4.1",
"version": "0.4.2",
"preferGlobal": "true",
"description": "Provision node script as a service via forever, allowing it to automatically start on boot, working across various Linux distros and OS",
"main": "lib/api.js",
Expand Down
2 changes: 1 addition & 1 deletion templates/sysvinit/initd.template
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ start() {
--killSignal $KILL_SIGNAL \
{{foreverOptions|default('')}} \
--uid {{service}} \
start {{script|default('app.js')}} 2>&1 >/dev/null
start {{script|default('app.js')}} {{scriptOptions|default('')}} 2>&1 >/dev/null
RETVAL=$?

[ $RETVAL = 0 ] && touch $LOCKFILE
Expand Down
2 changes: 1 addition & 1 deletion templates/upstart/upstart.template
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ env KILLWAITTIME={{forceKillWaitTime|default('5000')}}

chdir {{cwd}}

exec {{foreverPath}}forever -a -l $LOGFILE --minUptime $MIN_UPTIME --spinSleepTime $SPIN_SLEEP_TIME --killSignal $KILL_SIGNAL {{foreverOptions|default('')}} --uid {{service}} start {{script|default('app.js')}}
exec {{foreverPath}}forever -a -l $LOGFILE --minUptime $MIN_UPTIME --spinSleepTime $SPIN_SLEEP_TIME --killSignal $KILL_SIGNAL {{foreverOptions|default('')}} --uid {{service}} start {{script|default('app.js')}} {{scriptOptions|default('')}}

post-start script
echo "{{service}} started"
Expand Down

0 comments on commit c293937

Please sign in to comment.