通过命令行可以启动:
cqh@cqh-MS-7A74:~/local_code/tscode/local_alarm$ npm run start
> local_alarm@1.0.0 start /home/cqh/local_code/tscode/local_alarm
> egg-scripts start --daemon --title=egg-server-local_alarm
[egg-scripts] Starting egg application at /home/cqh/local_code/tscode/local_alarm
[egg-scripts] Run node /home/cqh/local_code/tscode/local_alarm/node_modules/egg-scripts/lib/start-cluster {"title":"egg-server-local_alarm","framework":"/home/cqh/local_code/tscode/local_alarm/node_modules/egg","baseDir":"/home/cqh/local_code/tscode/local_alarm"} --title=egg-server-local_alarm
[egg-scripts] Save log file to /home/cqh/logs
[egg-scripts] Wait Start: 1...
[egg-scripts] egg started on http://127.0.0.1:7001
service 文件
[Unit]
Description= local alarm service write by lua
[Service]
Type=simple
WorkingDirectory=/home/cqh/local_code/tscode/local_alarm
ExecStart=/home/cqh/git/nvm/versions/node/v10.3.0/bin/npm run start
User=cqh
Restart=on-failure
ExecStop=/home/cqh/git/nvm/versions/node/v10.3.0/bin/npm run stop
[Install]
WantedBy=multi-user.target
但是通过 systemctl 无法启动
journalctl -xe
显示
-- Subject: local_alarm_lua.service 单元已结束停止操作
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- local_alarm_lua.service 单元已结束停止操作。
8 月 06 10:51:01 cqh-MS-7A74 systemd[1]: Started local alarm service write by lua.
-- Subject: local_alarm_lua.service 单元已结束启动
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- local_alarm_lua.service 单元已结束启动。
--
-- 启动结果为“ done ”。
8 月 06 10:51:01 cqh-MS-7A74 npm[4792]: /home/cqh/git/nvm/versions/node/v10.3.0/lib/node_modules/npm/bin/npm-cli.js:79
8 月 06 10:51:01 cqh-MS-7A74 npm[4792]: let notifier = require('update-notifier')({pkg})
8 月 06 10:51:01 cqh-MS-7A74 npm[4792]: ^^^
8 月 06 10:51:01 cqh-MS-7A74 npm[4792]: SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
8 月 06 10:51:01 cqh-MS-7A74 npm[4792]: at exports.runInThisContext (vm.js:53:16)
8 月 06 10:51:01 cqh-MS-7A74 npm[4792]: at Module._compile (module.js:374:25)
8 月 06 10:51:01 cqh-MS-7A74 npm[4792]: at Object.Module._extensions..js (module.js:417:10)
8 月 06 10:51:01 cqh-MS-7A74 npm[4792]: at Module.load (module.js:344:32)
8 月 06 10:51:01 cqh-MS-7A74 npm[4792]: at Function.Module._load (module.js:301:12)
8 月 06 10:51:01 cqh-MS-7A74 npm[4792]: at Function.Module.runMain (module.js:442:10)
8 月 06 10:51:01 cqh-MS-7A74 npm[4792]: at startup (node.js:136:18)
8 月 06 10:51:01 cqh-MS-7A74 npm[4792]: at node.js:966:3
8 月 06 10:51:01 cqh-MS-7A74 systemd[1]: local_alarm_lua.service: Main process exited, code=exited, status=1/FAILURE
8 月 06 10:51:01 cqh-MS-7A74 npm[4808]: /home/cqh/git/nvm/versions/node/v10.3.0/lib/node_modules/npm/bin/npm-cli.js:79
8 月 06 10:51:01 cqh-MS-7A74 npm[4808]: let notifier = require('update-notifier')({pkg})
8 月 06 10:51:01 cqh-MS-7A74 npm[4808]: ^^^
8 月 06 10:51:01 cqh-MS-7A74 npm[4808]: SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
8 月 06 10:51:01 cqh-MS-7A74 npm[4808]: at exports.runInThisContext (vm.js:53:16)
8 月 06 10:51:01 cqh-MS-7A74 npm[4808]: at Module._compile (module.js:374:25)
8 月 06 10:51:01 cqh-MS-7A74 npm[4808]: at Object.Module._extensions..js (module.js:417:10)
8 月 06 10:51:01 cqh-MS-7A74 npm[4808]: at Module.load (module.js:344:32)
8 月 06 10:51:01 cqh-MS-7A74 npm[4808]: at Function.Module._load (module.js:301:12)
8 月 06 10:51:01 cqh-MS-7A74 npm[4808]: at Function.Module.runMain (module.js:442:10)
8 月 06 10:51:01 cqh-MS-7A74 npm[4808]: at startup (node.js:136:18)
8 月 06 10:51:01 cqh-MS-7A74 npm[4808]: at node.js:966:3
8 月 06 10:51:01 cqh-MS-7A74 systemd[1]: local_alarm_lua.service: Control process exited, code=exited status=1
8 月 06 10:51:01 cqh-MS-7A74 systemd[1]: local_alarm_lua.service: Unit entered failed state.
8 月 06 10:51:01 cqh-MS-7A74 systemd[1]: local_alarm_lua.service: Failed with result 'exit-code'.
8 月 06 10:51:01 cqh-MS-7A74 systemd[1]: local_alarm_lua.service: Service hold-off time over, scheduling restart.
8 月 06 10:51:01 cqh-MS-7A74 systemd[1]: Stopped local alarm service write by lua.
-- Subject: local_alarm_lua.service 单元已结束停止操作
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
所以, 这个 service 到底该怎么写呢?
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.