Commit d32c03ed by Torkel Ödegaard

Rpm working again, systemd working on centos 7

parent 3e496090
......@@ -71,8 +71,7 @@ func main() {
case "package":
//verifyGitRepoIsClean()
//grunt("release", "--pkgVer="+version)
createPackage("deb", "default")
//createPackage("rpm", "sysconfig")
createLinuxPackages()
case "latest":
makeLatestDistCopies()
......@@ -110,66 +109,116 @@ func readVersionFromPackageJson() {
version = jsonObj["version"].(string)
}
func createPackage(packageType string, defaultPath string) {
homeDir := "/usr/share/grafana"
configDir := "/etc/grafana"
configFilePath := "/etc/grafana/grafana.ini"
defaultFilePath := filepath.Join("/etc/", defaultPath, "grafana-server")
grafanaServerBinPath := "/usr/sbin/" + serverBinaryName
initdScriptPath := "/etc/init.d/grafana-server"
systemdServiceFilePath := "/usr/lib/systemd/system/grafana-server.service"
type linuxPackageOptions struct {
packageType string
homeDir string
binPath string
configDir string
configFilePath string
etcDefaultPath string
etcDefaultFilePath string
initdScriptFilePath string
systemdServiceFilePath string
postinstSrc string
initdScriptSrc string
defaultFileSrc string
systemdFileSrc string
depends []string
}
packageRoot, _ := ioutil.TempDir("", "grafana-linux-pack")
packageConfDir := filepath.Join("packaging", packageType)
func createLinuxPackages() {
createPackage(linuxPackageOptions{
packageType: "deb",
homeDir: "/usr/share/grafana",
binPath: "/usr/sbin/grafana-server",
configDir: "/etc/grafana",
configFilePath: "/etc/grafana/grafana.ini",
etcDefaultPath: "/etc/default",
etcDefaultFilePath: "/etc/default/grafana-server",
initdScriptFilePath: "/etc/init.d/grafana-server",
systemdServiceFilePath: "/usr/lib/systemd/system/grafana-server.service",
postinstSrc: "packaging/deb/control/postinst",
initdScriptSrc: "packaging/deb/init.d/grafana-server",
defaultFileSrc: "packaging/deb/default/grafana-server",
systemdFileSrc: "packaging/deb/systemd/grafana-server.service",
depends: []string{"adduser", "libfontconfig"},
})
createPackage(linuxPackageOptions{
packageType: "rpm",
homeDir: "/usr/share/grafana",
binPath: "/usr/sbin/grafana-server",
configDir: "/etc/grafana",
configFilePath: "/etc/grafana/grafana.ini",
etcDefaultPath: "/etc/sysconfig",
etcDefaultFilePath: "/etc/sysconfig/grafana-server",
initdScriptFilePath: "/etc/init.d/grafana-server",
systemdServiceFilePath: "/usr/lib/systemd/system/grafana-server.service",
postinstSrc: "packaging/rpm/control/postinst",
initdScriptSrc: "packaging/rpm/init.d/grafana-server",
defaultFileSrc: "packaging/rpm/sysconfig/grafana-server",
systemdFileSrc: "packaging/rpm/systemd/grafana-server.service",
depends: []string{"initscripts", "fontconfig"},
})
}
postintSrc := filepath.Join(packageConfDir, "control/postinst")
initdScriptSrc := filepath.Join(packageConfDir, "init.d/grafana-server")
defaultFileSrc := filepath.Join(packageConfDir, defaultPath, "grafana-server")
systemdFileSrc := filepath.Join(packageConfDir, "systemd/grafana-server.service")
func createPackage(options linuxPackageOptions) {
packageRoot, _ := ioutil.TempDir("", "grafana-linux-pack")
// create directories
runPrint("mkdir", "-p", filepath.Join(packageRoot, homeDir))
runPrint("mkdir", "-p", filepath.Join(packageRoot, configDir))
runPrint("mkdir", "-p", filepath.Join(packageRoot, options.homeDir))
runPrint("mkdir", "-p", filepath.Join(packageRoot, options.configDir))
runPrint("mkdir", "-p", filepath.Join(packageRoot, "/etc/init.d"))
runPrint("mkdir", "-p", filepath.Join(packageRoot, "/etc/", defaultPath))
runPrint("mkdir", "-p", filepath.Join(packageRoot, options.etcDefaultPath))
runPrint("mkdir", "-p", filepath.Join(packageRoot, "/usr/lib/systemd/system"))
runPrint("mkdir", "-p", filepath.Join(packageRoot, "/usr/sbin"))
// copy binary
runPrint("cp", "-p", filepath.Join(workingDir, "tmp/bin/"+serverBinaryName), filepath.Join(packageRoot, grafanaServerBinPath))
runPrint("cp", "-p", filepath.Join(workingDir, "tmp/bin/"+serverBinaryName), filepath.Join(packageRoot, options.binPath))
// copy init.d script
runPrint("cp", "-p", initdScriptSrc, filepath.Join(packageRoot, initdScriptPath))
runPrint("cp", "-p", options.initdScriptSrc, filepath.Join(packageRoot, options.initdScriptFilePath))
// copy environment var file
runPrint("cp", "-p", defaultFileSrc, filepath.Join(packageRoot, defaultFilePath))
runPrint("cp", "-p", options.defaultFileSrc, filepath.Join(packageRoot, options.etcDefaultFilePath))
// copy systemd file
runPrint("cp", "-p", systemdFileSrc, filepath.Join(packageRoot, systemdServiceFilePath))
runPrint("cp", "-p", options.systemdFileSrc, filepath.Join(packageRoot, options.systemdServiceFilePath))
// copy release files
runPrint("cp", "-a", filepath.Join(workingDir, "tmp")+"/.", filepath.Join(packageRoot, homeDir))
runPrint("cp", "-a", filepath.Join(workingDir, "tmp")+"/.", filepath.Join(packageRoot, options.homeDir))
// copy sample ini file to /etc/opt/grafana
runPrint("cp", "conf/sample.ini", filepath.Join(packageRoot, configFilePath))
runPrint("cp", "conf/sample.ini", filepath.Join(packageRoot, options.configFilePath))
args := []string{
"-s", "dir",
"--description", "Grafana",
"-C", packageRoot,
"--vendor", "Grafana",
"--depends", "adduser",
"--url", "http://grafana.org",
"--license", "Apache 2.0",
"--maintainer", "contact@grafana.org",
"--config-files", configFilePath,
"--config-files", initdScriptPath,
"--config-files", defaultFilePath,
"--config-files", systemdServiceFilePath,
"--after-install", postintSrc,
"--config-files", options.configFilePath,
"--config-files", options.initdScriptFilePath,
"--config-files", options.etcDefaultFilePath,
"--config-files", options.systemdServiceFilePath,
"--after-install", options.postinstSrc,
"--name", "grafana",
"--version", version,
"-p", "./dist",
".",
}
fmt.Println("Creating package: ", packageType)
runPrint("fpm", append([]string{"-t", packageType}, args...)...)
// add dependenciesj
for _, dep := range options.depends {
args = append(args, "--depends", dep)
}
args = append(args, ".")
fmt.Println("Creating package: ", options.packageType)
runPrint("fpm", append([]string{"-t", options.packageType}, args...)...)
}
func verifyGitRepoIsClean() {
......
......@@ -70,7 +70,7 @@ case "$1" in
fi
# Prepare environment
mkdir -p "$LOG_DIR" "$DATA_DIR" "$WORK_DIR" && chown "$GRAFANA_USER":"$GRAFANA_GROUP" "$LOG_DIR" "$DATA_DIR" "$WORK_DIR"
mkdir -p "$LOG_DIR" "$DATA_DIR" && chown "$GRAFANA_USER":"$GRAFANA_GROUP" "$LOG_DIR" "$DATA_DIR"
touch "$PID_FILE" && chown "$GRAFANA_USER":"$GRAFANA_GROUP" "$PID_FILE"
if [ -n "$MAX_OPEN_FILES" ]; then
......
......@@ -24,17 +24,17 @@ stopGrafana() {
fi
}
case "$1" in
configure)
# Initial installation: $1 == 1
# Upgrade: $1 == 2, and configured to restart on upgrade
if [ $1 -eq 1 ] ; then
[ -z "$GRAFANA_USER" ] && GRAFANA_USER="grafana"
[ -z "$GRAFANA_GROUP" ] && GRAFANA_GROUP="grafana"
if ! getent group "$GRAFANA_GROUP" > /dev/null 2>&1 ; then
addgroup --system "$GRAFANA_GROUP" --quiet
groupadd -r "$GRAFANA_GROUP"
fi
if ! id $GRAFANA_USER > /dev/null 2>&1 ; then
adduser --system --home /usr/share/grafana --no-create-home \
--ingroup "$GRAFANA_GROUP" --disabled-password --shell /bin/false \
"$GRAFANA_USER"
if ! getent passwd "$GRAFANA_USER" > /dev/null 2>&1 ; then
useradd -r -g grafana -d /usr/share/grafana -s /sbin/nologin \
-c "grafana user" grafana
fi
# Set user permissions on /var/log/grafana, /var/lib/grafana
......@@ -48,24 +48,20 @@ case "$1" in
find /etc/grafana -type f -exec chmod 644 {} ';'
find /etc/grafana -type d -exec chmod 755 {} ';'
# if $2 is set, this is an upgrade
if ( [ -n $2 ] && [ "$RESTART_ON_UPGRADE" = "true" ] ) ; then
startGrafana
# this is a fresh installation
elif [ -z $2 ] ; then
if [ -x /bin/systemctl ] ; then
echo "### NOT starting on installation, please execute the following statements to configure elasticsearch to start automatically using systemd"
echo " sudo /bin/systemctl daemon-reload"
echo " sudo /bin/systemctl enable grafana-server.service"
echo "### You can start grafana-server by executing"
echo " sudo /bin/systemctl start grafana-server.service"
if [ -x /bin/systemctl ] ; then
echo "### NOT starting on installation, please execute the following statements to configure elasticsearch to start automatically using systemd"
echo " sudo /bin/systemctl daemon-reload"
echo " sudo /bin/systemctl enable grafana-server.service"
echo "### You can start grafana-server by executing"
echo " sudo /bin/systemctl start grafana-server.service"
elif [ -x /usr/sbin/update-rc.d ] ; then
echo "### NOT starting grafana-server by default on bootup, please execute"
echo " sudo update-rc.d grafana-server defaults 95 10"
echo "### In order to start grafana-server, execute"
echo " sudo service grafana-server start"
fi
fi
;;
esac
elif [ -x /usr/sbin/update-rc.d ] ; then
echo "### NOT starting grafana-server by default on bootup, please execute"
echo " sudo update-rc.d grafana-server defaults 95 10"
echo "### In order to start grafana-server, execute"
echo " sudo service grafana-server start"
fi
elif [ $1 -ge 2 -a "$RESTART_ON_UPGRADE" == "true" ] ; then
stopGrafana
startGrafana
fi
......@@ -20,9 +20,21 @@
# 3. Centos with initscripts package installed
PATH=/bin:/usr/bin:/sbin:/usr/sbin
NAME=grafana
NAME=grafana-server
DESC="Grafana Server"
GRAFANA_USER=grafana
GRAFANA_GROUP=grafana
GRAFANA_HOME=/usr/share/grafana
CONF_DIR=/etc/grafana
WORK_DIR=$GRAFANA_HOME
DATA_DIR=/var/lib/grafana
LOG_DIR=/var/log/grafana
CONF_FILE=$CONF_DIR/grafana.ini
MAX_OPEN_FILES=10000
PID_FILE=/var/run/$NAME.pid
DAEMON=/usr/sbin/$NAME
#
# init.d / servicectl compatibility (openSUSE)
#
......@@ -38,21 +50,10 @@ if [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
fi
GRAFANA_USER=grafana
GRAFANA_GROUP=grafana
GRAFANA_HOME=/opt/$NAME
CONF_DIR=/etc/$NAME
WORK_DIR=$GRAFANA_HOME
DATA_DIR=$GRAFANA_HOME/data
LOG_DIR=/var/log/$NAME
CONF_FILE=$CONF_DIR/grafana.ini
MAX_OPEN_FILES=65535
# overwrite settings from default file
[ -e /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
PID_FILE=/var/run/$NAME.pid
DAEMON=$GRAFANA_HOME/bin/grafana
DAEMON_OPTS="--pidfile=${PID_FILE} --config=${CONF_FILE} --default-data-path=${DATA_DIR} --default-log-path=${LOG_DIR} web"
# Check DAEMON exists
......@@ -88,7 +89,7 @@ case "$1" in
fi
# Prepare environment
mkdir -p "$LOG_DIR" "$DATA_DIR" "$WORK_DIR" && chown "$GRAFANA_USER":"$GRAFANA_GROUP" "$LOG_DIR" "$DATA_DIR" "$WORK_DIR"
mkdir -p "$LOG_DIR" "$DATA_DIR" && chown "$GRAFANA_USER":"$GRAFANA_GROUP" "$LOG_DIR" "$DATA_DIR"
touch "$PID_FILE" && chown "$GRAFANA_USER":"$GRAFANA_GROUP" "$PID_FILE"
if [ -n "$MAX_OPEN_FILES" ]; then
......
GRAFANA_USER=grafana
#GRAFANA_USER=grafana
GRAFANA_GROUP=grafana
#GRAFANA_GROUP=grafana
GRAFANA_HOME=/usr/share/grafana
#LOG_DIR=/var/log/grafana
LOG_DIR=/var/log/grafana
#GRAFANA_HOME=/opt/grafana
#DATA_DIR=/opt/data/grafana
#WORK_DIR=/opt/grafana
DATA_DIR=/var/lib/grafana
#CONF_DIR=/etc/grafana
#CONF_FILE=/etc/grafana/grafana.ini
MAX_OPEN_FILES=10000
#RESTART_ON_UPGRADE=true
CONF_DIR=/etc/grafana
CONF_FILE=/etc/grafana/grafana.ini
RESTART_ON_UPGRADE=true
[Unit]
Description=Starts and stops a single grafana instance on this system
Documentation=http://docs.grafana.org
Wants=network-online.target
After=network-online.target
[Service]
EnvironmentFile=/etc/sysconfig/grafana-server
User=grafana
Group=grafana
Type=simple
WorkingDirectory=/usr/share/grafana
ExecStart=/usr/sbin/grafana-server \
--config=${CONF_FILE} \
cfg:default.paths.logs=${LOG_DIR} \
cfg:default.paths.data=${DATA_DIR} \
LimitNOFILE=10000
TimeoutStopSec=20
[Install]
WantedBy=multi-user.target
......@@ -227,6 +227,7 @@ func evalConfigValues() {
func loadSpecifedConfigFile(configFile string) {
userConfig, err := ini.Load(configFile)
userConfig.BlockMode = false
if err != nil {
log.Fatal(3, "Failed to parse %v, %v", configFile, err)
}
......@@ -262,7 +263,7 @@ func loadConfiguration(args *CommandLineArgs) {
configFiles = append(configFiles, defaultConfigFile)
Cfg, err = ini.Load(defaultConfigFile)
Cfg.BlockMode = true
Cfg.BlockMode = false
if err != nil {
log.Fatal(3, "Failed to parse defaults.ini, %v", err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment