Skip to content

Instantly share code, notes, and snippets.

@JSONOrona
Created April 23, 2024 22:15
Show Gist options
  • Save JSONOrona/8bc453f0202db8529a1d247ffcbc6c00 to your computer and use it in GitHub Desktop.
Save JSONOrona/8bc453f0202db8529a1d247ffcbc6c00 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Directory setup
mkdir -p /opt/eed/current
mkdir -p /opt/eed/factory
# Creating and configuring each service script
for i in {00..04}; do
# Create script file
SCRIPT_PATH="/opt/eed/factory/eed-savi-app-$i.sh"
cat > $SCRIPT_PATH << EOF
#!/bin/bash
j=0
SLEEP_INTERVAL=36000 # 10 hours
while :
do
echo "App $i entry point (\$j), interval=\$SLEEP_INTERVAL"
((j=j+1))
sleep \$SLEEP_INTERVAL
break
done
EOF
# Make the script executable
chmod +x $SCRIPT_PATH
# Create systemd unit file
UNIT_FILE="/etc/systemd/system/eed-savi-app-$i.service"
cat > $UNIT_FILE << EOF
[Unit]
Description=EED SAVI Application Service $i
[Service]
ExecStart=$SCRIPT_PATH
Restart=always
[Install]
WantedBy=multi-user.target
EOF
done
# Reload systemd, enable and start services
systemctl daemon-reload
for i in {00..04}; do
systemctl enable eed-savi-app-$i.service
systemctl start eed-savi-app-$i.service
done
echo "Services have been created and started."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment