Add Makefile to install as systemctl service

This commit is contained in:
Jansen Price 2020-09-11 02:14:22 -05:00
parent 5eb44de02d
commit b6c8e590de
4 changed files with 93 additions and 1 deletions

75
Makefile Normal file
View File

@ -0,0 +1,75 @@
.SILENT: help
ccyellow = $(shell echo "\033[33m")
ccend = $(shell tput op)
notice = $(ccyellow) $(0) $(ccend)
_path := $(shell pwd)
_user := gemini-data
ORBIT_HOSTNAME ?= localhost
SERVICE_PATH = /etc/systemd/system/orbit.service
EXEC_PATH = /usr/local/bin/orbit
CONF_PATH = /etc/orbit
LOG_PATH = /var/log/orbit
help:
echo "To run tests, run make test, to install on system run make install"
test:
cd tests; ../vendor/bin/phpunit .
install_bin:
@echo
@echo "$(ccyellow)> Installing orbit bin$(ccend)"
rm $(EXEC_PATH)
ln -s $(_path)/bin/orbit $(EXEC_PATH)
install_conf:
@echo
@echo "$(ccyellow)> Installing orbit config; Hostname: $(ORBIT_HOSTNAME)$(ccend)"
install -d $(CONF_PATH)
install config/localhost.ini $(CONF_PATH)/config.ini
sed -i -e 's#Example##' $(CONF_PATH)/config.ini
sed -i -e 's#localhost#$(ORBIT_HOSTNAME)#' $(CONF_PATH)/config.ini
sed -i -e 's#certs#$(CONF_PATH)/certs#' $(CONF_PATH)/config.ini
sed -i -e 's#log/#$(LOG_PATH)/#' $(CONF_PATH)/config.ini
install -o $(_user) -d $(LOG_PATH)
install_cert:
ifeq (,$(wildcard $(CONF_PATH)/certs/$(ORBIT_HOSTNAME).cert.pem))
@echo
@echo "$(ccyellow)> Generating certs for host $(ORBIT_HOSTNAME)$(ccend)"
bin/makecert $(ORBIT_HOSTNAME)
install -d $(CONF_PATH)/certs
install certs/$(ORBIT_HOSTNAME).cert.pem $(CONF_PATH)/certs/$(ORBIT_HOSTNAME).cert.pem
install certs/$(ORBIT_HOSTNAME).key.pem $(CONF_PATH)/certs/$(ORBIT_HOSTNAME).key.pem
endif
install_user:
ifeq ($(shell id -u $(_user) 2>/dev/null),)
@echo
@echo "$(ccyellow)> Creating user $(_user)$(ccend)"
useradd -m -d /var/$(_user) -s /usr/sbin/nologin -c "Orbit gemini service account" -U $(_user)
endif
install_service:
@echo
@echo "$(ccyellow)> Creating orbit.service file at $(SERVICE_PATH)$(ccend)"
install orbit.service $(SERVICE_PATH)
sed -i -e 's/{USER}/$(_user)/' $(SERVICE_PATH)
install: install_bin install_conf install_cert install_user install_service
@echo
@echo "--------------------------------"
@echo "done"
@echo "> The service runs with the user $(_user), which I created for you"
@echo "> The actual orbit script is at $(EXEC_PATH)"
@echo " - But that is just a symlink to $(_path)/bin/orbit"
@echo "> I created a config file at $(CONF_PATH)/config.ini"
@echo " - Edit settings in that file to change configuration settings"
@echo "> I created a self-signed cert at $(CONF_PATH)/certs"
@echo "> The server log will be written at $(LOG_PATH)/orbit.log"
@echo "Run 'sudo systemctl start orbit' to start the service"
@echo "Run 'sudo systemctl restart orbit' to restart the service"
@echo "Run 'sudo systemctl enable orbit' to configure orbit to auto-start when machine starts"

View File

@ -16,6 +16,9 @@
"require-dev": { "require-dev": {
"phpunit/phpunit": "^9.3" "phpunit/phpunit": "^9.3"
}, },
"bin": [
"bin/orbit"
],
"autoload": { "autoload": {
"psr-4" : { "psr-4" : {
"Orbit\\" : "src/Orbit" "Orbit\\" : "src/Orbit"

View File

@ -34,7 +34,7 @@ log_file = "log/orbit.log"
log_level = "info" log_level = "info"
; Root dir : Root directory of the server files ; Root dir : Root directory of the server files
root_dir = "." root_dir = "/var/gemini"
; Index file : Name of the index file (when a directory is accessed) ; Index file : Name of the index file (when a directory is accessed)
index_file = "index.gmi" index_file = "index.gmi"

14
orbit.service Normal file
View File

@ -0,0 +1,14 @@
[Unit]
Description=Orbit gemini server
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User={USER}
ExecStart=/usr/local/bin/orbit --config /etc/orbit/config.ini -q
[Install]
WantedBy=multi-user.target