The tune of this song is shared by the Scottish "Ring the Bell, Watchman", and the Welsh "Twll Bach y Clo". In Australia, it is used for a sheep-sheering song called "Click Go the Shears". As to which version is the original, it is difficult to say, but Stan Hugill suspects this sailor version is one of the oldest.
Aboard ship, time was kept by striking the bell such that a twenty-four hour day would be divided into watches. In English and American ships, each watch was four hours (except the first dogwatch: 4-6pm and last dogwatch: 6-8pm, included to give seamen different hours of watch on alternate days). Other countries used alternative schedules to match continental mealtimes.
On many ships, a grommet or deckboy would turn a half-hour sandglass and when it emptied, ring out the number of bells upon every half-hour.