define first exactly what
we mean by a “moral
obligation”.

A moral obligation or a
moral duty is a morally
required form of conduct.

This defines the word obligation. The word "moral" and "morally" remains undefined.

Let's be frank, moral means good and evil, right and wrong, already antiquated concepts these days where money matters more than truth, and goodness/righteousness are interpretations that can more or less be purchased, or are entirely contingent on your perspective/the perspective of the agent reporting information to you.

The closest thing we have to a definition of moral or "good" and "evil" these days is "adheres to the law" and "does not adhere to the law" since there is no higher authority on the value of one's actions (unless you're a subjectivist/nihilist etc but if you're any of those positions, you don't really care about the question this article poses).

There is an idea of a shared common morality that makes certain things objectionable, cheating on your partner for instance, is frowned upon by many people. But is it immoral? It cannot be, because the opinion of infidelity changes with time, and to a growing number these days infidelity is considered natural, inevitable, or at least trivial. If the immorality of something shifts with the group mentality over time, and was merely inherited from a previous generation but without consideration in law (infidelity is considered in divorce proceedings, but only as grounds for the legal proceedings not as something that can be prosecuted itself) whence call it a matter of morality? Good and evil can change with time too -- but that's largely why I say these concepts aren't very useful to talk about. May as well constrain morality to law, even though that changes as well, it's less dynamic than group taboo.

So you have an obligation to live in accordance with the laws set by your host society.

Moral obligation to yourself and others begins and ends there. It is argued that you should be good to others -- those arguments are made entirely by those others , but in defence of their obvious bias, being good to others is just good business.

So how can the length of your life fit in? The law doesn't state that you must live as long as possible or that you must use your every waking second to help others, and even if it did, it would also have to stipulate that there is an imperative to achieving a high score at the end -- the achievement of which would be greatly aided by long life.

No, the length of your life has nothing to do with the law, so it either has nothing to do with morality or morality and law aren't equivalent in the case if this question.

Maybe it's a question of do you prefer being alive or being dead?

Since death is a state of existence no one can talk about, but could quite possibly be equivalent to ceasing to exist as a conscious, thinking person, I would argue that being alive has a good chance of being preferable to being dead in most cases.

On those grounds, living longer is preferable, but not in a moral way.

Some people are suffering and would prefer to end that suffering, even if the consequence is no longer existing. Can you call their desire immoral? Can you say with certainty that they are wrong to feel that way, if they have a condition that causes them extreme pain without end?

You can argue that they should keep going to wait for treatments to improve, to try experimental treatments etc. You can argue that pain makes us bad decision makers, that's certainly true as well.

Can it be argued that for all possible states of living, that they are all preferable to being dead? I guess you could be born into a messed up situation where you're imprisoned, abused and tortured by a creep or creeps, and if you're in that position there are surely moments where you think death is better. But again, everyone not in that position would say "better to wait for rescue no matter how long" -- it just seems unfair to say that death is always worse than being alive regardless of the circumstances of your life.

But bottom line, even if someone who terminates their life prematurely has made a bad decision, it cannot be said to be a morally bad one. Just an irrational one at most, and quite possibly a very rational one from their point of view.

It's just a choice based on maximising enjoyment/minimising suffering. That's not a moral question, it's just "do you like being alive? then keep living"