pneumon
v0.1.4
Published
Pneumon is a module that allows automatic updating and managment of nodeJS app deployments
Downloads
10
Maintainers
Readme
pneumon
Pneumon is a module that allows automatic updating and managment of nodeJS app deployments.
API
Pneumon(options)
String version
: Current app versionupdater
: Updater configurationFunction<Promise<Object>>
: A function that returns a promise that contains the following valuesString version
: Version String (Can be anything, pnemoun does not differentiate between up- and downgrades)Buffer checksum
(optional): Multihash encoded checksum (note: only a subset supported). If this is null, checksum checks will be skipped (UNRECOMMENDED)String url
: Download URL for file
String
: URL to a JSON file in the above format, except checksum must be encoded as hex
Integer checkInterval
: Check interval for updates. Default 1000 * 60 * 60 (1h)String executorPath
: Binary to execute the executable with. This usually is the nodeJS runtime. Set this tofalse
to make the binary get directly executed, as it is required for pkg. (Note: Ifprocess.pkg
is set then this is automatically getting set tofalse
)String binaryPath
: The path to the binary. This isprocess.argv[1]
by default, unlessexecutorPath
is set tofalse
then it'sprocess.argv[0]
wrapperScript
: Wrapper script that needs to be replaced. Optional.Boolean
: Iftrue
then a wrapper script will be created atbinaryPath
+ extension for platformString
: Path to wrapper scriptObject
:path
: Path to wrapper scripttype
: Can be one ofsh
,bat
,ps
. Usually auto-detected based on file-ending or platform
Function serviceManager({ name, cmd, args })
: Service manager. Can be either a string ofsystemd
,linux
,mac
,windows
(NOTE: last 3 will get deperacted soon, see issue #1) or an object. Default is auto-detected by platformPromise<Boolean> isInstalled(name)
: Checks whether the named service is installedPromise<Void> install(name, cmd, args)
: Installs a service that launches a command with arguments. NOTE: Will also be called sometimes to update an existing servicePromise<Void> uninstall()
: Uninstalls the servicePromise<Void> start()
: Starts the servicePromise<Void> stop()
: Stops the servicePromise<Void> restart(bg)
: Restarts the service,bg
option forks the command to the backgroundPromise<Boolean> isRunningAsService()
: Tries to detect whether the app is running in a service
String name
: Name used for app service
Promise<Boolean> .isInstalled()
: Returns whether the app is installed as a service
Promise<Void> .install()
: Installs app and starts service
Promise<Void> .uninstall()
: Uninstalls app and stops service
Promise<Void> routines.install()
: Installs app
Promise<Void> routines.uninstall()
: Uninstalls app
.service
: See serviceManager
Promise<Boolean> .isRunningAsService()
: Check whether we are in a service or not
Promise<Boolean> .checkForUpdates()
: Returns if updates are available
Promise<Void> .update()
: Runs update routine (Check?, Download, Replace, Restart)
Events (NOT YET IMPLEMENTED)
checkFailed(err)
: Update check has failed
check(data, currentVersion)
: Update check has succeded
updateFound(data, currentVersion)
: Update check has found new version
download(url)
: Downloading newer version
downloadFail(err)
: Downloading newer version failed
Usage
const pneumon = require('pneumon')
const App = Pneumon({ // most stuff is optional, this is the bare-minimum
version: require('./package.json').version,
updater: 'https://your-ota-server/app/pneumon.json',
name: 'my-cool-app'
})
const main = async () => {
if (!await app.isInstalled()) {
await app.install() // installs service
process.exit(0) // quit this instance
}
if (!await app.isRunningAsService()) {
console.error('Run this as a service')
process.exit(0)
}
}
main()
Helpful notes
To use pneumon, you need to bundle your code into a single file which you can do using pkg or parcel
You could also use docker, but sometimes that's simply not an option or just too much, that's why I created this lib
GitLab Config
If you want to deploy the binary from gitlab simply launch a gitlab-artifacts-server and add this job to the gitlab-ci yaml:
build:
script:
# for pkg
- npx pkg --out-path deploy .
# OR for parcel (unrecommended as it doesn't always work)
# - npx parcel --target node --bundle-node-modules
# writes metadata
- 'for f in deploy/*; do npx pneumon --version "$(cat package.json | jq -rc)" --hash --file "$f" --out "$f.json"; done'
image: node:10
stage: build
artifacts:
paths:
- deploy/
Wrapper Script
The wrapper script is a simple script that checks for a new binary, replaces the current one with the new one and runs the new binary
Todo
- [ ] Tests
- [ ] More services
- [ ] Maybe support archives, too