Skip to content

Commit e7ee48e

Browse files
committed
feat(deploy): add Makefile to setup systemd for auto-start and logs
1 parent 50208eb commit e7ee48e

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

Makefile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
SERVICE_NAME := sw
2+
3+
define SERVICE_FILE
4+
[Unit]
5+
Description=Showcase Website
6+
After=network.target
7+
8+
[Service]
9+
ExecStart=$(shell which bun) run start
10+
WorkingDirectory=$(shell pwd)
11+
Restart=always
12+
RestartSec=5
13+
User=$(shell whoami)
14+
15+
[Install]
16+
WantedBy=multi-user.target
17+
endef
18+
19+
export SERVICE_FILE
20+
21+
.PHONY: help init update logs
22+
23+
help:
24+
@echo "This is a production only tool. Please use bun directly in development."
25+
@echo ""
26+
@echo "Run 'sudo make init' once, and then every time you want to update the website, run 'sudo make update'."
27+
@echo ""
28+
@echo "Rules:"
29+
@echo " - init: creates the service"
30+
@echo " - restart: restart website wthout pulling latest version"
31+
@echo " - update: updates and restarts"
32+
@echo " - logs: opens the logs"
33+
@echo " - help: displays this message"
34+
35+
init:
36+
echo "$$SERVICE_FILE" | sudo tee /etc/systemd/system/$(SERVICE_NAME).service
37+
sudo systemctl daemon-reload
38+
sudo systemctl enable $(SERVICE_NAME)
39+
40+
update:
41+
git fetch origin
42+
git reset --hard origin/main
43+
git pull --force origin main
44+
sudo systemctl stop $(SERVICE_NAME)
45+
bun i
46+
bun run build
47+
sudo systemctl start $(SERVICE_NAME)
48+
49+
restart:
50+
sudo systemctl restart $(SERVICE_NAME)
51+
52+
logs:
53+
sudo journalctl -xeu $(SERVICE_NAME)

0 commit comments

Comments
 (0)