cleanup sudo, chmod secrets, dont overwrite units
This commit is contained in:
parent
d896c56b8e
commit
5845e8ff61
6 changed files with 39 additions and 83 deletions
|
|
@ -4,13 +4,8 @@ start_services() {
|
|||
LND_STATUS=$1
|
||||
PUB_UPGRADE=$2
|
||||
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
USER_HOME=$(getent passwd ${SUDO_USER} | cut -d: -f6)
|
||||
USER_NAME=$SUDO_USER
|
||||
else
|
||||
USER_HOME=$HOME
|
||||
USER_NAME=$(whoami)
|
||||
fi
|
||||
USER_HOME=$HOME
|
||||
USER_NAME=$(whoami)
|
||||
|
||||
# Ensure NVM_DIR is set
|
||||
if [ -z "$NVM_DIR" ]; then
|
||||
|
|
@ -20,34 +15,23 @@ start_services() {
|
|||
if [ "$OS" = "Linux" ]; then
|
||||
if [ "$SYSTEMCTL_AVAILABLE" = true ]; then
|
||||
mkdir -p "$USER_HOME/.config/systemd/user"
|
||||
cat > "$USER_HOME/.config/systemd/user/lnd.service" <<EOF
|
||||
[Unit]
|
||||
Description=LND Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=${USER_HOME}/lnd/lnd
|
||||
Restart=always
|
||||
# Check and create lnd.service if needed
|
||||
LND_UNIT="$USER_HOME/.config/systemd/user/lnd.service"
|
||||
NEW_LND_CONTENT="[Unit]\nDescription=LND Service\nAfter=network.target\n\n[Service]\nExecStart=${USER_HOME}/lnd/lnd\nRestart=always\n\n[Install]\nWantedBy=default.target"
|
||||
if [ ! -f "$LND_UNIT" ] || [ "$(cat "$LND_UNIT")" != "$NEW_LND_CONTENT" ]; then
|
||||
echo -e "$NEW_LND_CONTENT" > "$LND_UNIT"
|
||||
systemctl --user daemon-reload
|
||||
fi
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
EOF
|
||||
# Check and create lightning_pub.service if needed
|
||||
PUB_UNIT="$USER_HOME/.config/systemd/user/lightning_pub.service"
|
||||
NEW_PUB_CONTENT="[Unit]\nDescription=Lightning.Pub Service\nAfter=network.target\n\n[Service]\nExecStart=/bin/bash -c 'source ${NVM_DIR}/nvm.sh && npm start'\nWorkingDirectory=${USER_HOME}/lightning_pub\nRestart=always\n\n[Install]\nWantedBy=default.target"
|
||||
if [ ! -f "$PUB_UNIT" ] || [ "$(cat "$PUB_UNIT")" != "$NEW_PUB_CONTENT" ]; then
|
||||
echo -e "$NEW_PUB_CONTENT" > "$PUB_UNIT"
|
||||
systemctl --user daemon-reload
|
||||
fi
|
||||
|
||||
cat > "$USER_HOME/.config/systemd/user/lightning_pub.service" <<EOF
|
||||
[Unit]
|
||||
Description=Lightning.Pub Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/bash -c 'source ${NVM_DIR}/nvm.sh && npm start'
|
||||
WorkingDirectory=${USER_HOME}/lightning_pub
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
EOF
|
||||
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable lnd >/dev/null 2>&1
|
||||
systemctl --user enable lightning_pub >/dev/null 2>&1
|
||||
|
||||
|
|
@ -90,30 +74,14 @@ EOF
|
|||
fi
|
||||
|
||||
else
|
||||
create_start_script
|
||||
log "systemctl not available. Created start.sh. Please use this script to start the services manually."
|
||||
log "systemctl not available. Please start the services manually (e.g., run lnd and npm start in separate terminals)."
|
||||
fi
|
||||
elif [ "$OS" = "Mac" ]; then
|
||||
# NOTE: macOS support is untested and unsupported. Use at your own risk.
|
||||
log "macOS detected. Please configure launchd manually to start ${SECONDARY_COLOR}LND${RESET_COLOR} and ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} at startup."
|
||||
create_start_script
|
||||
elif [ "$OS" = "Cygwin" ] || [ "$OS" = "MinGw" ]; then
|
||||
log "Windows detected. Please configure your startup scripts manually to start ${SECONDARY_COLOR}LND${RESET_COLOR} and ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} at startup."
|
||||
create_start_script
|
||||
else
|
||||
log "Unsupported OS detected. Please configure your startup scripts manually."
|
||||
create_start_script
|
||||
fi
|
||||
}
|
||||
|
||||
create_start_script() {
|
||||
cat <<EOF > start.sh
|
||||
#!/bin/bash
|
||||
${USER_HOME}/lnd/lnd &
|
||||
LND_PID=\$!
|
||||
sleep 10
|
||||
npm start &
|
||||
NODE_PID=\$!
|
||||
wait \$LND_PID \$NODE_PID
|
||||
EOF
|
||||
chmod +x start.sh
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue