npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

forever-service

v0.5.11

Published

Provision node script as a service via forever, allowing it to automatically start on boot, working across various Linux distros and OS

Downloads

1,303

Readme

forever-service

Make provisioning node script as a service simple.

We love nodejs for server development. But, It is surprising to find that there is no standard tool to provision script as a service. Forever kind of tools comes close but they only demonize the process and not provision as service; which can be automatically started on reboots. To make matter worse, each OS and Linux distro has its own unique way of provisioning the services correctly.

Goals

  1. Make an universal service installer across various Linux distros and other OS.
  2. Automatically configure other useful things such as Logrotation scripts, port monitoring scripts etc.
  3. Graceful shutdown of services as default behaviour.

Platforms supported

  • Amazon Linux
  • Redhat Linux
  • CentOS
  • Ubuntu (upstart, sysv fallback for >= 15.04, no systemd support)
  • Debian
  • Raspbian
  • OSMC Linux
  • Fedora 21
  • Oracle Linux
  • Elementary OS
  • BunsenLabs
  • more to come..

Prerequisite

forever must be installed globally using

npm install -g forever

Install

npm install -g forever-service

Usage

$ forever-service --help

forever-service version 0.x.x


  Usage: forever-service [options] [command]

  Commands:

    install [options] [service]
       Install node script (defaults to app.js in current directory) as service via forever
    
    
    
    delete [service]
       Delete all provisioned files for the service, will stop service if running before delete
    

  Options:

    -h, --help     output usage information
    -V, --version  output the version number

Install new service

$ forever-service install --help

forever-service version 0.x.x


  Usage: install [options] [service]

  Options:

    -h, --help                         output usage information
    -s, --script [script]              Script to run as service e.g. app.js, defaults to app.js

    -e --envVars [vars]                Environment Variables for the script
                                       e.g. -e "PORT=80 ENV=prod FOO=bar"

    -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
                                       
    --noGracefulShutdown               Disable graceful shutdown
                                       
    -t --forceKillWaitTime [waittime]  Time to wait in milliseconds before force killing; after failed graceful stop
                                       defaults to 5000 ms, after which entire process tree is forcibly terminated
                                       
    -f --foreverOptions " [options]"   Extra command line options for forever
                                       e.g. -f " --watchDirectory /your/watch/directory -w -c /custom/cli" etc..
                                       NOTE: a mandatory space is required after double quotes, if begining with -
                                       
    --start                            Start service after provisioning
                                       
    --nologrotate                      Do not generate logrotate script
                                       
    --logrotateFrequency [frequency]   Frequency of logrotation
                                       valid values are daily, weekly, monthly, "size 100k" etc, default daily
                                       
    --logrotateMax [value]             Maximum logrotated files to retain, default 10 (logrotate parameter)
                                       
    --logrotateDateExt                 Archive old versions of log files adding a daily extension like YYYYMMDD instead of simply adding a number

    --logrotateCompress                Enable compression for logrotate

    -p --foreverPath                   Path for forever cli e.g. /usr/local/bin,
                                       by default forever cli is searched in system Path variable

    -u --applyUlimits                  Apply increased ulimits in supported environment

    -r --runAsUser [user]              *Experimental* Run service as a specific user, defaults to root (No ubuntu support yet)

Delete service

$ forever-service delete --help

forever-service version 0.x.x


  Usage: delete [options] [service]

  Options:

    -h, --help  output usage information

Examples

  • Provision a service 'test' with app.js script in current directory
$ sudo forever-service install test

On Amazon Linux, This command will setup initd script and provision service using chkconfig, Create logrotate scripts

  • Provision a service 'test' with main.js script in current directory
$ sudo forever-service install test --script main.js
  • Custom options for forever
$ 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"
  • Delete service
$ 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

Run non nodejs scripts as service

forever allows to use -c command line parameter to point to alternate command line for execution, using that one can easily launch non-node apps also as service

  • Run Java Program as service
$ sudo forever-service install javaservice1 -s start.jar -f " -c 'java -Xms1024m -Xmx1024m -jar'"

This command will run start.jar using java command line

  • Run PHP Program as service
$ sudo forever-service install phpservice1 -s info.php -f " -c php"

This command will run info.php using php command line

Known Issue(s)

"restart service" command works like stop in Ubuntu due to bug in upstart https://bugs.launchpad.net/upstart/+bug/703800

Roadmap

Support other Linux distros, OSX, Windows etc.

Contributions are welcome, please send pull requests

Sponsored By

Zapty - Seamless teamwork anywhere (Modern Communication, Task & Project management for teams)