Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

linux - 如何在启动时运行shell脚本(How to run a shell script at startup)

On an amazon linux instance, I have two scripts called start_my_app and stop_my_app which start and stop forever (which in turn runs my node.js app).

(在亚马逊linux实例上,我有两个名为start_my_appstop_my_app脚本,它们永远启动和停止(后者又运行我的node.js应用程序)。)

I use these scripts to manually start and stop my node app.

(我使用这些脚本手动启动和停止我的节点应用程序。)

So far so good.

(到现在为止还挺好。)

My problem: I also want to set it up such that start_my_app is run whenever the system boots up.

(我的问题:我也想设置它, start_my_app在系统启动时运行start_my_app 。)

I know that I need to add a file inside init.d and I know how to symlink it to the proper directory within rc.d , but can't figure out what actually needs to go inside the file that I place in init.d .

(我知道我需要在init.d添加一个文件,我知道如何将它符号链接到rc.d的正确目录,但是无法弄清楚我在init.d放置的文件中究竟需要什么。 。)

I'm thinking it should be just one line, like, start_my_app , but that hasn't been working for me.

(我认为它应该只是一行,比如, start_my_app ,但这对我start_my_app 。)

  ask by meetamit translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Set a crontab for this

(为此设置一个crontab)

#crontab -e
@reboot  /home/user/test.sh

after every startup it will run the test script.

(每次启动后,它都会运行测试脚本。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...