Commit d32c03ed by Torkel Ödegaard

Rpm working again, systemd working on centos 7

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