Skip to content

Commit

Permalink
Support running locally from git repo
Browse files Browse the repository at this point in the history
The time series charts need a running web server.  That requires a
partial system install, and flexibility about where things live.
  • Loading branch information
zultron committed Nov 28, 2017
1 parent c571615 commit 7a8fd57
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 36 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.pyc
/pb_goldibox-00A0.dtbo
# Run artifacts
/saved_state.yaml
/rrd/
*.autosave
# Min install artifacts
/etc/config.yaml
78 changes: 55 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
ifndef MININSTALL
# Service user ID
USER = goldibox

# System user ID
ROOT_USER = root
# For saved state
VAR_DIR = /var/lib/goldibox

# For configuration
ETC_DIR = /etc/goldibox

# HAL configs
HAL_DIR = $(ETC_DIR)/hal
HAL_FILES = common.hal pb.hal sim.hal

# Executables
BIN_DIR = /usr/bin
BIN_FILES = goldibox goldibox-control goldibox-logger goldibox-remote \
goldibox-sim-temp

# Python lib
PYTHON_DIR = /usr/lib/python$(shell \
python -c \
'from sys import version_info as v; print "%s.%s" % (v.major, v.minor)')
PYTHON_FILES = goldibox.py

# QML files
SHARE_DIR = /usr/share/goldibox
else # MININSTALL
# Service user ID
USER = $(SUDO_USER)
# System user ID
ROOT_USER = $(SUDO_USER)
# For saved state
VAR_DIR = $(PWD)/rrd
# For configuration
ETC_DIR = $(PWD)/etc
# HAL configs
HAL_DIR = $(PWD)/hal
# Executables
BIN_DIR = $(PWD)/bin
# Python lib
PYTHON_DIR = $(PWD)/lib/python
# QML files
SHARE_DIR = $(PWD)
endif


HAL_FILES = common.hal pb.hal sim.hal
BIN_FILES = goldibox goldibox-control goldibox-logger goldibox-remote \
goldibox-sim-temp
PYTHON_FILES = goldibox.py
SHARE_FILES = \
images/icon.png \
launcher.ini \
Expand All @@ -48,11 +66,13 @@ HAVE_DTC = $(shell test -f /usr/bin/dtc && echo 1)
.PHONY: default
default:
@echo "Please specify a target; choices:" 1>&2
@echo " install"
@echo " install [ MININSTALL=1 ]"
@echo " build"
@echo " - Use MININSTALL=1 to run from source directory"

.PHONY: add_user
add_user:
ifndef MININSTALL
@ if ! id $(USER) 2>/dev/null >/dev/null; then \
echo "Creating user $(USER)"; \
adduser \
Expand All @@ -63,6 +83,7 @@ add_user:
--disabled-password \
$(USER) >/dev/null; \
fi
endif

$(patsubst %,$(HAL_DIR)/%,$(HAL_FILES)): $(HAL_DIR)/%: hal/%
@mkdir -p $(HAL_DIR)
Expand Down Expand Up @@ -92,30 +113,33 @@ $(patsubst %,$(SHARE_DIR)/%,$(SHARE_FILES)): $(SHARE_DIR)/%: %
/etc/apache2/conf-enabled/goldibox.conf

$(VAR_DIR)/graphs/index.html: templates/index.html $(VAR_DIR)/saved_state.yaml
@install -d -o $(USER) $(VAR_DIR)
@install -d -o $(USER) -g www-data -m 775 $(dir $@)
cp $< $@
install -o $(ROOT_USER) -m 755 $< $@

$(VAR_DIR)/graphs/uichart.png.cgi: templates/uichart.png.cgi
@install -d -o $(USER) $(VAR_DIR)
@install -d -o $(USER) -g www-data -m 775 $(dir $@)
install -m 755 $< $@
install -o $(ROOT_USER) -m 755 $< $@

$(VAR_DIR)/saved_state.yaml:
install -d -o $(USER) $(VAR_DIR)
@install -d -o $(USER) $(VAR_DIR)
touch $(VAR_DIR)/saved_state.yaml
chown $(USER) $(VAR_DIR)/saved_state.yaml

$(ETC_DIR)/overlay-pb.bbio: etc/overlay-pb.bbio
install -d $(ETC_DIR)
@mkdir -p $(dir $@)
@install -o $(ROOT_USER) -d $(ETC_DIR)
install -m 644 $< $@

$(ETC_DIR)/config.yaml: templates/config.yaml
@mkdir -p $(ETC_DIR)
@install -o $(USER) -d $(ETC_DIR)
sed < $< > $@ \
-e 's,@HAL_DIR@,$(HAL_DIR),' \
-e 's,@VAR_DIR@,$(VAR_DIR),' \
-e 's,@ETC_DIR@,$(ETC_DIR),' \
-e 's,@BIN_DIR@,$(BIN_DIR),' \
-e 's,@SHARE_DIR@,$(SHARE_DIR),'
@chown $(ROOT_USER) $@

