Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

Thanks

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

3 Answers 3

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

 
discard

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.