简体   繁体   English

在计算机启动时使用grunt启动Node js应用程序

[英]Starting node js application using grunt on machine start up

I am new to both linux and Node js basically we have developed Node js application in Windows and I need to deploy it on Debian 8 Jessie and I am able to deploy it on linux and for this I need to install npm, node js, grunt cli etc. And to run my application I just need to type grunt using terminal and application starts. 我对Linux和Node js都是陌生的,基本上我们已经在Windows中开发了Node js应用程序,我需要将其部署在Debian 8 Jessie上,并且能够在Linux上进行部署,为此,我需要安装npm,node js,grunt cli等。要运行我的应用程序,我只需要使用终端输入grunt即可启动应用程序。 But the problem I need to start server every time after reboot of system by typing grunt in terminal. 但是问题是我需要在系统重新启动后每次在终端中键入grunt来启动服务器。

So need solution how can I start my application/server on machine start. 因此需要解决方案,如何在机器启动时启动我的应用程序/服务器。 Also let me know how this stuff works!!. 也让我知道这些东西是如何工作的!

Thanks 谢谢

as always there is more than one way 一如既往,有不止一种方法

rc.local rc.local

the prefered way. 首选方式。 rc.local will be executed on system startup. rc.local将在系统启动时执行。
to edit the file use your favourite text-editor (eg nano) nano /etc/rc.local and add your script before the last line containing exit 0 要编辑文件,请使用您喜欢的文本编辑器(例如nano) nano /etc/rc.local ,并将脚本添加到包含exit 0的最后一行之前

/usr/bin/myscript -arg1 -arg2
exit 0

cronjob cronjob

if there is also the need for recurring tasks (eg a daily backup), cronjob could be a good choice to keep things together. 如果还需要重复执行任务(例如每日备份),则cronjob可能是使事情保持一致的好选择。
Within your terminal type sudo crontab -e to edit your cronjobs. 在终端中,输入sudo crontab -e编辑您的cronjobs。 there add your command with the @reboot time argument. 在其中添加带有@reboot time参数的命令。

@reboot /usr/bin/myscript -arg1 -arg2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM