Wowza Community

Startup Script for Wowza Server

Hi,

I have a Wowza EC2 instance created from pre-built EC2 AMI.

I have written a script ‘mount.sh’ which mounts certain s3 buckets.

I want to run this script on machine startup before wowza server starts.

There is a ‘StartupStreams.xml’ in /home/wowza/conf directory which can be used to start certain streams. On similar lines, is there a ‘startup.xml’ file on wowza where i can register the script to run before server starts?

Any pointers will be helpful.

Thanks,

Karuna.

Karuna,

You may want to check out my blog post on startup packages:

http://blog.ianbeyer.com/wowza-startup-packages/

Do it like this:

<RunScript>
     <Script>tuning/tune.sh</Script>
</RunScript>
<RunScript>
     <Script>mount.sh</Script>
</RunScript>

To debug the script if necessary, start without the above and run the script yourself on new new instance.

Richard

Hi,

I tried to edit the ‘startup.xml’ file as mentioned in the blog:

http://blog.ianbeyer.com/wowza-startup-packages/

My “startup.xml” file path was: /opt/working/default_2.2

The file contents are:

<Startup>
	<Commands>
		<Install>
			<Folder>wowza</Folder>
		</Install>
		<RunScript>
			<Script>tuning/tune.sh</Script>
			<Script>mount.sh</Script>
		</RunScript>
	</Commands>
</Startup>

The “mount.sh” file is at the same location as startup.xml.

Its contents are:

#!/bin/sh
logmsg="/usr/bin/logger -t WowzaUserScript "
$logmsg "Wowza Mount Script"
#create Wowza Content and Logs folder in mnt
if ! [ -d /mnt/WowzaMediaServer ]; then 
	$logmsg "Creating /mnt/WowzaMediaServer dir"
	mkdir /mnt/WowzaMediaServer
	mkdir /mnt/WowzaMediaServer/content
	mkdir /mnt/WowzaMediaServer/logs
	$logmsg "Created Wowza content and logs directories"
fi
#create required keys
export AWSACCESSKEYID=XXX
export AWSSECRETACCESSKEY=YYY
#create config directory and mount it
if ! [ -d /mnt/config ]; then 
	$logmsg "Creating /mnt/config dir"
	mkdir /mnt/config;
fi
s3fs ABC -o default_acl=public-read /mnt/config
$logmsg "Mounted /mnt/config dir"
#copy the loadbalancertargets.txt file
cp -f /mnt/config/loadbalancertargets.txt /home/wowza/conf
$logmsg "Copied /mnt/config/loadbalancertargets.txt to /home/wowza/conf"
#umonunt config and delete the folder
fusermount -uz /mnt/config
$logmsg "Unmount /mnt/config"
#mount today's bucket
if ! [ -d /mnt/`date +%Y%m%d`]; then 
	mkdir /mnt/`date +%Y%m%d`; 
	$logmsg "Created today's directory: /mnt/`date +%Y%m%d`"
fi
s3fs ABC-53e39950-0b63-48dc-8e5d-098c62b97440-`date +%Y%m%d` -o default_acl=public-read /mnt/`date +%Y%m%d`
$logmsg "Mounted today's directory: /mnt/`date +%Y%m%d` with bucket: ABC-53e39950-0b63-48dc-8e5d-098c62b97440-`date +%Y%m%d`"
#mount tomorrow's bucket
if ! [ -d /mnt/`date --date="tomorrow" +%Y%m%d`]; then 
	mkdir /mnt/`date --date="tomorrow" +%Y%m%d`; 
	$logmsg "Created tomorrow's directory: /mnt/`date --date=\"tomorrow\" +%Y%m%d`"
fi
s3fs ABC-53e39950-0b63-48dc-8e5d-098c62b97440-`date --date="tomorrow" +%Y%m%d` -o default_acl=public-read /mnt/`date --date="tomorrow" +%Y%m%d`
$logmsg "Mounted tomorrow's directory: /mnt/`date --date=\"tomorrow\" +%Y%m%d` with bucket: ABC-53e39950-0b63-48dc-8e5d-098c62b97440-`date --date=\"tomorrow\" +%Y%m%d`"
$logmsg "Wowza Mount Script Completed"

I then created a AMI of this Wowza server EC2 instance, say ami-123abc

When I created a new instance from the AMI “ami-123abc”, the above mount.sh script did not run when the server started.

Any pointers will be helpful.

Thanks,

Karuna.

Hi Richard,

I did the changes in startup.xml like you suggested.

The script still did not run on the new instance created from the AMI. :frowning:

When I manually ran the script, it executed successfully.

Any pointers will be helpful.

Thanks,

Karuna.

Hi,

I finally got it working by putting the script in “init.d” folder and scheduling it to run before the wowza media server starts :slight_smile:

Thanks,

Karuna.

How you acheive it?
I am using aws ec2 instance and i need to schedule script to running in background before wowza media engine starting, any suggestions?

If you are running in ec2 consider taking advantage of user data scripts section. https://aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/