docs: improve service guide and clarity
Restructure README, add admonitions, fix log command, and refine script comments and safety notes.
This commit is contained in:
@@ -1,76 +1,108 @@
|
|||||||
## Basic init yt-local for openrc
|
# Basic init yt-local for openrc
|
||||||
|
|
||||||
1. Write `/etc/init.d/ytlocal` file.
|
## Prerequisites
|
||||||
|
|
||||||
```
|
- System with OpenRC installed and configured.
|
||||||
#!/sbin/openrc-run
|
- Administrative privileges (doas or sudo).
|
||||||
# Distributed under the terms of the GNU General Public License v3 or later
|
- `ytlocal` script located at `/usr/sbin/ytlocal` and application files in an accessible directory.
|
||||||
name="yt-local"
|
|
||||||
pidfile="/var/run/ytlocal.pid"
|
|
||||||
command="/usr/sbin/ytlocal"
|
|
||||||
|
|
||||||
depend() {
|
## Service Installation
|
||||||
|
|
||||||
|
1. **Create the OpenRC service script** `/etc/init.d/ytlocal`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
#!/sbin/openrc-run
|
||||||
|
# Distributed under the terms of the GNU General Public License v3 or later
|
||||||
|
name="yt-local"
|
||||||
|
pidfile="/var/run/ytlocal.pid"
|
||||||
|
command="/usr/sbin/ytlocal"
|
||||||
|
|
||||||
|
depend() {
|
||||||
use net
|
use net
|
||||||
}
|
}
|
||||||
|
|
||||||
start_pre() {
|
start_pre() {
|
||||||
if [ ! -f /usr/sbin/ytlocal ] ; then
|
if [ ! -f /usr/sbin/ytlocal ]; then
|
||||||
eerror "Please create script file of ytlocal in '/usr/sbin/ytlocal'"
|
eerror "Please create script file of ytlocal in '/usr/sbin/ytlocal'"
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
ebegin "Starting yt-local"
|
ebegin "Starting yt-local"
|
||||||
start-stop-daemon --start --exec "${command}" --pidfile "${pidfile}"
|
start-stop-daemon --start --exec "${command}" --pidfile "${pidfile}"
|
||||||
eend $?
|
eend $?
|
||||||
}
|
}
|
||||||
|
|
||||||
reload() {
|
reload() {
|
||||||
ebegin "Reloading ${name}"
|
ebegin "Reloading ${name}"
|
||||||
start-stop-daemon --signal HUP --pidfile "${pidfile}"
|
start-stop-daemon --signal HUP --pidfile "${pidfile}"
|
||||||
eend $?
|
eend $?
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
ebegin "Stopping ${name}"
|
ebegin "Stopping ${name}"
|
||||||
start-stop-daemon --quiet --stop --exec "${command}" --pidfile "${pidfile}"
|
start-stop-daemon --quiet --stop --exec "${command}" --pidfile "${pidfile}"
|
||||||
eend $?
|
eend $?
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
after, modified execute permissions:
|
> [!NOTE]
|
||||||
|
> Ensure the script is executable:
|
||||||
|
>
|
||||||
|
> ```sh
|
||||||
|
> doas chmod a+x /etc/init.d/ytlocal
|
||||||
|
> ```
|
||||||
|
|
||||||
$ doas chmod a+x /etc/init.d/ytlocal
|
2. **Create the executable script** `/usr/sbin/ytlocal`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
2. Write `/usr/sbin/ytlocal` and configure path.
|
# Change the working directory according to your installation path
|
||||||
|
# Example: if installed in /usr/local/ytlocal, use:
|
||||||
|
cd /home/your-path/ytlocal/ # <-- MODIFY TO YOUR PATH
|
||||||
|
source venv/bin/activate
|
||||||
|
python server.py > /dev/null 2>&1 &
|
||||||
|
echo $! > /var/run/ytlocal.pid
|
||||||
|
```
|
||||||
|
|
||||||
```
|
> [!WARNING]
|
||||||
#!/usr/bin/env bash
|
> Run this script only as root or via `doas`, as it writes to `/var/run` and uses network privileges.
|
||||||
|
|
||||||
cd /home/your-path/ytlocal/ # change me
|
> [!TIP]
|
||||||
source venv/bin/activate
|
> To store the PID in a different location, adjust the `pidfile` variable in the service script.
|
||||||
python server.py > /dev/null 2>&1 &
|
|
||||||
echo $! > /var/run/ytlocal.pid
|
|
||||||
```
|
|
||||||
|
|
||||||
after, modified execute permissions:
|
> [!IMPORTANT]
|
||||||
|
> Verify that the virtual environment (`venv`) is correctly set up and that `python` points to the appropriate version.
|
||||||
|
|
||||||
$ doas chmod a+x /usr/sbin/ytlocal
|
> [!CAUTION]
|
||||||
|
> Do not stop the process manually; use OpenRC commands (`rc-service ytlocal stop`) to avoid race conditions.
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> When run with administrative privileges, the configuration is saved in `/root/.yt-local`, which is root‑only.
|
||||||
|
|
||||||
3. OpenRC check
|
## Service Management
|
||||||
|
|
||||||
- status: `doas rc-service ytlocal status`
|
- **Status**: `doas rc-service ytlocal status`
|
||||||
- start: `doas rc-service ytlocal start`
|
- **Start**: `doas rc-service ytlocal start`
|
||||||
- restart: `doas rc-service ytlocal restart`
|
- **Restart**: `doas rc-service ytlocal restart`
|
||||||
- stop: `doas rc-service ytlocal stop`
|
- **Stop**: `doas rc-service ytlocal stop`
|
||||||
|
- **Enable at boot**: `doas rc-update add ytlocal default`
|
||||||
|
- **Disable**: `doas rc-update del ytlocal`
|
||||||
|
|
||||||
- enable: `doas rc-update add ytlocal default`
|
## Post‑Installation Verification
|
||||||
- disable: `doas rc-update del ytlocal`
|
|
||||||
|
|
||||||
When yt-local is run with administrator privileges,
|
- Confirm the process is running: `doas rc-service ytlocal status`
|
||||||
the configuration file is stored in /root/.yt-local
|
- Inspect logs for issues: `doas tail -f /var/log/ytlocal.log` (if logging is configured).
|
||||||
|
|
||||||
|
## Troubleshooting Common Issues
|
||||||
|
|
||||||
|
- **Service fails to start**: verify script permissions, correct `command=` path, and that the virtualenv exists.
|
||||||
|
- **Port conflict**: adjust the server’s port configuration before launching.
|
||||||
|
- **Import errors**: ensure all dependencies are installed in the virtual environment.
|
||||||
|
|
||||||
|
[!IMPORTANT]
|
||||||
|
Keep the service script updated when modifying startup logic or adding new dependencies.
|
||||||
|
|||||||
Reference in New Issue
Block a user