How do two users start/stop a service? eg: Tomcat

1

I found a big problem with sharing management of tomcat server.

Eg: There are 2 Linux accounts (ua & ub) both in charge of start/stop certain tomcat server.

ua: Start tomcat server with generating a pid file.

ub: Try to stop the tomcat by shutdown.sh -force, however it does not work since ub can not kill the process started by ua.

Instead of sharing single Linux account, is there a good way to deal with this situation?

ShenLei

Posted 2015-02-07T07:38:00.170

Reputation: 333

Answers

1

make an account for the service . set up sudoers to grant ua ub ability of running as the service account . like this .

# /etc/sudoers
ua,ub ALL= (service-account) /usr/sbin/daemon-programme,/bin/kill

where service-account is the account name . then users can run this and vice versa .

ua $ sudo -u service-account /usr/bin/daemon-programme --pid-file /run/programme.pid
ub $ sudo -u service-account /bin/kill $(cat /run/programme.pid)

把友情留在无盐

Posted 2015-02-07T07:38:00.170

Reputation: 383

Thank you very much! From your explanation, I get clue of why many service like mysql create a dedicated account when installation. – ShenLei – 2015-02-07T08:13:15.850

I think it can be improved further. Like sudo service mysql restart, there is no need to explicitly set uid, but mysql server is run as mysql account. How to achieve that? – ShenLei – 2015-02-07T08:49:45.647