Skip to content

Commit

Permalink
Carbon user implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
deniszh authored and Civil committed May 18, 2021
1 parent bb33f26 commit 8b2af16
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions contrib/carbonapi/deb/carbonapi.service
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ PIDFile=/var/run/carbonapi/carbonapi.pid
LimitNOFILE=200000
RuntimeDirectory=carbonapi
RuntimeDirectoryMode=0755
User=carbon
Group=carbon

[Install]
WantedBy=multi-user.target
45 changes: 45 additions & 0 deletions contrib/carbonapi/fpm/carbon-user-systemd-reload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh

# based on https://github.com/leoleovich/grafsy/blob/master/packaging/postinst

# Abort if any command returns an error value
set -e

USER=carbon
GROUP=carbon
CONF=/etc/carbonapi/carbonapi.yaml
PIDFILE=/var/run/carbonapi/carbonapi.pid
LOGFILE=/var/log/carbonapi/carbonapi.log

# Following user part should be tested on both RPM and DEB systems
if ! getent group "${GROUP}" > /dev/null 2>&1 ; then
groupadd --system "${GROUP}"
fi
GID=$(getent group "${GROUP}" | cut -d: -f 3)
if ! id "${USER}" > /dev/null 2>&1 ; then
adduser --system --home /dev/null --no-create-home \
--gid "${GID}" --shell /bin/false \
"${USER}"
fi

# fix PID permissions
if [ -f "${PIDFILE}" ]; then
chown "${USER}":"${GROUP}" "${PIDFILE}"
fi

# fix log permissions
if [ -f "${LOGFILE}" ]; then
chown "${USER}":"${GROUP}" "${LOGFILE}"
fi

if [ ! -e "${CONF}" ]; then
echo "For use this software you have to create ${CONF} file. You could use /usr/share/carbonapi/carbonapi.example.yaml as default"
else
# On debian jessie (systemd 215) it fails if symlink already exists
systemctl is-enabled carbonapi || systemctl enable carbonapi
# Check if systemd is up and running, e.g. not in chroot
if systemctl 1>/dev/null 2>&1; then
systemctl daemon-reload
systemctl restart carbonapi.service
fi
fi
2 changes: 2 additions & 0 deletions contrib/carbonapi/rhel/carbonapi.service
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ PIDFile=/var/run/carbonapi/carbonapi.pid
LimitNOFILE=200000
RuntimeDirectory=carbonapi
RuntimeDirectoryMode=0755
User=carbon
Group=carbon

[Install]
WantedBy=multi-user.target

0 comments on commit 8b2af16

Please sign in to comment.