How Run command on Linux CentOS Startup?

blog

Verified User
Joined
Jan 28, 2011
Messages
131
Hi

I will run chat application when server is restarted

it is located in: /home/admin/public_html/chat_server/

this is my command manually

cd /home/admin/public_html/chat_server/

after it I am in chat_server directory I run: forever start websocket.js

How I can run this when server is restarted?

Thank you.
 
I would not do that in any case for a chat because running from rc.local normally means running as root. You should not want to run a chat app as root. I would not even run it as admin but create a user account for it. But that's your choice.

@Blog:
For automatic starting you could create a cronjob.
First make a file like startchat.sh for example with this content:

Code:
#!/bin/sh
forever start websocket.js

Put this in the /home/admin/public_html/chat_server/ directory and do:
Code:
chmod 750 startchat.sh
Take care the file is owned by admin. Or the user if you are following my advise to run chat server under a user account.

Then create a cronjob which calls this file at reboot, you can use the @reboot variable for that.
 
Last edited:
Many thanks for your help, Have a lucky and wonderful 2015
 
Back
Top