2

I have a software that needs to be run via specific user "non-root" hence its home directory is /home/non-root/, I have to emphasize that the program must not be run via root and must only run after mysql has started running

And it has a software that needs to run via command: ./athena-start start. I am not really familiar with unix system, I tried googling for any tutorial, but I had no luck finding a guide that teaches how to auto-run via non-root and on centos, I found this here, but seems like it is only for Fedora.

Can somebody help me?

1 Answer 1

3

There are a few approaches to this. An init script, using crontab and various others. The simplest one, in my humble opinion, is to use @reboot tag in crontab of the user who should be running athena-start start command.

The @reboot tag runs command exactly once after your computer boots. Use crontab -e -u <yourusername> to put what follows into crontab of the user of your choice. What follows is what you should put into the crontab.

@reboot while [ "x`ps -ef|awk '$8 ~ /[:print:]*mysqld[:mysqld:]*/ { print $2 }'|wc -l`" == "x0" ]; do sleep 10 ; done && cd /your/directory && ./your_command

It might be a good idea to write that into a script and place somewhere, instead of using a horrible one-liner in your crontab. The idea behind all that is: we check the process table every 10 seconds and if we find a match, ie. there is a mysqld process (or something closely resembling it), we exit the loop, change to the directory where the precious command to be run is and then run the command in the end.

Another option would be to write an init script which starts after MySQL daemon, but an example for that would require contents of the line beginning with # chkconfig of your MySQL init script.

3
  • Hello! Thanks, my server did not have crontab installed, so I installed using yum install cronie is it right? But after running crontab -e <yourusername> via root user I got this error: crontab: usage error: no arguments permitted after this option. Actually, I learned that I do not need to know if mysql is running already, because the software seems to run every 15secs until it can connect to Mysql, so I do not think I still need "script" match function? I really appreciate this. Commented Aug 2, 2014 at 17:29
  • The command example I gave was simply incorrect. I simply did not include -u command line switch which is needed when editing another user's crontab. Answer has been edited to include a correct example. Commented Aug 3, 2014 at 8:54
  • Tried it and I think it is working. Man! Thank you very much, how can I confirm that your reply is the answer? Commented Aug 3, 2014 at 11:40

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.