From 5cad73e3c297a43ce038bd1ee7ba5948d3180d58 Mon Sep 17 00:00:00 2001 From: Sam Whitney Date: Tue, 30 Jan 2018 15:45:49 -0600 Subject: [PATCH 1/8] Add bedrock configuration files for Ubuntu Xenial --- configs/bedrock.conf | 23 +++++++++++++++++++++++ configs/bedrock.service | 25 +++++++++++++++++++++++++ configs/bedrock_prerequisites.service | 11 +++++++++++ 3 files changed, 59 insertions(+) create mode 100644 configs/bedrock.conf create mode 100644 configs/bedrock.service create mode 100644 configs/bedrock_prerequisites.service diff --git a/configs/bedrock.conf b/configs/bedrock.conf new file mode 100644 index 000000000..f1895bf79 --- /dev/null +++ b/configs/bedrock.conf @@ -0,0 +1,23 @@ +# Bedrock default config file. +# Run `bedrock -?` for help with command line arguments + +# Path of db file; will be created if absent +BEDROCK_DB_PATH="/var/lib/bedrock/bedrock.db" + +# Single node, unknown environment +THISNODE="bedrock" +PRIORITY=200 + +# Cache size in kilobytes +CACHE_SIZE="10001" + +VERBOSE="-v" + +# Bind to network address +SERVER_HOST="0.0.0.0:8888" +NODE_HOST="0.0.0.0:8889" + +EXTRA_FLAGS="-readThreads 1 -plugins status,db,jobs,cache" + +# If running a cluster, uncomment to enable. +# PEERS="-peerList node1,node2" diff --git a/configs/bedrock.service b/configs/bedrock.service new file mode 100644 index 000000000..66d7be9d3 --- /dev/null +++ b/configs/bedrock.service @@ -0,0 +1,25 @@ +[Unit] +Description=Expensify Bedrock Server +Documentation=http://bedrockdb.com/ +After=network.target + +# The following creates database file if absent +After=bedrock_prerequisites.service +Requires=bedrock_prerequisites.service + +[Service] +EnvironmentFile=/etc/bedrock/bedrock.conf +PIDFile=/var/run/bedrock.pid + +Type=simple + +ExecStart=/usr/sbin/bedrock \ + -nodeName ${THISNODE} \ + -db ${BEDROCK_DB_PATH} \ + -serverHost ${SERVER_HOST} \ + -nodeHost ${NODE_HOST} \ + -priority ${PRIORITY} \ + -cache ${CACHE_SIZE} \ + ${VERBOSE} ${PEERS} $EXTRA_FLAGS +ExecStop=/bin/kill -HUP $MAINPID +KillMode=process diff --git a/configs/bedrock_prerequisites.service b/configs/bedrock_prerequisites.service new file mode 100644 index 000000000..0b749c408 --- /dev/null +++ b/configs/bedrock_prerequisites.service @@ -0,0 +1,11 @@ +[Unit] +Description=Generates prerequisite files for bedrock.service, if absent +Documentation=http://bedrockdb.com/ + +[Service] +Type=oneshot +EnvironmentFile=/etc/bedrock/bedrock.conf + +# The following creates database dir and database file +ExecStart=/bin/sh -c 'mkdir -p "$(dirname "${BEDROCK_DB_PATH}")"' +ExecStart=/bin/sh -c 'test -f "${BEDROCK_DB_PATH}" || touch "${BEDROCK_DB_PATH}"' From a3edd4a65c50dd722d15f2f8e23657232ff201f0 Mon Sep 17 00:00:00 2001 From: Sam Whitney Date: Tue, 30 Jan 2018 17:57:00 -0600 Subject: [PATCH 2/8] Comment out extra args --- configs/bedrock.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/bedrock.conf b/configs/bedrock.conf index f1895bf79..61abc1699 100644 --- a/configs/bedrock.conf +++ b/configs/bedrock.conf @@ -17,7 +17,7 @@ VERBOSE="-v" SERVER_HOST="0.0.0.0:8888" NODE_HOST="0.0.0.0:8889" -EXTRA_FLAGS="-readThreads 1 -plugins status,db,jobs,cache" +#EXTRA_FLAGS="-readThreads 1 -plugins db,jobs,cache,mysql" # If running a cluster, uncomment to enable. # PEERS="-peerList node1,node2" From 2aa37c83c274e06c033656b9dda5eaa6199629c4 Mon Sep 17 00:00:00 2001 From: Sam Whitney Date: Wed, 31 Jan 2018 17:19:49 -0600 Subject: [PATCH 3/8] Bedrock Xenial conf improvements --- configs/bedrock.conf | 17 +++++++++++------ configs/bedrock.service | 16 +++++++++++----- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/configs/bedrock.conf b/configs/bedrock.conf index 61abc1699..f866b383b 100644 --- a/configs/bedrock.conf +++ b/configs/bedrock.conf @@ -8,16 +8,21 @@ BEDROCK_DB_PATH="/var/lib/bedrock/bedrock.db" THISNODE="bedrock" PRIORITY=200 -# Cache size in kilobytes -CACHE_SIZE="10001" - -VERBOSE="-v" +# Cache size in kilobytes. Default: 1GB +CACHE_SIZE="-cacheSize 10000" # Bind to network address SERVER_HOST="0.0.0.0:8888" NODE_HOST="0.0.0.0:8889" -#EXTRA_FLAGS="-readThreads 1 -plugins db,jobs,cache,mysql" +# Number of worker threads. Default: # of CPUs on the system. +WORKER_THREADS="-workerThreads 2" + +# Select which plugins to run. Default: db,jobs,cache +# PLUGINS="-plugins db,jobs,cache" # If running a cluster, uncomment to enable. -# PEERS="-peerList node1,node2" +# PEER_LIST="-peerList node1,node2" + +# Use '-v' for verbose or '-q' for quiet. Omit this option for standard log level. +# LOG_LEVEL="-v" diff --git a/configs/bedrock.service b/configs/bedrock.service index 66d7be9d3..7be66e993 100644 --- a/configs/bedrock.service +++ b/configs/bedrock.service @@ -3,7 +3,7 @@ Description=Expensify Bedrock Server Documentation=http://bedrockdb.com/ After=network.target -# The following creates database file if absent +# The following creates the database file if absent After=bedrock_prerequisites.service Requires=bedrock_prerequisites.service @@ -11,15 +11,21 @@ Requires=bedrock_prerequisites.service EnvironmentFile=/etc/bedrock/bedrock.conf PIDFile=/var/run/bedrock.pid -Type=simple +Type=forking ExecStart=/usr/sbin/bedrock \ + -fork \ + -pidFile /var/run/bedrock.pid \ -nodeName ${THISNODE} \ -db ${BEDROCK_DB_PATH} \ -serverHost ${SERVER_HOST} \ -nodeHost ${NODE_HOST} \ -priority ${PRIORITY} \ - -cache ${CACHE_SIZE} \ - ${VERBOSE} ${PEERS} $EXTRA_FLAGS -ExecStop=/bin/kill -HUP $MAINPID + ${PLUGINS} \ + ${WORKER_THREADS} \ + ${CACHE_SIZE} \ + ${PEER_LIST} \ + ${LOG_LEVEL} + +ExecStop=/bin/kill -TERM $MAINPID KillMode=process From 522e696b3f6249f18be2bd5754851f304afa5fad Mon Sep 17 00:00:00 2001 From: Sam Whitney Date: Wed, 31 Jan 2018 17:21:52 -0600 Subject: [PATCH 4/8] Update comments --- configs/bedrock.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configs/bedrock.conf b/configs/bedrock.conf index f866b383b..910e9b92c 100644 --- a/configs/bedrock.conf +++ b/configs/bedrock.conf @@ -4,7 +4,7 @@ # Path of db file; will be created if absent BEDROCK_DB_PATH="/var/lib/bedrock/bedrock.db" -# Single node, unknown environment +# If running a cluster, these values need to be different for each node. THISNODE="bedrock" PRIORITY=200 @@ -16,7 +16,7 @@ SERVER_HOST="0.0.0.0:8888" NODE_HOST="0.0.0.0:8889" # Number of worker threads. Default: # of CPUs on the system. -WORKER_THREADS="-workerThreads 2" +WORKER_THREADS="-workerThreads 1" # Select which plugins to run. Default: db,jobs,cache # PLUGINS="-plugins db,jobs,cache" From 8a129f467fd15e021dd401f7bb8911be59072979 Mon Sep 17 00:00:00 2001 From: Sam Whitney Date: Tue, 20 Feb 2018 15:14:41 -0600 Subject: [PATCH 5/8] Fix 14.04 init script --- configs/bedrock.init | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configs/bedrock.init b/configs/bedrock.init index 7a6e3aa99..765c41a3c 100644 --- a/configs/bedrock.init +++ b/configs/bedrock.init @@ -36,7 +36,7 @@ if [ -n "$OTHERNODES" ]; then FLAGS="-peerList $OTHERNODES" fi -DAEMON_OPTS="-fork -nodeName $THISNODE -db $BEDROCK_DB_PATH -serverHost 0.0.0.0:8888 -nodeHost 0.0.0.0:8889 -priority $PRIORITY -pidfile $PIDFILE -quorumCheckpoint 100 -readThreads 4 -plugins status,db,jobs,cache,mysql $FLAGS" +DAEMON_OPTS="-fork -nodeName $THISNODE -db $BEDROCK_DB_PATH -serverHost 0.0.0.0:8888 -nodeHost 0.0.0.0:8889 -priority $PRIORITY -pidfile $PIDFILE -workerThreads 1 $FLAGS" if ! [[ -x $BIN ]]; then echo "$1: Job failed! Missing or broken binary file: $BIN" && exit 2; fi set -e @@ -56,7 +56,7 @@ case "$1" in fi if [ ! -f $BEDROCK_DB_PATH ]; then log_daemon_msg "No db found, creating db." - if ! touch $BEDROCK_DB_PATH; then + if ! touch $BEDROCK_DB_PATH; then log_end_msg 1 else log_end_msg 0 From 578c8dd4bf80363227233c43c92db70c1baf31e3 Mon Sep 17 00:00:00 2001 From: Sam Whitney Date: Wed, 21 Feb 2018 11:08:04 -0600 Subject: [PATCH 6/8] Use default workerThreads values --- configs/bedrock.conf | 2 +- configs/bedrock.init | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configs/bedrock.conf b/configs/bedrock.conf index 910e9b92c..ea2cfee81 100644 --- a/configs/bedrock.conf +++ b/configs/bedrock.conf @@ -16,7 +16,7 @@ SERVER_HOST="0.0.0.0:8888" NODE_HOST="0.0.0.0:8889" # Number of worker threads. Default: # of CPUs on the system. -WORKER_THREADS="-workerThreads 1" +# WORKER_THREADS="-workerThreads 1" # Select which plugins to run. Default: db,jobs,cache # PLUGINS="-plugins db,jobs,cache" diff --git a/configs/bedrock.init b/configs/bedrock.init index 765c41a3c..6d04feced 100644 --- a/configs/bedrock.init +++ b/configs/bedrock.init @@ -36,7 +36,7 @@ if [ -n "$OTHERNODES" ]; then FLAGS="-peerList $OTHERNODES" fi -DAEMON_OPTS="-fork -nodeName $THISNODE -db $BEDROCK_DB_PATH -serverHost 0.0.0.0:8888 -nodeHost 0.0.0.0:8889 -priority $PRIORITY -pidfile $PIDFILE -workerThreads 1 $FLAGS" +DAEMON_OPTS="-fork -nodeName $THISNODE -db $BEDROCK_DB_PATH -serverHost 0.0.0.0:8888 -nodeHost 0.0.0.0:8889 -priority $PRIORITY -pidfile $PIDFILE $FLAGS" if ! [[ -x $BIN ]]; then echo "$1: Job failed! Missing or broken binary file: $BIN" && exit 2; fi set -e From f9fa87c387f4c17360b34273a6f37c8038ae4c55 Mon Sep 17 00:00:00 2001 From: Sam Whitney Date: Wed, 21 Feb 2018 15:23:23 -0600 Subject: [PATCH 7/8] Enable mysql plugin by default --- main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 59b37f1aa..de439e2ce 100644 --- a/main.cpp +++ b/main.cpp @@ -207,7 +207,7 @@ int main(int argc, char* argv[]) { cout << "-nodeHost Listen on this host:port for connections from other nodes" << endl; cout << "-peerList See below" << endl; cout << "-priority See '-peerList Details' below (defaults to 100)" << endl; - cout << "-plugins Enable these plugins (defaults to 'db,jobs,cache')" << endl; + cout << "-plugins Enable these plugins (defaults to 'db,jobs,cache,mysql')" << endl; cout << "-cacheSize number of KB to allocate for a page cache (defaults to 1GB)" << endl; cout << "-workerThreads <#> Number of worker threads to start (min 1, defaults to # of cores)" << endl; cout << "-queryLog Set the query log filename (default 'queryLog.csv', SIGUSR2/SIGQUIT to " @@ -269,7 +269,7 @@ int main(int argc, char* argv[]) { SETDEFAULT("-controlPort", "localhost:9999"); SETDEFAULT("-nodeName", SGetHostName()); SETDEFAULT("-cacheSize", SToStr(1024 * 1024)); // 1024 * 1024KB = 1GB. - SETDEFAULT("-plugins", "db,jobs,cache"); + SETDEFAULT("-plugins", "db,jobs,cache,mysql"); SETDEFAULT("-priority", "100"); SETDEFAULT("-maxJournalSize", "1000000"); SETDEFAULT("-queryLog", "queryLog.csv"); From 225ef1ba0808ab7897dbf8f3acbb9a4bdd4ac360 Mon Sep 17 00:00:00 2001 From: Sam Whitney Date: Thu, 22 Feb 2018 14:04:49 -0600 Subject: [PATCH 8/8] Remove unnecessary warn in MySQL plugin --- plugins/MySQL.h | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/MySQL.h b/plugins/MySQL.h index e0ece18ea..69f46f541 100644 --- a/plugins/MySQL.h +++ b/plugins/MySQL.h @@ -96,7 +96,6 @@ class BedrockPlugin_MySQL : public BedrockPlugin { virtual string getName() { return "MySQL"; } virtual void initialize(const SData& args, BedrockServer& server) { _args = args; } virtual string getPort() { - SWARN("ARGS: " << _args.serialize()); return _args.isSet("-mysql.host") ? _args["-mysql.host"] : "localhost:3306"; } virtual void onPortAccept(STCPManager::Socket* s);