diff --git a/configs/bedrock.conf b/configs/bedrock.conf new file mode 100644 index 000000000..ea2cfee81 --- /dev/null +++ b/configs/bedrock.conf @@ -0,0 +1,28 @@ +# 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" + +# If running a cluster, these values need to be different for each node. +THISNODE="bedrock" +PRIORITY=200 + +# 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" + +# Number of worker threads. Default: # of CPUs on the system. +# WORKER_THREADS="-workerThreads 1" + +# Select which plugins to run. Default: db,jobs,cache +# PLUGINS="-plugins db,jobs,cache" + +# If running a cluster, uncomment to enable. +# 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.init b/configs/bedrock.init index 7a6e3aa99..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 -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 $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 diff --git a/configs/bedrock.service b/configs/bedrock.service new file mode 100644 index 000000000..7be66e993 --- /dev/null +++ b/configs/bedrock.service @@ -0,0 +1,31 @@ +[Unit] +Description=Expensify Bedrock Server +Documentation=http://bedrockdb.com/ +After=network.target + +# The following creates the database file if absent +After=bedrock_prerequisites.service +Requires=bedrock_prerequisites.service + +[Service] +EnvironmentFile=/etc/bedrock/bedrock.conf +PIDFile=/var/run/bedrock.pid + +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} \ + ${PLUGINS} \ + ${WORKER_THREADS} \ + ${CACHE_SIZE} \ + ${PEER_LIST} \ + ${LOG_LEVEL} + +ExecStop=/bin/kill -TERM $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}"' 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"); 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);