0

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

Dima
  • 485
  • 3
  • 7
  • 15
  • What are you actually trying to achieve. What kind of different logic? – Jason Axelson Apr 02 '11 at 01: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 02 '11 at 02:10

3 Answers3

1

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.

Suku
  • 2,036
  • 13
  • 15
0

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
silviud
  • 2,687
  • 2
  • 18
  • 19
0

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.

wrmine
  • 267
  • 1
  • 4