Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
c3cffeb1
Commit
c3cffeb1
authored
Sep 04, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packaging: fixed issue with pid file on systemd systems, fixes #9133
parent
ce6050f5
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
80 additions
and
50 deletions
+80
-50
packaging/deb/control/postinst
+7
-0
packaging/deb/default/grafana-server
+3
-0
packaging/deb/systemd/grafana-server.service
+5
-5
packaging/rpm/control/postinst
+13
-0
packaging/rpm/sysconfig/grafana-server
+3
-0
packaging/rpm/systemd/grafana-server.service
+5
-5
pkg/cmd/grafana-server/main.go
+0
-38
pkg/cmd/grafana-server/server.go
+44
-2
No files found.
packaging/deb/control/postinst
View file @
c3cffeb1
...
...
@@ -6,6 +6,7 @@ set -e
IS_UPGRADE
=
false
case
"
$1
"
in
configure
)
[
-z
"
$GRAFANA_USER
"
]
&&
GRAFANA_USER
=
"grafana"
...
...
@@ -41,6 +42,12 @@ case "$1" in
IS_UPGRADE
=
true
fi
# make sure there is a /var/run/grafana dir on systemd systems
if
[
-x
/bin/systemctl
]
;
then
mkdir
-p
$PID_FILE_DIR
chown
-R
$GRAFANA_USER
:
$GRAFANA_GROUP
$PID_FILE_DIR
fi
if
[
"x
$IS_UPGRADE
"
!=
"xtrue"
]
;
then
if
command
-v
systemctl
>
/dev/null
;
then
echo
"### NOT starting on installation, please execute the following statements to configure grafana to start automatically using systemd"
...
...
packaging/deb/default/grafana-server
View file @
c3cffeb1
...
...
@@ -17,3 +17,6 @@ CONF_FILE=/etc/grafana/grafana.ini
RESTART_ON_UPGRADE=true
PLUGINS_DIR=/var/lib/grafana/plugins
# Only used on systemd systems
PID_FILE_DIR=/var/run/grafana
packaging/deb/systemd/grafana-server.service
View file @
c3cffeb1
...
...
@@ -12,11 +12,11 @@ Group=grafana
Type=simple
Restart=on-failure
WorkingDirectory=/usr/share/grafana
ExecStart=/usr/sbin/grafana-server \
--config=${CONF_FILE} \
--pidfile=${PID_FILE
}
\
cfg:default.paths.logs=${LOG_DIR} \
cfg:default.paths.data=${DATA_DIR} \
ExecStart=/usr/sbin/grafana-server
\
--config=${CONF_FILE}
\
--pidfile=${PID_FILE
_DIR}/grafana-server.pid
\
cfg:default.paths.logs=${LOG_DIR}
\
cfg:default.paths.data=${DATA_DIR}
\
cfg:default.paths.plugins=${PLUGINS_DIR}
LimitNOFILE=10000
TimeoutStopSec=20
...
...
packaging/rpm/control/postinst
View file @
c3cffeb1
...
...
@@ -25,6 +25,7 @@ stopGrafana() {
fi
}
# Initial installation: $1 == 1
# Upgrade: $1 == 2, and configured to restart on upgrade
if
[
$1
-eq
1
]
;
then
...
...
@@ -55,6 +56,12 @@ if [ $1 -eq 1 ] ; then
find /etc/grafana
-type
f
-exec
chmod 640
{}
';'
find /etc/grafana
-type
d
-exec
chmod 755
{}
';'
# make sure there is a /var/run/grafana dir on systemd systems
if
[
-x
/bin/systemctl
]
;
then
mkdir
-p
$PID_FILE_DIR
chown
-R
$GRAFANA_USER
:
$GRAFANA_GROUP
$PID_FILE_DIR
fi
if
[
-x
/bin/systemctl
]
;
then
echo
"### NOT starting on installation, please execute the following statements to configure grafana to start automatically using systemd"
echo
" sudo /bin/systemctl daemon-reload"
...
...
@@ -68,6 +75,12 @@ if [ $1 -eq 1 ] ; then
echo
" sudo service grafana-server start"
fi
elif
[
$1
-ge
2
]
;
then
# make sure there is a /var/run/grafana dir on systemd systems
if
[
-x
/bin/systemctl
]
;
then
mkdir
-p
$PID_FILE_DIR
chown
-R
$GRAFANA_USER
:
$GRAFANA_GROUP
$PID_FILE_DIR
fi
if
[
"
$RESTART_ON_UPGRADE
"
==
"true"
]
;
then
stopGrafana
startGrafana
...
...
packaging/rpm/sysconfig/grafana-server
View file @
c3cffeb1
...
...
@@ -17,3 +17,6 @@ CONF_FILE=/etc/grafana/grafana.ini
RESTART_ON_UPGRADE=true
PLUGINS_DIR=/var/lib/grafana/plugins
# Only used on systemd systems
PID_FILE_DIR=/var/run/grafana
packaging/rpm/systemd/grafana-server.service
View file @
c3cffeb1
...
...
@@ -12,11 +12,11 @@ Group=grafana
Type=simple
Restart=on-failure
WorkingDirectory=/usr/share/grafana
ExecStart=/usr/sbin/grafana-server \
--config=${CONF_FILE} \
--pidfile=${PID_FILE
}
\
cfg:default.paths.logs=${LOG_DIR} \
cfg:default.paths.data=${DATA_DIR} \
ExecStart=/usr/sbin/grafana-server
\
--config=${CONF_FILE}
\
--pidfile=${PID_FILE
_DIR}/grafana-server.pid
\
cfg:default.paths.logs=${LOG_DIR}
\
cfg:default.paths.data=${DATA_DIR}
\
cfg:default.paths.plugins=${PLUGINS_DIR}
LimitNOFILE=10000
TimeoutStopSec=20
...
...
pkg/cmd/grafana-server/main.go
View file @
c3cffeb1
...
...
@@ -3,10 +3,8 @@ package main
import
(
"flag"
"fmt"
"io/ioutil"
"os"
"os/signal"
"path/filepath"
"runtime"
"runtime/trace"
"strconv"
...
...
@@ -16,7 +14,6 @@ import (
"net/http"
_
"net/http/pprof"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
...
...
@@ -87,46 +84,11 @@ func main() {
server
.
Start
()
}
func
initRuntime
()
{
err
:=
setting
.
NewConfigContext
(
&
setting
.
CommandLineArgs
{
Config
:
*
configFile
,
HomePath
:
*
homePath
,
Args
:
flag
.
Args
(),
})
if
err
!=
nil
{
log
.
Fatal
(
3
,
err
.
Error
())
}
logger
:=
log
.
New
(
"main"
)
logger
.
Info
(
"Starting Grafana"
,
"version"
,
version
,
"commit"
,
commit
,
"compiled"
,
time
.
Unix
(
setting
.
BuildStamp
,
0
))
setting
.
LogConfigurationInfo
()
}
func
initSql
()
{
sqlstore
.
NewEngine
()
sqlstore
.
EnsureAdminUser
()
}
func
writePIDFile
()
{
if
*
pidFile
==
""
{
return
}
// Ensure the required directory structure exists.
err
:=
os
.
MkdirAll
(
filepath
.
Dir
(
*
pidFile
),
0700
)
if
err
!=
nil
{
log
.
Fatal
(
3
,
"Failed to verify pid directory"
,
err
)
}
// Retrieve the PID and write it.
pid
:=
strconv
.
Itoa
(
os
.
Getpid
())
if
err
:=
ioutil
.
WriteFile
(
*
pidFile
,
[]
byte
(
pid
),
0644
);
err
!=
nil
{
log
.
Fatal
(
3
,
"Failed to write pidfile"
,
err
)
}
}
func
listenToSystemSignals
(
server
models
.
GrafanaServer
)
{
signalChan
:=
make
(
chan
os
.
Signal
,
1
)
ignoreChan
:=
make
(
chan
os
.
Signal
,
1
)
...
...
pkg/cmd/grafana-server/server.go
View file @
c3cffeb1
...
...
@@ -2,7 +2,12 @@ package main
import
(
"context"
"flag"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"time"
"golang.org/x/sync/errgroup"
...
...
@@ -45,8 +50,9 @@ type GrafanaServerImpl struct {
func
(
g
*
GrafanaServerImpl
)
Start
()
{
go
listenToSystemSignals
(
g
)
writePIDFile
()
initRuntime
()
g
.
initLogging
()
g
.
writePIDFile
()
initSql
()
metrics
.
Init
()
search
.
Init
()
...
...
@@ -74,6 +80,22 @@ func (g *GrafanaServerImpl) Start() {
g
.
startHttpServer
()
}
func
(
g
*
GrafanaServerImpl
)
initLogging
()
{
err
:=
setting
.
NewConfigContext
(
&
setting
.
CommandLineArgs
{
Config
:
*
configFile
,
HomePath
:
*
homePath
,
Args
:
flag
.
Args
(),
})
if
err
!=
nil
{
g
.
log
.
Error
(
err
.
Error
())
os
.
Exit
(
1
)
}
g
.
log
.
Info
(
"Starting Grafana"
,
"version"
,
version
,
"commit"
,
commit
,
"compiled"
,
time
.
Unix
(
setting
.
BuildStamp
,
0
))
setting
.
LogConfigurationInfo
()
}
func
(
g
*
GrafanaServerImpl
)
startHttpServer
()
{
g
.
httpServer
=
api
.
NewHttpServer
()
...
...
@@ -101,3 +123,23 @@ func (g *GrafanaServerImpl) Shutdown(code int, reason string) {
log
.
Close
()
os
.
Exit
(
code
)
}
func
(
g
*
GrafanaServerImpl
)
writePIDFile
()
{
if
*
pidFile
==
""
{
return
}
// Ensure the required directory structure exists.
err
:=
os
.
MkdirAll
(
filepath
.
Dir
(
*
pidFile
),
0700
)
if
err
!=
nil
{
g
.
log
.
Error
(
"Failed to verify pid directory"
,
"error"
,
err
)
os
.
Exit
(
1
)
}
// Retrieve the PID and write it.
pid
:=
strconv
.
Itoa
(
os
.
Getpid
())
if
err
:=
ioutil
.
WriteFile
(
*
pidFile
,
[]
byte
(
pid
),
0644
);
err
!=
nil
{
g
.
log
.
Error
(
"Failed to write pidfile"
,
"error"
,
err
)
os
.
Exit
(
1
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment