[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.target
The 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)