Rugg, C.J.
This is a petition for a writ of mandamus. It was filed on October 16, 1935. The petitioner seeks to be restored to a civil service position in the employ of the city of Peabody from which he alleges he has been illegally removed. The respondents are the mayor and the members of the city council of the city of Peabody. The case was referred to an auditor, whose findings of fact were by agreement of parties to be final. There were no exceptions to the auditor’s report and no motion to recommit. The case was then heard upon the auditor’s report before a single justice, who ordered that the.petition be denied as matter of discretion. The petitioner’s exception to that order brings the case here.
The relevant facts are these: The petitioner is a civil engineer. The city engineer of Peabody, in July, 1926, appointed the petitioner, in conformity to the requirements of the civil service law, assistant engineer, and duly notified the civil service commission. The petitioner served under this appointment until he ceased work in April, 1935. It has not been argued that the petitioner was not entitled to the protection of the civil service laws. The city of Peabody was incorporated as a city by Spec. St. 1916, c. 300. Its legislative powers were vested in the city council. By an ordinance adopted in 1917 there was created the office of city engineer with extensive supervision over public works of the city and with power “to employ such superintendents, inspectors, foremen, clerks, laborers and other employees” as might be necessary to carry on the work subject to the civil service laws. The titles of assistant city engineer, superintendent of streets, and superintendent of water division were given to persons appointed by and under the city engineer. Salary ordinances adopted from time to time referred to the assistant city engineer. In 1935 an ordinance was adopted after due proceedings and was properly advertised. By its terms there was estab*501listed a department of public works to bé under the charge and supervision of the commissioner of public works. The offices of city engineer, assistant city engineer, superintendent of streets, and superintendent of water division were abolished and all duties and powers formerly vested in them were transferred to the department of public works. The auditor did not find that any respondent supported this ordinance in order to avoid the law or the rules with reference to the civil service, “or to make room for particular appointees or for any reason other than the belief that it would result in better service to the city at lower cost.” The petitioner was competent in the position which he held. On April 17, 1935, the newly appointed commissioner of public works handed to the petitioner a letter signed by the mayor stating that the adoption of the ordinance creating the department of public works had caused his position to be abolished and that his services were therefore terminated. Another person, who had not passed any civil service examination and who was not a civil service appointee, was appointed deputy commissioner of public works. He has performed work of a similar nature to that performed by the petitioner, and has also done other work. The petitioner requested in writing of the mayor a public hearing under G. L. (Ter. Ed.) c. 31, § 43, stating that he contended that the abolition of his office was illegal and that the action was taken in bad faith. A hearing was had but no evidence was introduced. The mayor closed the hearing by saying that the questions raised were for a court and not within his jurisdiction, and that therefore no hearing was necessary. He gave no written notice of his decision to the petitioner. The petitioner took no steps to have this decision reviewed by a district court under G. L. (Ter. Ed.) c. 31, § 45.
The auditor concluded his report with the statement that he did not find that the service to the city was less efficient under the new ordinance than under the old system, or that any persons under civil service in the department set up by the new ordinance were doing work beyond the limits of their respective positions under the civil service rules.
*502The petitioner contends that there was abuse of discretion by the single justice in refusing to issue the writ of mandamus. He bases this contention on the proposition that his right is absolute and no other remedy is open. He recognizes the general principle often stated that mandamus is an extraordinary writ to be granted in the discretion of the court, where no other relief can be given. Crocker v. Justices of the Superior Court, 208 Mass. 162, 164. Direct-Mail Service, Inc. v. Commissioner of Public Works, 295 Mass. 9, 10. The single justice hearing the petition may deny it as matter of discretion, and ordinarily his action will be upheld. Smith v. Commissioner of Public Works of Boston, 215 Mass. 353, 354. Brattin v. Civil Service Commissioners, 249 Mass. 170, 172. Blake v. Hammersley, 288 Mass. 247, 249. The writ cannot be invoked as matter of right. The application is addressed to the discretion of the court. “But this is not an arbitrary discretion; it is a judicial discretion; and when there is a right, and the law has established no specific remedy, this writ should not be denied.” St. Luke’s Church in Chelsea v. Slack, 7 Cush. 226, 239. Peckham v. Mayor of Fall River, 253 Mass. 590, 592. Toothaker v. School Committee of Rockland, 256 Mass. 584, 592. Blackwell v. Mayor of Boston, 261 Mass. 58, 60. As was said by Chief Justice Gray: “The granting of the writ of mandamus rests in the sound judicial discretion of the court, which has cautiously abstained from laying down any limits to the exercise of this discretionary power.” Attorney General v. Boston, 123 Mass. 460, 471, 472. Not infrequently cases are presented to this court as raising a bald question of law, when the ruling of the single justice may be reversed. Ransom v. Mayor of Boston, 193 Mass. 537. No element of discretion may be involved. Shawmut Mills v. Assessors of Fall River, 271 Mass. 358, 360.
For reasons about to be stated, the contention that there was abuse of judicial discretion in the case at bar cannot be supported and the petitioner fails to show himself entitled to the relief here sought.
The contention of the petitioner that the ordinance of 1935 was illegal cannot be supported. It was enacted in *503good faith. If it went beyond the authority conferred by law, it has no binding force. Cawley v. Northern Waste Co. 239 Mass. 540, 544. But the city council had authority to pass such an ordinance. It is plain from Spec. St. 1916, e. 300, § 1, that Peabody is to be governed in general like other cities in the Commonwealth. It follows from G. L. (Ter. Ed.) c. 39, § 1, that it may enact ordinances for directing and managing its “prudential affairs.” Willard v. Newburyport, 12 Pick. 227, 231. Spaulding v. Lowell, 23 Pick. 71, 77. Clarke v. Fall River, 219 Mass. 580, 584. By § 5 of said c. 300 the legislative power of Peabody is vested in the city council and no limitation is placed upon its exercise of such power. By § 54 of said c. 300 it is provided that “ordinance” shall have the same meaning as in St. 1915, c. 267, Part I, § 1 (now G. L. [Ter. Ed.] c. 43, § 1), whereby “ordinance” is defined to be “a vote or order of the . . . city council . . . designed for the permanent regulation of any matter within the jurisdiction of the . . . city council as laid down in this act.” It was stated in Decatur v. Auditor of Peabody, 251 Mass. 82, 84, that said c. 300 is in its essentials similar to Plan B of G. L. c. 43. In said c. 300, § 6, mention is made of “heads of departments.” Since no departments are created by the charter itself, the necessary implication is that departments may be created by ordinance.
The ordinance of 1935 cannot be regarded as defective because indefinite and uncertain. It is specific as to the abolition of four positions and as to the creation of two offices, and leaves other employees to the usual methods of discharge and appointment. The new ordinance repeals any ordinance or parts of ordinances inconsistent with it. The terms of the ordinance accomplish the design of establishing a new department for the administration of defined municipal functions.
The contention of the petitioner that his employment under the civil service law cannot be cut short by ordinance is untenable. The purpose of civil service legislation was to protect efficient public employees from partisan political control. Alger v. Justice of the District Court of Brockton, *504283 Mass. 596, 598, 601. But it was not designed to prevent a city from undertaking in good faith a reorganization of a municipal department in order to promote effectiveness and economy. Reynolds v. McDermott, 264 Mass. 158. Donaghy v. Macy, 167 Mass. 178, 181. Garvey v. Lowell, 199 Mass. 47, 50.
The position formerly occupied by the petitioner has been abolished. Another person having duties differing in substantial respects from those formerly performed by the petitioner has entered the service of the city. Mandamus cannot rightly issue in these circumstances. Donaghy v. Macy, 167 Mass. 178. Reynolds v. McDermott, 264 Mass. 158.
The situation in the case at bar is not unlike that disclosed in Yunitz v. Chelsea, 270 Mass. 179. The petitioner does not show himself to be entitled to the writ of mandamus. There was no error in the action of the single justice in denying the writ.
Exceptions overruled.