Posted On May 31, 2020

Linux: How to Set Startup Script

kimconnect 0 comments
blog.KimConnect.com >> Codes , Linux >> Linux: How to Set Startup Script

In previous Linux versions, startup scripts can simply be enabled by linking a script into the /etc/rc.d/ directory, and voila:

startupScript=/etc/init.d/startupScript
ln -s $startupScript /etc/rc.d/

However, recent versions of major branches such as Debian require that a script be LSB compliant to be triggered by the system upon booting; hence, a more universal method to edit startup routines on any Linux machine is to configure cron as shown in this example:

startupScript=/ect/init.d/startVncSessions.sh
cat <<EOF >  $startupScript
#!/bin/bash
# /etc/init.d/startVncSessions.sh
# Manually set users and session IDs
declare -A users=(
	["einie"]=1
	["minie"]=2
	["maynie"]=3
	["moe"]=4
	["wiwi"]=5
	)

for k in "${!users[@]}"
do
	username=$k
	sessionId=${users[$k]}
	#printf "%s\n" "key: $username value: $sessionId"
	sudo -H -u $username bash -c "vncserver -kill :$sessionId"	
	sudo rm -f /tmp/.X$sessionId-lock
	sudo rm -f /tmp/.X11-unix/X$sessionId
	sudo -H -u $username bash -c "vncserver :$sessionId -geometry 1920x1080 -depth 15 -pixelformat rgb565"
	sudo -H -u $username bash -c "websockify -D --web=/usr/share/novnc/ --cert=/etc/ssl/novnc.pem 908$sessionId localhost:590$sessionId"
done
EOF

# Set script to run at startup
chmod a+x $startupScript
chmod 777 $startupScript # optional: this is to give everyone full access, including editing rights

# Put it in cron
crontab -e
### add this line ###
@reboot /bin/bash -c '/ect/init.d/startVncSessions.sh' &

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Restart a Service on All Hyper-V Hosts of a Cluster

$serviceName='vmms' $clusterName='HyperV-cluster001' function restartServiceAllClusterNodes($service='vmms',$clusterName){ function restartService($serviceName){ $waitSeconds=40 $isValidProcess=try{[bool](get-service $serviceName -EA Stop)}catch{$false} if($isValidProcess){ try{ $process=Start-Process -FilePath…

PowerShell: Reset Active Directory Server

Step 0: # Ensure that AD management module is available for PS Sessionif (!(get-module -name…

PowerShell: Expand Volume of Virtual FileServer Role

Option 1: Expanding disk of a Virtual Machine in Hyper-V # ExpandVolumeVirtualFileServerRole.ps1 # Update these…