68 lines
1.6 KiB
Bash
68 lines
1.6 KiB
Bash
|
#!/usr/bin/env bash
|
||
|
|
||
|
if [ -z "$NODEVER" ]; then
|
||
|
NODEVER="20";
|
||
|
fi
|
||
|
|
||
|
if [ -z "$environment" ]; then
|
||
|
environment="PROD"
|
||
|
fi
|
||
|
|
||
|
adduser -u $uid $user
|
||
|
|
||
|
mkdir -p /home/$user/app
|
||
|
mkdir -p /home/$user/logs/{nginx,nodejs}
|
||
|
|
||
|
# Link log directories
|
||
|
rm -rf /var/log/nginx
|
||
|
ln -s /home/$user/logs/nginx /var/log/nginx
|
||
|
ln -s /home/$user/logs/nodejs /var/log/nodejs
|
||
|
|
||
|
# Configure nginx for reverse proxy
|
||
|
/scripts/create-nginx-config.sh
|
||
|
|
||
|
# Set ownership and permissions
|
||
|
chown -R $user:$user /home/$user
|
||
|
chmod -R 755 /home/$user
|
||
|
|
||
|
# Start nginx
|
||
|
nginx
|
||
|
|
||
|
if [[ $environment == 'DEV' ]]; then
|
||
|
echo "Starting Dev Deployment"
|
||
|
mkdir -p /home/$user/_backups
|
||
|
|
||
|
# Ensure microdnf is available for installing additional packages in DEV mode
|
||
|
if ! command -v microdnf &> /dev/null; then
|
||
|
echo "microdnf not found, installing with dnf..."
|
||
|
dnf install -y microdnf && dnf clean all
|
||
|
fi
|
||
|
|
||
|
# Install Memcached for session storage in DEV mode with memory limit
|
||
|
microdnf install -y memcached
|
||
|
# Start memcached with 32MB memory limit
|
||
|
nohup memcached -d -u $user -p 11211 -m 32
|
||
|
|
||
|
# Set up automatic backups
|
||
|
echo "*/30 * * * * root /scripts/backup.sh $user" >> /etc/crontab
|
||
|
fi
|
||
|
|
||
|
# Start cron for log rotation and backups
|
||
|
/usr/sbin/crond
|
||
|
|
||
|
# If there's an app in the user directory, start it with PM2
|
||
|
if [ -f /home/$user/app/package.json ]; then
|
||
|
cd /home/$user/app
|
||
|
su -c "npm install" $user
|
||
|
su -c "pm2 start ecosystem.config.js" $user
|
||
|
else
|
||
|
# Start default app
|
||
|
cd /var/www/html
|
||
|
npm install
|
||
|
su -c "pm2 start ecosystem.config.js" $user
|
||
|
fi
|
||
|
|
||
|
# Follow logs
|
||
|
tail -f /home/$user/logs/nginx/* /home/$user/logs/nodejs/*
|
||
|
|
||
|
exit 0
|