added git hook and systemd guide
This commit is contained in:
parent
5ec72108ad
commit
0728cc190d
33
memo/git-hook.md
Normal file
33
memo/git-hook.md
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
# Automate update via Git Hook
|
||||||
|
|
||||||
|
1. Navigate to the bare repository:
|
||||||
|
```bash
|
||||||
|
cd ~/git/asobi.git/hooks
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Create `post-receive` Hook:
|
||||||
|
```bash
|
||||||
|
nano post-receive
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Add script you want to run:
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Deployment directory
|
||||||
|
DEPLOY_DIR="/home/nik/repo/asobi"
|
||||||
|
|
||||||
|
# Navigate to the deployment directory
|
||||||
|
cd $DEPLOY_DIR
|
||||||
|
|
||||||
|
# Pull the latest changes
|
||||||
|
git pull origin main
|
||||||
|
|
||||||
|
# Restart the service
|
||||||
|
sudo systemctl restart asobi-web.service
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Make the hook executable:
|
||||||
|
```
|
||||||
|
chmod +x post-receive
|
||||||
|
```
|
||||||
45
memo/make-systemd.md
Normal file
45
memo/make-systemd.md
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
1. Open new service file:
|
||||||
|
```
|
||||||
|
sudo nano /etc/systemd/system/<name>.service
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Content
|
||||||
|
```
|
||||||
|
[Unit]
|
||||||
|
Description=Page Host Service
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=your_username
|
||||||
|
WorkingDirectory=/home/your_username/repo/asobi
|
||||||
|
Environment=PYENV_ROOT=/home/your_username/.pyenv
|
||||||
|
ExecStart=/bin/bash -c "source $PYENV_ROOT/bin/pyenv && pyenv activate pyenv && python page_host.py"
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Reload systemd, enable service:
|
||||||
|
```
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable <name>.service
|
||||||
|
sudo systemctl start <name>.service
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Check status:
|
||||||
|
```
|
||||||
|
sudo systemctl status <name>.service
|
||||||
|
journalctl -u <name>.service
|
||||||
|
```
|
||||||
|
|
||||||
|
5. Test reboot:
|
||||||
|
```
|
||||||
|
sudo reboot
|
||||||
|
```
|
||||||
|
|
||||||
|
Check status
|
||||||
|
```
|
||||||
|
sudo systemctl status page_host.service
|
||||||
|
```
|
||||||
Loading…
x
Reference in New Issue
Block a user