Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can I know if my service is started on system init or it started by user using service command?

On my service I need to make different logic (into service starter script) if service is started automatically or by user command.


share|improve this question
What are you actually trying to achieve. What kind of different logic? – Jason Axelson Apr 2 '11 at 1:14
Doesn't answer your question, but what you should really do is make an init script and only start the service with it. Then it shouldn't whether it was started by a user or by init. – Scott Pack Apr 2 '11 at 2:10
up vote 0 down vote accepted

if the users use sudo or they su root i don't think is a way you can tell, but i think you can do this:

add a command that looks for server uptime - if the uptime is very very low as in is just starting then you can ASSUME that is server startup and you do the logic around it.

uptime | awk '{print $3}' # prints the minutes since the host is up
share|improve this answer

If service is ON in chkconfig list, it is started by init.

If service is OFF in chkconfig list and service is in started state, then it is started from user level.

share|improve this answer

If I understand correctly, your looking for 'chkconfig --list' which will list all the registered services in /etc/init.d/* . Other service commands can be started from /etc/init.d but not be added to chkconfig, from /etc/rc.local, and from /etc/inittab.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.