mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
chown the pidfile to the correct user
This commit is contained in:
parent
a235f79a3f
commit
51c5944cd7
@ -368,7 +368,7 @@ class PidfileMixin(object):
|
||||
|
||||
def set_pidfile(self):
|
||||
from salt.utils.process import set_pidfile
|
||||
set_pidfile(self.config['pidfile'])
|
||||
set_pidfile(self.config['pidfile'], self.config['user'])
|
||||
|
||||
|
||||
class TargetOptionsMixIn(object):
|
||||
|
@ -6,7 +6,7 @@ import time
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def set_pidfile(pidfile):
|
||||
def set_pidfile(pidfile, user):
|
||||
'''
|
||||
Save the pidfile
|
||||
'''
|
||||
@ -18,6 +18,29 @@ def set_pidfile(pidfile):
|
||||
f.write(str(os.getpid()))
|
||||
except IOError:
|
||||
pass
|
||||
log.debug(('Created pidfile: {0}').format(pidfile))
|
||||
if 'os' in os.environ:
|
||||
if os.environ['os'].startswith('Windows'):
|
||||
return True
|
||||
import pwd # after confirming not running Windows
|
||||
import grp
|
||||
try:
|
||||
pwnam = pwd.getpwnam(user)
|
||||
uid = pwnam[2]
|
||||
gid = pwnam[3]
|
||||
groups = [g.gr_gid for g in grp.getgrall() if user in g.gr_mem]
|
||||
except KeyError:
|
||||
err = ('Failed to set the pid to user: '
|
||||
'{0}. The user is not available.\n').format(user)
|
||||
sys.stderr.write(err)
|
||||
sys.exit(2)
|
||||
try:
|
||||
os.chown(pidfile, uid, gid)
|
||||
except Error as e:
|
||||
msg = ('Failed to set the pid to user {0}').format(ser)
|
||||
sys.stderr.write(msg)
|
||||
sys.exit(e.errno)
|
||||
log.debug(('Chowned pidfile: {0} to user: {1}').format(pidfile, user))
|
||||
|
||||
|
||||
def clean_proc(proc, wait_for_kill=10):
|
||||
|
Loading…
Reference in New Issue
Block a user