I'm replacing our old init.d Glassfish script with a .service file. I want the ability to start/stop domains one by one, but also a quick way to start/stop all of them at once.

So far, I have this as glassfish@.service:

Description=Glassfish4 Domain %i

ExecStart=/opt/glassfish4/glassfish/bin/asadmin --passwordfile /my/pw/file start-domain %i
ExecStop=/opt/glassfish4/glassfish/bin/asadmin --passwordfile /my/pw/file stop-domain %i



This works and I can start, stop and enable a single domain like this:

systemctl start glassfish@domain1

However, I would also like to be able to stop or start all the domains like this:

systemctl stop glassfish

How can I achieve this? Also, how can I show the status of each instance of glassfish@.service?

I'm currently thinking of writing a script which is called from the .service file and actually starts/stops the domains, using a default set of parameters if none are supplied. But this feels hacky and wrong.

1 Answer 1


I figured it out myself.

systemd apparently supports wildcards. So once you have enabled some instances, you can easily stop all of them like this:

systemctl stop 'glassfish@*'

Apparently, Ubuntu requires you to add a --all, so the total command is

systemctl stop 'glassfish@*' --all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.