├── .gitignore ├── Dockerfile ├── Makefile ├── README.md ├── build-binary.sh ├── driver-bin └── sphere-serial ├── sphere.sh └── src ├── bin ├── sphere-serial └── start ├── ninja-services ├── mqtt-bridgeify │ └── run ├── sphere-client │ └── run └── sphere-homecloud │ └── run ├── redis.conf └── system-services ├── mosquitto └── run ├── ninjasphere-services └── run └── redis └── run /.gitignore: -------------------------------------------------------------------------------- 1 | /bin-* 2 | /mqtt-bridgeify 3 | /sphere-client 4 | /sphere-config 5 | /sphere-director 6 | /sphere-go-homecloud 7 | /sphere-schemas 8 | /volume-data 9 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM phusion/baseimage:0.9.16 2 | MAINTAINER Theo Julienne 3 | 4 | RUN apt-get update; apt-get install -y mosquitto redis-server 5 | 6 | RUN adduser --disabled-password ninja 7 | 8 | RUN mkdir -p /opt/ninjablocks 9 | 10 | # sphere-client 11 | ADD sphere-client/ninjapack/root/opt/ninjablocks/sphere-client /opt/ninjablocks/sphere-client 12 | ADD bin-linux-amd64/sphere-client /opt/ninjablocks/sphere-client/ 13 | 14 | # sphere-go-homecloud 15 | ADD sphere-go-homecloud/ninjapack/root/opt/ninjablocks/sphere-go-homecloud /opt/ninjablocks/sphere-go-homecloud 16 | ADD bin-linux-amd64/sphere-go-homecloud /opt/ninjablocks/sphere-go-homecloud/ 17 | 18 | # utils 19 | ADD src/bin /opt/ninjablocks/bin 20 | ADD bin-linux-amd64/mqtt-bridgeify /opt/ninjablocks/bin/ 21 | 22 | ADD sphere-config/config /opt/ninjablocks/config 23 | ADD sphere-schemas /opt/ninjablocks/sphere-schemas 24 | 25 | ADD src/system-services /etc/service 26 | ADD src/ninja-services /home/ninja/service 27 | RUN chown -R ninja.ninja /home/ninja/service 28 | 29 | RUN mkdir -p /data/etc/avahi/services /data/etc/opt/ninja 30 | RUN chown -R ninja.ninja /data 31 | 32 | ADD src/redis.conf /etc/redis/redis.conf 33 | 34 | RUN ln -s /opt/ninjablocks/bin/start /usr/sbin/start 35 | 36 | VOLUME ["/data"] 37 | 38 | CMD ["/sbin/my_init"] 39 | ENV PATH="/opt/ninjablocks/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" 40 | ENV NINJA_BOARD_TYPE="sphere" 41 | ENV NINJA_OS_TAG="norelease" 42 | ENV NINJA_OS_BUILD_TARGET="sphere-docker-hacking" 43 | ENV NINJA_OS_BUILD_NAME="ubuntu_docker_trusty_norelease_sphere-hacking" 44 | 45 | EXPOSE 1883 8000 -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: client director homecloud mqtt-bridgeify build 2 | 3 | build: sphere-config sphere-schemas 4 | docker build -t theojulienne/ninjasphere . 5 | 6 | sphere-config: 7 | git clone https://github.com/ninjasphere/sphere-config.git 8 | 9 | sphere-schemas: 10 | git clone https://github.com/ninjasphere/schemas.git sphere-schemas 11 | 12 | client: 13 | bash build-binary.sh ninjasphere/sphere-client 14 | 15 | director: 16 | bash build-binary.sh ninjasphere/sphere-director 17 | 18 | homecloud: 19 | bash build-binary.sh ninjasphere/sphere-go-homecloud 20 | 21 | mqtt-bridgeify: 22 | bash build-binary.sh ninjablocks/mqtt-bridgeify -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ninjasphere-docker 2 | 3 | Runs a small, self-contained and definitely subtly-different-to-a-real-sphere copy of the Ninja Sphere client services. 4 | 5 | Currently only runs on x86_64 Docker, and natively supports boot2docker. 6 | 7 | ## Getting Started 8 | 9 | You'll need docker set up and ready to go. Start by running: 10 | ``` 11 | ./sphere.sh start 12 | ``` 13 | 14 | Subsequent ```start``` calls don't need the serial number, it's saved. Pair the Sphere here: http://api.sphere.ninja/ Note that the IP shown after pairing and the link won't work, but you can verify from the logs that it's paired. 15 | 16 | To get a list of supported commands (they are just simple convenience wrappers around docker): 17 | ``` 18 | ./sphere.sh 19 | ``` 20 | 21 | Most usefully: 22 | ``` 23 | ./sphere.sh logs -f 24 | ``` 25 | 26 | And the convenient wrapper to run a Go driver pointing at the docker instance: 27 | ``` 28 | ..../ninjasphere-docker/sphere.sh run-driver ./driver-awesome [extra driver arguments] 29 | ``` 30 | 31 | ## Complete Driver Example 32 | 33 | A more complete example of getting an entire Go driver into your local Go sources and running it: 34 | ``` 35 | go get github.com/ninjasphere/driver-go-chromecast 36 | cd $GOPATH/src/github.com/ninjasphere/driver-go-chromecast 37 | go build 38 | ..../ninjasphere-docker/sphere.sh run-driver ./driver-go-chromecast 39 | ``` 40 | 41 | ## Data Persistance 42 | 43 | All "user data" will be stored in ```volume-data``` in the current directory - to start fresh, delete this directory. The serial number will be cached across multiple runs, but it's also stored in this directory to make complete resets easier. 44 | 45 | ## Exposed Services 46 | 47 | Ports 1883 (MQTT) and 8000 (HomeCloud REST) are exposed from the container (and the sphere.sh script publishes them for you too). 48 | 49 | REST services can be accessed at for example: 50 | ``` 51 | http://your_docker_host_ip:8000/rest/v1/things 52 | ``` 53 | 54 | MQTT can be sniffed using the mosquitto client tools (available as part of homebrew's mosquitto install and ```mosquitto-clients``` on Ubuntu): 55 | ``` 56 | mosquitto_sub -t '#' -v -h your_docker_host_ip 57 | ``` 58 | 59 | ## Missing Services & Errata 60 | 61 | * Drivers are not included, and homecloud will mutter a bit about them being restarted 62 | * Sphere Director (the driver/process manager) is not yet installed 63 | 64 | ## Building 65 | 66 | At the time of writing, some of the repositories used to build this are still private, so external users won't be able to build a new copy of the docker image. Once the repositories are public I'll update the scripts so they work without GitHub authentication. -------------------------------------------------------------------------------- /build-binary.sh: -------------------------------------------------------------------------------- 1 | 2 | REPO=$1 3 | DIR=$(basename $REPO) 4 | 5 | if [ ! -d $DIR ]; then 6 | git clone git@github.com:${REPO}.git $DIR 7 | fi 8 | 9 | pushd $DIR 10 | git pull 11 | popd 12 | 13 | PLATFORMS="linux/amd64" 14 | 15 | for PLATFORM in $PLATFORMS; do 16 | export GOOS=${PLATFORM%/*} 17 | export GOARCH=${PLATFORM#*/} 18 | 19 | pushd $DIR 20 | ./scripts/build.sh 21 | popd 22 | mkdir -p bin-$GOOS-$GOARCH 23 | cp $DIR/bin/* bin-$GOOS-$GOARCH/ 24 | done 25 | 26 | -------------------------------------------------------------------------------- /driver-bin/sphere-serial: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cat $(dirname $0)/../volume-data/sphere-serial.conf -------------------------------------------------------------------------------- /sphere.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | NINJA_SERIAL=$2 4 | 5 | SCRIPT_PATH=$(cd $(dirname $0); pwd) 6 | 7 | start() { 8 | if [[ $NINJA_SERIAL == "" ]]; then 9 | if [ -f volume-data/sphere-serial.conf ]; then 10 | NINJA_SERIAL=$(cat volume-data/sphere-serial.conf) 11 | fi 12 | fi 13 | 14 | if [[ $NINJA_SERIAL == "" ]]; then 15 | echo "Serial number must be specified the first time: $0 start " 16 | exit 1 17 | fi 18 | 19 | mkdir -p volume-data 20 | echo -n "$NINJA_SERIAL" > volume-data/sphere-serial.conf 21 | 22 | docker run -d -it \ 23 | -v $(pwd)/volume-data:/data \ 24 | --env NINJA_SERIAL=$NINJA_SERIAL \ 25 | --name=ninjasphere \ 26 | -p 1883:1883 -p 8000:8000 \ 27 | theojulienne/ninjasphere 28 | 29 | echo 'Sphere service launched.' 30 | } 31 | 32 | stop() { 33 | docker kill ninjasphere 34 | docker rm ninjasphere 35 | } 36 | 37 | ps() { 38 | docker exec ninjasphere ps aux 39 | } 40 | 41 | interact() { 42 | docker exec -it ninjasphere bash 43 | } 44 | 45 | logs() { 46 | docker $@ ninjasphere 47 | } 48 | 49 | run-driver() { 50 | export sphere_installDirectory=$SCRIPT_PATH 51 | export PATH=$PATH:$SCRIPT_PATH/driver-bin 52 | 53 | if [[ "$1" == "" ]]; then 54 | echo "You must specify the path to the driver" 55 | exit 1 56 | fi 57 | 58 | MQTT_HOST=127.0.0.1 59 | 60 | if which boot2docker >/dev/null; then 61 | MQTT_HOST=$(boot2docker ip 2>/dev/null) 62 | fi 63 | 64 | $@ --mqtt.host=$MQTT_HOST --mqtt.port=1883 65 | } 66 | 67 | case "$1" in 68 | start) 69 | start 70 | ;; 71 | stop) 72 | stop 73 | ;; 74 | ps) 75 | ps 76 | ;; 77 | shell) 78 | interact 79 | ;; 80 | logs) 81 | logs $@ 82 | ;; 83 | run-driver) 84 | run-driver $2 85 | ;; 86 | *) 87 | echo "Usage: $0 start [serial] -- start the sphere stack, serial must be specified the first time" 88 | echo " $0 stop -- stop the sphere stack" 89 | echo " $0 ps -- 'ps aux' inside the container" 90 | echo " $0 shell -- 'bash' inside the container" 91 | echo " $0 logs [-f] -- show (or follow) the logs" 92 | exit 1 93 | esac 94 | 95 | -------------------------------------------------------------------------------- /src/bin/sphere-serial: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo -n ${NINJA_SERIAL} -------------------------------------------------------------------------------- /src/bin/start: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sv start /home/ninja/service/$1 -------------------------------------------------------------------------------- /src/ninja-services/mqtt-bridgeify/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | exec /opt/ninjablocks/bin/mqtt-bridgeify agent -serial=$(sphere-serial) -------------------------------------------------------------------------------- /src/ninja-services/sphere-client/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sv start /home/ninja/service/mqtt-bridgeify || exit 1 4 | 5 | # make sure sphere-homecloud is NOT running until we later turn it on 6 | sv stop /home/ninja/service/sphere-homecloud 7 | 8 | mkdir -p /data/etc/avahi/services /data/etc/opt/ninja 9 | chown -R ninja.ninja /data 10 | 11 | cd /opt/ninjablocks/sphere-client 12 | exec /opt/ninjablocks/sphere-client/sphere-client --cloud-production 13 | -------------------------------------------------------------------------------- /src/ninja-services/sphere-homecloud/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # make sure sphere-client starts first 4 | sv start /home/ninja/service/sphere-client || exit 1 5 | 6 | cd /opt/ninjablocks/sphere-go-homecloud 7 | exec /opt/ninjablocks/sphere-go-homecloud/sphere-go-homecloud 8 | -------------------------------------------------------------------------------- /src/redis.conf: -------------------------------------------------------------------------------- 1 | # Redis configuration file example 2 | 3 | # Note on units: when memory size is needed, it is possible to specify 4 | # it in the usual form of 1k 5GB 4M and so forth: 5 | # 6 | # 1k => 1000 bytes 7 | # 1kb => 1024 bytes 8 | # 1m => 1000000 bytes 9 | # 1mb => 1024*1024 bytes 10 | # 1g => 1000000000 bytes 11 | # 1gb => 1024*1024*1024 bytes 12 | # 13 | # units are case insensitive so 1GB 1Gb 1gB are all the same. 14 | 15 | ################################## INCLUDES ################################### 16 | 17 | # Include one or more other config files here. This is useful if you 18 | # have a standard template that goes to all Redis server but also need 19 | # to customize a few per-server settings. Include files can include 20 | # other files, so use this wisely. 21 | # 22 | # Notice option "include" won't be rewritten by command "CONFIG REWRITE" 23 | # from admin or Redis Sentinel. Since Redis always uses the last processed 24 | # line as value of a configuration directive, you'd better put includes 25 | # at the beginning of this file to avoid overwriting config change at runtime. 26 | # 27 | # If instead you are interested in using includes to override configuration 28 | # options, it is better to use include as the last line. 29 | # 30 | # include /path/to/local.conf 31 | # include /path/to/other.conf 32 | 33 | ################################ GENERAL ##################################### 34 | 35 | # By default Redis does not run as a daemon. Use 'yes' if you need it. 36 | # Note that Redis will write a pid file in /var/run/redis.pid when daemonized. 37 | daemonize no 38 | 39 | # When running daemonized, Redis writes a pid file in /var/run/redis.pid by 40 | # default. You can specify a custom pid file location here. 41 | pidfile /var/run/redis/redis-server.pid 42 | 43 | # Accept connections on the specified port, default is 6379. 44 | # If port 0 is specified Redis will not listen on a TCP socket. 45 | port 6379 46 | 47 | # By default Redis listens for connections from all the network interfaces 48 | # available on the server. It is possible to listen to just one or multiple 49 | # interfaces using the "bind" configuration directive, followed by one or 50 | # more IP addresses. 51 | # 52 | # Examples: 53 | # 54 | # bind 192.168.1.100 10.0.0.1 55 | bind 127.0.0.1 56 | 57 | # Specify the path for the unix socket that will be used to listen for 58 | # incoming connections. There is no default, so Redis will not listen 59 | # on a unix socket when not specified. 60 | # 61 | # unixsocket /var/run/redis/redis.sock 62 | # unixsocketperm 755 63 | 64 | # Close the connection after a client is idle for N seconds (0 to disable) 65 | timeout 0 66 | 67 | # TCP keepalive. 68 | # 69 | # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence 70 | # of communication. This is useful for two reasons: 71 | # 72 | # 1) Detect dead peers. 73 | # 2) Take the connection alive from the point of view of network 74 | # equipment in the middle. 75 | # 76 | # On Linux, the specified value (in seconds) is the period used to send ACKs. 77 | # Note that to close the connection the double of the time is needed. 78 | # On other kernels the period depends on the kernel configuration. 79 | # 80 | # A reasonable value for this option is 60 seconds. 81 | tcp-keepalive 0 82 | 83 | # Specify the server verbosity level. 84 | # This can be one of: 85 | # debug (a lot of information, useful for development/testing) 86 | # verbose (many rarely useful info, but not a mess like the debug level) 87 | # notice (moderately verbose, what you want in production probably) 88 | # warning (only very important / critical messages are logged) 89 | loglevel notice 90 | 91 | # Specify the log file name. Also the empty string can be used to force 92 | # Redis to log on the standard output. Note that if you use standard 93 | # output for logging but daemonize, logs will be sent to /dev/null 94 | logfile "" 95 | 96 | # To enable logging to the system logger, just set 'syslog-enabled' to yes, 97 | # and optionally update the other syslog parameters to suit your needs. 98 | # syslog-enabled no 99 | 100 | # Specify the syslog identity. 101 | # syslog-ident redis 102 | 103 | # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7. 104 | # syslog-facility local0 105 | 106 | # Set the number of databases. The default database is DB 0, you can select 107 | # a different one on a per-connection basis using SELECT where 108 | # dbid is a number between 0 and 'databases'-1 109 | databases 16 110 | 111 | ################################ SNAPSHOTTING ################################ 112 | # 113 | # Save the DB on disk: 114 | # 115 | # save 116 | # 117 | # Will save the DB if both the given number of seconds and the given 118 | # number of write operations against the DB occurred. 119 | # 120 | # In the example below the behaviour will be to save: 121 | # after 900 sec (15 min) if at least 1 key changed 122 | # after 300 sec (5 min) if at least 10 keys changed 123 | # after 60 sec if at least 10000 keys changed 124 | # 125 | # Note: you can disable saving at all commenting all the "save" lines. 126 | # 127 | # It is also possible to remove all the previously configured save 128 | # points by adding a save directive with a single empty string argument 129 | # like in the following example: 130 | # 131 | # save "" 132 | 133 | save 900 1 134 | save 300 10 135 | save 60 10000 136 | 137 | # By default Redis will stop accepting writes if RDB snapshots are enabled 138 | # (at least one save point) and the latest background save failed. 139 | # This will make the user aware (in a hard way) that data is not persisting 140 | # on disk properly, otherwise chances are that no one will notice and some 141 | # disaster will happen. 142 | # 143 | # If the background saving process will start working again Redis will 144 | # automatically allow writes again. 145 | # 146 | # However if you have setup your proper monitoring of the Redis server 147 | # and persistence, you may want to disable this feature so that Redis will 148 | # continue to work as usual even if there are problems with disk, 149 | # permissions, and so forth. 150 | stop-writes-on-bgsave-error yes 151 | 152 | # Compress string objects using LZF when dump .rdb databases? 153 | # For default that's set to 'yes' as it's almost always a win. 154 | # If you want to save some CPU in the saving child set it to 'no' but 155 | # the dataset will likely be bigger if you have compressible values or keys. 156 | rdbcompression yes 157 | 158 | # Since version 5 of RDB a CRC64 checksum is placed at the end of the file. 159 | # This makes the format more resistant to corruption but there is a performance 160 | # hit to pay (around 10%) when saving and loading RDB files, so you can disable it 161 | # for maximum performances. 162 | # 163 | # RDB files created with checksum disabled have a checksum of zero that will 164 | # tell the loading code to skip the check. 165 | rdbchecksum yes 166 | 167 | # The filename where to dump the DB 168 | dbfilename dump.rdb 169 | 170 | # The working directory. 171 | # 172 | # The DB will be written inside this directory, with the filename specified 173 | # above using the 'dbfilename' configuration directive. 174 | # 175 | # The Append Only File will also be created inside this directory. 176 | # 177 | # Note that you must specify a directory here, not a file name. 178 | dir /data 179 | 180 | ################################# REPLICATION ################################# 181 | 182 | # Master-Slave replication. Use slaveof to make a Redis instance a copy of 183 | # another Redis server. Note that the configuration is local to the slave 184 | # so for example it is possible to configure the slave to save the DB with a 185 | # different interval, or to listen to another port, and so on. 186 | # 187 | # slaveof 188 | 189 | # If the master is password protected (using the "requirepass" configuration 190 | # directive below) it is possible to tell the slave to authenticate before 191 | # starting the replication synchronization process, otherwise the master will 192 | # refuse the slave request. 193 | # 194 | # masterauth 195 | 196 | # When a slave loses its connection with the master, or when the replication 197 | # is still in progress, the slave can act in two different ways: 198 | # 199 | # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will 200 | # still reply to client requests, possibly with out of date data, or the 201 | # data set may just be empty if this is the first synchronization. 202 | # 203 | # 2) if slave-serve-stale-data is set to 'no' the slave will reply with 204 | # an error "SYNC with master in progress" to all the kind of commands 205 | # but to INFO and SLAVEOF. 206 | # 207 | slave-serve-stale-data yes 208 | 209 | # You can configure a slave instance to accept writes or not. Writing against 210 | # a slave instance may be useful to store some ephemeral data (because data 211 | # written on a slave will be easily deleted after resync with the master) but 212 | # may also cause problems if clients are writing to it because of a 213 | # misconfiguration. 214 | # 215 | # Since Redis 2.6 by default slaves are read-only. 216 | # 217 | # Note: read only slaves are not designed to be exposed to untrusted clients 218 | # on the internet. It's just a protection layer against misuse of the instance. 219 | # Still a read only slave exports by default all the administrative commands 220 | # such as CONFIG, DEBUG, and so forth. To a limited extent you can improve 221 | # security of read only slaves using 'rename-command' to shadow all the 222 | # administrative / dangerous commands. 223 | slave-read-only yes 224 | 225 | # Slaves send PINGs to server in a predefined interval. It's possible to change 226 | # this interval with the repl_ping_slave_period option. The default value is 10 227 | # seconds. 228 | # 229 | # repl-ping-slave-period 10 230 | 231 | # The following option sets the replication timeout for: 232 | # 233 | # 1) Bulk transfer I/O during SYNC, from the point of view of slave. 234 | # 2) Master timeout from the point of view of slaves (data, pings). 235 | # 3) Slave timeout from the point of view of masters (REPLCONF ACK pings). 236 | # 237 | # It is important to make sure that this value is greater than the value 238 | # specified for repl-ping-slave-period otherwise a timeout will be detected 239 | # every time there is low traffic between the master and the slave. 240 | # 241 | # repl-timeout 60 242 | 243 | # Disable TCP_NODELAY on the slave socket after SYNC? 244 | # 245 | # If you select "yes" Redis will use a smaller number of TCP packets and 246 | # less bandwidth to send data to slaves. But this can add a delay for 247 | # the data to appear on the slave side, up to 40 milliseconds with 248 | # Linux kernels using a default configuration. 249 | # 250 | # If you select "no" the delay for data to appear on the slave side will 251 | # be reduced but more bandwidth will be used for replication. 252 | # 253 | # By default we optimize for low latency, but in very high traffic conditions 254 | # or when the master and slaves are many hops away, turning this to "yes" may 255 | # be a good idea. 256 | repl-disable-tcp-nodelay no 257 | 258 | # Set the replication backlog size. The backlog is a buffer that accumulates 259 | # slave data when slaves are disconnected for some time, so that when a slave 260 | # wants to reconnect again, often a full resync is not needed, but a partial 261 | # resync is enough, just passing the portion of data the slave missed while 262 | # disconnected. 263 | # 264 | # The biggest the replication backlog, the longer the time the slave can be 265 | # disconnected and later be able to perform a partial resynchronization. 266 | # 267 | # The backlog is only allocated once there is at least a slave connected. 268 | # 269 | # repl-backlog-size 1mb 270 | 271 | # After a master has no longer connected slaves for some time, the backlog 272 | # will be freed. The following option configures the amount of seconds that 273 | # need to elapse, starting from the time the last slave disconnected, for 274 | # the backlog buffer to be freed. 275 | # 276 | # A value of 0 means to never release the backlog. 277 | # 278 | # repl-backlog-ttl 3600 279 | 280 | # The slave priority is an integer number published by Redis in the INFO output. 281 | # It is used by Redis Sentinel in order to select a slave to promote into a 282 | # master if the master is no longer working correctly. 283 | # 284 | # A slave with a low priority number is considered better for promotion, so 285 | # for instance if there are three slaves with priority 10, 100, 25 Sentinel will 286 | # pick the one with priority 10, that is the lowest. 287 | # 288 | # However a special priority of 0 marks the slave as not able to perform the 289 | # role of master, so a slave with priority of 0 will never be selected by 290 | # Redis Sentinel for promotion. 291 | # 292 | # By default the priority is 100. 293 | slave-priority 100 294 | 295 | # It is possible for a master to stop accepting writes if there are less than 296 | # N slaves connected, having a lag less or equal than M seconds. 297 | # 298 | # The N slaves need to be in "online" state. 299 | # 300 | # The lag in seconds, that must be <= the specified value, is calculated from 301 | # the last ping received from the slave, that is usually sent every second. 302 | # 303 | # This option does not GUARANTEES that N replicas will accept the write, but 304 | # will limit the window of exposure for lost writes in case not enough slaves 305 | # are available, to the specified number of seconds. 306 | # 307 | # For example to require at least 3 slaves with a lag <= 10 seconds use: 308 | # 309 | # min-slaves-to-write 3 310 | # min-slaves-max-lag 10 311 | # 312 | # Setting one or the other to 0 disables the feature. 313 | # 314 | # By default min-slaves-to-write is set to 0 (feature disabled) and 315 | # min-slaves-max-lag is set to 10. 316 | 317 | ################################## SECURITY ################################### 318 | 319 | # Require clients to issue AUTH before processing any other 320 | # commands. This might be useful in environments in which you do not trust 321 | # others with access to the host running redis-server. 322 | # 323 | # This should stay commented out for backward compatibility and because most 324 | # people do not need auth (e.g. they run their own servers). 325 | # 326 | # Warning: since Redis is pretty fast an outside user can try up to 327 | # 150k passwords per second against a good box. This means that you should 328 | # use a very strong password otherwise it will be very easy to break. 329 | # 330 | # requirepass foobared 331 | 332 | # Command renaming. 333 | # 334 | # It is possible to change the name of dangerous commands in a shared 335 | # environment. For instance the CONFIG command may be renamed into something 336 | # hard to guess so that it will still be available for internal-use tools 337 | # but not available for general clients. 338 | # 339 | # Example: 340 | # 341 | # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52 342 | # 343 | # It is also possible to completely kill a command by renaming it into 344 | # an empty string: 345 | # 346 | # rename-command CONFIG "" 347 | # 348 | # Please note that changing the name of commands that are logged into the 349 | # AOF file or transmitted to slaves may cause problems. 350 | 351 | ################################### LIMITS #################################### 352 | 353 | # Set the max number of connected clients at the same time. By default 354 | # this limit is set to 10000 clients, however if the Redis server is not 355 | # able to configure the process file limit to allow for the specified limit 356 | # the max number of allowed clients is set to the current file limit 357 | # minus 32 (as Redis reserves a few file descriptors for internal uses). 358 | # 359 | # Once the limit is reached Redis will close all the new connections sending 360 | # an error 'max number of clients reached'. 361 | # 362 | # maxclients 10000 363 | 364 | # Don't use more memory than the specified amount of bytes. 365 | # When the memory limit is reached Redis will try to remove keys 366 | # according to the eviction policy selected (see maxmemory-policy). 367 | # 368 | # If Redis can't remove keys according to the policy, or if the policy is 369 | # set to 'noeviction', Redis will start to reply with errors to commands 370 | # that would use more memory, like SET, LPUSH, and so on, and will continue 371 | # to reply to read-only commands like GET. 372 | # 373 | # This option is usually useful when using Redis as an LRU cache, or to set 374 | # a hard memory limit for an instance (using the 'noeviction' policy). 375 | # 376 | # WARNING: If you have slaves attached to an instance with maxmemory on, 377 | # the size of the output buffers needed to feed the slaves are subtracted 378 | # from the used memory count, so that network problems / resyncs will 379 | # not trigger a loop where keys are evicted, and in turn the output 380 | # buffer of slaves is full with DELs of keys evicted triggering the deletion 381 | # of more keys, and so forth until the database is completely emptied. 382 | # 383 | # In short... if you have slaves attached it is suggested that you set a lower 384 | # limit for maxmemory so that there is some free RAM on the system for slave 385 | # output buffers (but this is not needed if the policy is 'noeviction'). 386 | # 387 | # maxmemory 388 | 389 | # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory 390 | # is reached. You can select among five behaviors: 391 | # 392 | # volatile-lru -> remove the key with an expire set using an LRU algorithm 393 | # allkeys-lru -> remove any key accordingly to the LRU algorithm 394 | # volatile-random -> remove a random key with an expire set 395 | # allkeys-random -> remove a random key, any key 396 | # volatile-ttl -> remove the key with the nearest expire time (minor TTL) 397 | # noeviction -> don't expire at all, just return an error on write operations 398 | # 399 | # Note: with any of the above policies, Redis will return an error on write 400 | # operations, when there are not suitable keys for eviction. 401 | # 402 | # At the date of writing this commands are: set setnx setex append 403 | # incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd 404 | # sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby 405 | # zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby 406 | # getset mset msetnx exec sort 407 | # 408 | # The default is: 409 | # 410 | # maxmemory-policy volatile-lru 411 | 412 | # LRU and minimal TTL algorithms are not precise algorithms but approximated 413 | # algorithms (in order to save memory), so you can select as well the sample 414 | # size to check. For instance for default Redis will check three keys and 415 | # pick the one that was used less recently, you can change the sample size 416 | # using the following configuration directive. 417 | # 418 | # maxmemory-samples 3 419 | 420 | ############################## APPEND ONLY MODE ############################### 421 | 422 | # By default Redis asynchronously dumps the dataset on disk. This mode is 423 | # good enough in many applications, but an issue with the Redis process or 424 | # a power outage may result into a few minutes of writes lost (depending on 425 | # the configured save points). 426 | # 427 | # The Append Only File is an alternative persistence mode that provides 428 | # much better durability. For instance using the default data fsync policy 429 | # (see later in the config file) Redis can lose just one second of writes in a 430 | # dramatic event like a server power outage, or a single write if something 431 | # wrong with the Redis process itself happens, but the operating system is 432 | # still running correctly. 433 | # 434 | # AOF and RDB persistence can be enabled at the same time without problems. 435 | # If the AOF is enabled on startup Redis will load the AOF, that is the file 436 | # with the better durability guarantees. 437 | # 438 | # Please check http://redis.io/topics/persistence for more information. 439 | 440 | appendonly no 441 | 442 | # The name of the append only file (default: "appendonly.aof") 443 | 444 | appendfilename "appendonly.aof" 445 | 446 | # The fsync() call tells the Operating System to actually write data on disk 447 | # instead to wait for more data in the output buffer. Some OS will really flush 448 | # data on disk, some other OS will just try to do it ASAP. 449 | # 450 | # Redis supports three different modes: 451 | # 452 | # no: don't fsync, just let the OS flush the data when it wants. Faster. 453 | # always: fsync after every write to the append only log . Slow, Safest. 454 | # everysec: fsync only one time every second. Compromise. 455 | # 456 | # The default is "everysec", as that's usually the right compromise between 457 | # speed and data safety. It's up to you to understand if you can relax this to 458 | # "no" that will let the operating system flush the output buffer when 459 | # it wants, for better performances (but if you can live with the idea of 460 | # some data loss consider the default persistence mode that's snapshotting), 461 | # or on the contrary, use "always" that's very slow but a bit safer than 462 | # everysec. 463 | # 464 | # More details please check the following article: 465 | # http://antirez.com/post/redis-persistence-demystified.html 466 | # 467 | # If unsure, use "everysec". 468 | 469 | # appendfsync always 470 | appendfsync everysec 471 | # appendfsync no 472 | 473 | # When the AOF fsync policy is set to always or everysec, and a background 474 | # saving process (a background save or AOF log background rewriting) is 475 | # performing a lot of I/O against the disk, in some Linux configurations 476 | # Redis may block too long on the fsync() call. Note that there is no fix for 477 | # this currently, as even performing fsync in a different thread will block 478 | # our synchronous write(2) call. 479 | # 480 | # In order to mitigate this problem it's possible to use the following option 481 | # that will prevent fsync() from being called in the main process while a 482 | # BGSAVE or BGREWRITEAOF is in progress. 483 | # 484 | # This means that while another child is saving, the durability of Redis is 485 | # the same as "appendfsync none". In practical terms, this means that it is 486 | # possible to lose up to 30 seconds of log in the worst scenario (with the 487 | # default Linux settings). 488 | # 489 | # If you have latency problems turn this to "yes". Otherwise leave it as 490 | # "no" that is the safest pick from the point of view of durability. 491 | 492 | no-appendfsync-on-rewrite no 493 | 494 | # Automatic rewrite of the append only file. 495 | # Redis is able to automatically rewrite the log file implicitly calling 496 | # BGREWRITEAOF when the AOF log size grows by the specified percentage. 497 | # 498 | # This is how it works: Redis remembers the size of the AOF file after the 499 | # latest rewrite (if no rewrite has happened since the restart, the size of 500 | # the AOF at startup is used). 501 | # 502 | # This base size is compared to the current size. If the current size is 503 | # bigger than the specified percentage, the rewrite is triggered. Also 504 | # you need to specify a minimal size for the AOF file to be rewritten, this 505 | # is useful to avoid rewriting the AOF file even if the percentage increase 506 | # is reached but it is still pretty small. 507 | # 508 | # Specify a percentage of zero in order to disable the automatic AOF 509 | # rewrite feature. 510 | 511 | auto-aof-rewrite-percentage 100 512 | auto-aof-rewrite-min-size 64mb 513 | 514 | ################################ LUA SCRIPTING ############################### 515 | 516 | # Max execution time of a Lua script in milliseconds. 517 | # 518 | # If the maximum execution time is reached Redis will log that a script is 519 | # still in execution after the maximum allowed time and will start to 520 | # reply to queries with an error. 521 | # 522 | # When a long running script exceed the maximum execution time only the 523 | # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be 524 | # used to stop a script that did not yet called write commands. The second 525 | # is the only way to shut down the server in the case a write commands was 526 | # already issue by the script but the user don't want to wait for the natural 527 | # termination of the script. 528 | # 529 | # Set it to 0 or a negative value for unlimited execution without warnings. 530 | lua-time-limit 5000 531 | 532 | ################################## SLOW LOG ################################### 533 | 534 | # The Redis Slow Log is a system to log queries that exceeded a specified 535 | # execution time. The execution time does not include the I/O operations 536 | # like talking with the client, sending the reply and so forth, 537 | # but just the time needed to actually execute the command (this is the only 538 | # stage of command execution where the thread is blocked and can not serve 539 | # other requests in the meantime). 540 | # 541 | # You can configure the slow log with two parameters: one tells Redis 542 | # what is the execution time, in microseconds, to exceed in order for the 543 | # command to get logged, and the other parameter is the length of the 544 | # slow log. When a new command is logged the oldest one is removed from the 545 | # queue of logged commands. 546 | 547 | # The following time is expressed in microseconds, so 1000000 is equivalent 548 | # to one second. Note that a negative number disables the slow log, while 549 | # a value of zero forces the logging of every command. 550 | slowlog-log-slower-than 10000 551 | 552 | # There is no limit to this length. Just be aware that it will consume memory. 553 | # You can reclaim memory used by the slow log with SLOWLOG RESET. 554 | slowlog-max-len 128 555 | 556 | ############################# Event notification ############################## 557 | 558 | # Redis can notify Pub/Sub clients about events happening in the key space. 559 | # This feature is documented at http://redis.io/topics/keyspace-events 560 | # 561 | # For instance if keyspace events notification is enabled, and a client 562 | # performs a DEL operation on key "foo" stored in the Database 0, two 563 | # messages will be published via Pub/Sub: 564 | # 565 | # PUBLISH __keyspace@0__:foo del 566 | # PUBLISH __keyevent@0__:del foo 567 | # 568 | # It is possible to select the events that Redis will notify among a set 569 | # of classes. Every class is identified by a single character: 570 | # 571 | # K Keyspace events, published with __keyspace@__ prefix. 572 | # E Keyevent events, published with __keyevent@__ prefix. 573 | # g Generic commands (non-type specific) like DEL, EXPIRE, RENAME, ... 574 | # $ String commands 575 | # l List commands 576 | # s Set commands 577 | # h Hash commands 578 | # z Sorted set commands 579 | # x Expired events (events generated every time a key expires) 580 | # e Evicted events (events generated when a key is evicted for maxmemory) 581 | # A Alias for g$lshzxe, so that the "AKE" string means all the events. 582 | # 583 | # The "notify-keyspace-events" takes as argument a string that is composed 584 | # by zero or multiple characters. The empty string means that notifications 585 | # are disabled at all. 586 | # 587 | # Example: to enable list and generic events, from the point of view of the 588 | # event name, use: 589 | # 590 | # notify-keyspace-events Elg 591 | # 592 | # Example 2: to get the stream of the expired keys subscribing to channel 593 | # name __keyevent@0__:expired use: 594 | # 595 | # notify-keyspace-events Ex 596 | # 597 | # By default all notifications are disabled because most users don't need 598 | # this feature and the feature has some overhead. Note that if you don't 599 | # specify at least one of K or E, no events will be delivered. 600 | notify-keyspace-events "" 601 | 602 | ############################### ADVANCED CONFIG ############################### 603 | 604 | # Hashes are encoded using a memory efficient data structure when they have a 605 | # small number of entries, and the biggest entry does not exceed a given 606 | # threshold. These thresholds can be configured using the following directives. 607 | hash-max-ziplist-entries 512 608 | hash-max-ziplist-value 64 609 | 610 | # Similarly to hashes, small lists are also encoded in a special way in order 611 | # to save a lot of space. The special representation is only used when 612 | # you are under the following limits: 613 | list-max-ziplist-entries 512 614 | list-max-ziplist-value 64 615 | 616 | # Sets have a special encoding in just one case: when a set is composed 617 | # of just strings that happens to be integers in radix 10 in the range 618 | # of 64 bit signed integers. 619 | # The following configuration setting sets the limit in the size of the 620 | # set in order to use this special memory saving encoding. 621 | set-max-intset-entries 512 622 | 623 | # Similarly to hashes and lists, sorted sets are also specially encoded in 624 | # order to save a lot of space. This encoding is only used when the length and 625 | # elements of a sorted set are below the following limits: 626 | zset-max-ziplist-entries 128 627 | zset-max-ziplist-value 64 628 | 629 | # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in 630 | # order to help rehashing the main Redis hash table (the one mapping top-level 631 | # keys to values). The hash table implementation Redis uses (see dict.c) 632 | # performs a lazy rehashing: the more operation you run into a hash table 633 | # that is rehashing, the more rehashing "steps" are performed, so if the 634 | # server is idle the rehashing is never complete and some more memory is used 635 | # by the hash table. 636 | # 637 | # The default is to use this millisecond 10 times every second in order to 638 | # active rehashing the main dictionaries, freeing memory when possible. 639 | # 640 | # If unsure: 641 | # use "activerehashing no" if you have hard latency requirements and it is 642 | # not a good thing in your environment that Redis can reply form time to time 643 | # to queries with 2 milliseconds delay. 644 | # 645 | # use "activerehashing yes" if you don't have such hard requirements but 646 | # want to free memory asap when possible. 647 | activerehashing yes 648 | 649 | # The client output buffer limits can be used to force disconnection of clients 650 | # that are not reading data from the server fast enough for some reason (a 651 | # common reason is that a Pub/Sub client can't consume messages as fast as the 652 | # publisher can produce them). 653 | # 654 | # The limit can be set differently for the three different classes of clients: 655 | # 656 | # normal -> normal clients 657 | # slave -> slave clients and MONITOR clients 658 | # pubsub -> clients subscribed to at least one pubsub channel or pattern 659 | # 660 | # The syntax of every client-output-buffer-limit directive is the following: 661 | # 662 | # client-output-buffer-limit 663 | # 664 | # A client is immediately disconnected once the hard limit is reached, or if 665 | # the soft limit is reached and remains reached for the specified number of 666 | # seconds (continuously). 667 | # So for instance if the hard limit is 32 megabytes and the soft limit is 668 | # 16 megabytes / 10 seconds, the client will get disconnected immediately 669 | # if the size of the output buffers reach 32 megabytes, but will also get 670 | # disconnected if the client reaches 16 megabytes and continuously overcomes 671 | # the limit for 10 seconds. 672 | # 673 | # By default normal clients are not limited because they don't receive data 674 | # without asking (in a push way), but just after a request, so only 675 | # asynchronous clients may create a scenario where data is requested faster 676 | # than it can read. 677 | # 678 | # Instead there is a default limit for pubsub and slave clients, since 679 | # subscribers and slaves receive data in a push fashion. 680 | # 681 | # Both the hard or the soft limit can be disabled by setting them to zero. 682 | client-output-buffer-limit normal 0 0 0 683 | client-output-buffer-limit slave 256mb 64mb 60 684 | client-output-buffer-limit pubsub 32mb 8mb 60 685 | 686 | # Redis calls an internal function to perform many background tasks, like 687 | # closing connections of clients in timeout, purging expired keys that are 688 | # never requested, and so forth. 689 | # 690 | # Not all tasks are performed with the same frequency, but Redis checks for 691 | # tasks to perform accordingly to the specified "hz" value. 692 | # 693 | # By default "hz" is set to 10. Raising the value will use more CPU when 694 | # Redis is idle, but at the same time will make Redis more responsive when 695 | # there are many keys expiring at the same time, and timeouts may be 696 | # handled with more precision. 697 | # 698 | # The range is between 1 and 500, however a value over 100 is usually not 699 | # a good idea. Most users should use the default of 10 and raise this up to 700 | # 100 only in environments where very low latency is required. 701 | hz 10 702 | 703 | # When a child rewrites the AOF file, if the following option is enabled 704 | # the file will be fsync-ed every 32 MB of data generated. This is useful 705 | # in order to commit the file to the disk more incrementally and avoid 706 | # big latency spikes. 707 | aof-rewrite-incremental-fsync yes -------------------------------------------------------------------------------- /src/system-services/mosquitto/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | exec /sbin/setuser mosquitto /usr/sbin/mosquitto -------------------------------------------------------------------------------- /src/system-services/ninjasphere-services/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sv start mosquitto || exit 1 4 | sv start redis || exit 1 5 | 6 | sleep 2 7 | 8 | exec 2>&1 9 | exec chpst -uninja runsvdir /home/ninja/service -------------------------------------------------------------------------------- /src/system-services/redis/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | exec /usr/bin/redis-server /etc/redis/redis.conf --------------------------------------------------------------------------------