You can specify a maximum duration for recording a rosbag using the --duration parameter as below:
rosbag record --duration=5m

You can also make the recording rosbag node required="true" so it shuts the whole launch file down automatically when it finishes.