fix logrotate perms
This commit is contained in:
@@ -95,10 +95,13 @@ systemctl status angie.service --no-pager
|
|||||||
systemctl status npm.service --no-pager
|
systemctl status npm.service --no-pager
|
||||||
```
|
```
|
||||||
# NPM UI
|
# NPM UI
|
||||||
# Default: http://<your-host>:81
|
# Default: http://"<your-host>":81
|
||||||
|
|
||||||
# Angie UI
|
# Angie UI
|
||||||
# Default: http://<your-host>:82
|
# Default: http://"<your-host>":82/console
|
||||||
|
|
||||||
|
# Prometheus
|
||||||
|
# Default: http://"<your-host>":82/p8s
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -1216,16 +1216,24 @@ def install_logrotate_for_data_logs():
|
|||||||
|
|
||||||
def fix_logrotate_permissions_and_wrapper():
|
def fix_logrotate_permissions_and_wrapper():
|
||||||
with step("Fixing logrotate state-file permissions and helper"):
|
with step("Fixing logrotate state-file permissions and helper"):
|
||||||
status = Path("/var/lib/logrotate/status")
|
system_status = Path("/var/lib/logrotate/status")
|
||||||
try:
|
if system_status.exists():
|
||||||
run(["setfacl", "-m", "u:npm:rw", str(status)], check=False)
|
try:
|
||||||
except FileNotFoundError:
|
run(["setfacl", "-m", "u:npm:rw", str(system_status)], check=False)
|
||||||
pass
|
except FileNotFoundError:
|
||||||
state_dir = Path("/opt/npm/var"); state_dir.mkdir(parents=True, exist_ok=True)
|
try:
|
||||||
|
run(["chgrp", "npm", str(system_status)], check=False)
|
||||||
|
os.chmod(system_status, 0o664)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
state_dir = Path("/opt/npm/var")
|
||||||
|
state_dir.mkdir(parents=True, exist_ok=True)
|
||||||
state_file = state_dir / "logrotate.state"
|
state_file = state_dir / "logrotate.state"
|
||||||
if not state_file.exists():
|
if not state_file.exists():
|
||||||
state_file.touch()
|
state_file.touch()
|
||||||
os.chmod(state_file, 0o664)
|
os.chmod(state_file, 0o664)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pwd, grp
|
import pwd, grp
|
||||||
uid = pwd.getpwnam("npm").pw_uid
|
uid = pwd.getpwnam("npm").pw_uid
|
||||||
@@ -1234,12 +1242,24 @@ def fix_logrotate_permissions_and_wrapper():
|
|||||||
os.chown(state_file, uid, gid)
|
os.chown(state_file, uid, gid)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
helper = Path("/usr/local/bin/logrotate-npm")
|
helper = Path("/usr/local/bin/logrotate-npm")
|
||||||
helper_content = f"""#!/bin/sh
|
helper_content = f"""#!/bin/sh
|
||||||
|
# Logrotate wrapper for npm user
|
||||||
exec /usr/sbin/logrotate -s {state_file} "$@"
|
exec /usr/sbin/logrotate -s {state_file} "$@"
|
||||||
"""
|
"""
|
||||||
write_file(helper, helper_content, 0o755)
|
write_file(helper, helper_content, 0o755)
|
||||||
|
|
||||||
|
logrotate_dir = Path("/var/lib/logrotate")
|
||||||
|
if logrotate_dir.exists():
|
||||||
|
try:
|
||||||
|
run(["usermod", "-aG", "adm", "npm"], check=False)
|
||||||
|
|
||||||
|
run(["chgrp", "adm", str(logrotate_dir)], check=False)
|
||||||
|
os.chmod(logrotate_dir, 0o775)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠ Warning: could not fix {logrotate_dir} permissions: {e}")
|
||||||
|
|
||||||
def create_systemd_units(ipv6_enabled: bool):
|
def create_systemd_units(ipv6_enabled: bool):
|
||||||
with step("Creating and starting systemd services (angie, npm)"):
|
with step("Creating and starting systemd services (angie, npm)"):
|
||||||
unit_lines = [
|
unit_lines = [
|
||||||
|
|||||||
Reference in New Issue
Block a user