Coder Social home page Coder Social logo

dgreif / forever-service Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zapty/forever-service

0.0 1.0 0.0 58 KB

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

Home Page: https://github.com/zapty/forever-service

License: MIT License

JavaScript 75.25% Shell 24.75%

forever-service's Introduction

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 (< 15.04)
  • Debian
  • Raspbian
  • OSMC Linux
  • Fedora 21
  • Oracle Linux
  • 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
                                       
    --nologroate                       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)
                                       
    --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)

forever-service's People

Contributors

andrew-vant avatar arvind-agarwal avatar ashyisme avatar jarmosa avatar ziacik avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.