The writ of habeas corpus is the remedy to be used when any person is restrained in his liberty. It is an order issued by a court or judge of competent jurisdiction, directed to any one having a person in his custody, or under his restraint, commanding him to produce such person, at a time and place named in the writ, and show why he is held in custody or under restraint.