ifneq ($(HAVE_DTC),)
/lib/firmware/pb_goldibox-00A0.dtbo: etc/pb_goldibox.dts
Expand All @@ -131,28 +155,36 @@ endif
-e 's,@USER@,$(USER),'
ln -sf $@ /lib/systemd/goldibox.service

# System-installed files needed to run from source directory
ALL_FILES += \
$(patsubst %,$(HAL_DIR)/%,$(HAL_FILES)) \
$(patsubst %,$(PYTHON_DIR)/%,$(PYTHON_FILES)) \
$(patsubst %,$(BIN_DIR)/%,$(BIN_FILES)) \
$(patsubst %,$(SHARE_DIR)/%,$(SHARE_FILES)) \
$(ETC_DIR)/config.yaml \
$(ETC_DIR)/overlay-pb.bbio \
$(VAR_DIR)/saved_state.yaml \
/etc/systemd/system/goldibox.service \
/etc/apache2/conf-available/goldibox.conf \
$(VAR_DIR)/graphs/index.html \
$(VAR_DIR)/graphs/uichart.png.cgi

# Full system install, started at boot time
ifndef MININSTALL
ALL_FILES += \
$(MIN_INSTALL_FILES) \
$(patsubst %,$(HAL_DIR)/%,$(HAL_FILES)) \
$(patsubst %,$(BIN_DIR)/%,$(BIN_FILES)) \
$(patsubst %,$(SHARE_DIR)/%,$(SHARE_FILES)) \
$(ETC_DIR)/overlay-pb.bbio \
$(VAR_DIR)/saved_state.yaml \
/etc/systemd/system/goldibox.service
endif
.PHONY: install
install: add_user $(ALL_FILES)

ifndef MININSTALL
.PHONY: uninstall
uninstall:
@ for i in $(ALL_FILES); do \
echo "Removing $$i"; \
rm -f $$i; \
done
endif


.PHONY: build
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,21 @@ repository directory.
On the PocketBeagle, start the Goldibox control from the command line
(load the overlay file for non-system installs):

# Install minimal apache and other config
sudo make install MININSTALL=1
# Start control
bin/goldibox -o

The Goldibox should now be ready for control. Start the
[MachinekitClient][qqvcp] and open the Goldibox app.

Alternatively, run a Goldibox simulated control and GUI in a Docker
container from the command line. Get the URL for the [latest
MachinekitClient build][mkclient-dl], then:
container from the command line:

# Start the container
docker/qqvcp.sh
# Install minimal apache and other config
sudo make install MININSTALL=1
# Start control
bin/goldibox &
# Start GUI
Expand Down
2 changes: 1 addition & 1 deletion bin/goldibox
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ try:
if args.board == 'sim':
# Start syslog, dbus and avahi services if they aren't
# already running in container
for svc in ('rsyslog', 'dbus', 'avahi-daemon'):
for svc in ('rsyslog', 'dbus', 'avahi-daemon', 'apache2'):
ret = subprocess.call(
['/usr/bin/sudo', '/etc/init.d/%s' % svc, 'status'])
if ret != 0:
Expand Down
2 changes: 2 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ RUN apt-get update \
rsyslog \
&& apt-get clean

# Zeroconf, httpd, RRD, python YAML
RUN apt-get install -y \
avahi-utils \
python-yaml \
python-rrdtool \
apache2 \
&& apt-get clean

# For appimage
Expand Down
7 changes: 0 additions & 7 deletions etc/config.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion lib/python/goldibox.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, config_file=None):
for path in (
config_file,
os.environ.get('GOLDIBOX_CONFIG',None),
os.path.join(os.getcwd(), 'etc'),
os.path.join(os.path.dirname(__file__),'..','..','etc'),
'/etc/goldibox'):
if path is None:
continue
Expand Down
1 change: 1 addition & 0 deletions templates/config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PATH: @BIN_DIR@
HALDIR: @HAL_DIR@
state_file: @VAR_DIR@/saved_state.yaml
rrd_file: @VAR_DIR@/logger.rrd
Expand Down
2 changes: 1 addition & 1 deletion templates/uichart.png.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ try:
from goldibox import Config
except ImportError as e:
# If running from the git tree, try adding the lib path
path = os.path.join(os.path.dirname(__file__),'..','lib','python')
path = os.path.join(os.path.dirname(__file__),'..','..','lib','python')
sys.path.append(path)
from goldibox import Config

Expand Down

0 comments on commit 7a8fd57

Please sign in to comment.