Browse Source

Add Makefile to install as systemctl service

develop
Jansen Price 5 months ago
parent
commit
b6c8e590de
4 changed files with 93 additions and 1 deletions
  1. +75
    -0
      Makefile
  2. +3
    -0
      composer.json
  3. +1
    -1
      config/localhost.ini
  4. +14
    -0
      orbit.service

+ 75
- 0
Makefile 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"

+ 3
- 0
composer.json View File

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


+ 1
- 1
config/localhost.ini View File

@ -34,7 +34,7 @@ log_file = "log/orbit.log"
log_level = "info"
; 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 = "index.gmi"


+ 14
- 0
orbit.service 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

Loading…
Cancel
Save