Node.js systemd service unit
This unit runs on <service_name>@.service, which means it is a multiple service instance that should be started with command systemctl start <service_name>@<instance>, place it under /etc/systemd/system/:
The wrapper:
[Unit]
Description=Botanical %i servlet
[Service]
ExecStart=/opt/autorun/node-js.service %i
Restart=no
User=www-data
Group=www-data
Environment=PATH=/usr/bin:/usr/local/bin
WorkingDirectory=/var/www/%i
[Install]
WantedBy=multi-user.targetThe wrapper:
#!/usr/bin/env node
"use strict";
const FS = require( "fs" );
const CLUSTER = require( "cluster" );
const SERV = process.argv[2];
if( !SERV )
{
console.error( "Service undefined" );
process.exit(1);
}
const SrvLocation = "/var/www/" + SERV + "/index.js"
if( FS.existsSync( SrvLocation ) )
{
if( CLUSTER.isMaster )
{
console.log( "Starting service: " + SERV );
}
else
{
console.log( "Cluster: " + process.pid );
}
process.chdir( "/var/www/" + SERV );
require( SrvLocation );
}
else
{
console.error( "Service \"" + SERV + "\" does not exists" );
process.exit(1);
}
Sat Feb 20 2016 17:33:33 GMT+0000 (Coordinated Universal Time)
Last modified: Sun Jan 22 2017 03:03:21 GMT+0000 (Coordinated Universal Time)
Comments
No comments here.
Do you even comment?
website:
Not a valid website
Invalid email format
Please enter your email
*Name:
Please enter a name
Submit
抱歉,Google Recaptcha 服務被牆掉了,所以不能回覆了