GlassFish V4 – Running as a service with user different from root on Ubuntu Server 14.04

junio 22, 2015

I’ve used a “sysadmin” user in Ubuntu 14.04 to install the GlassFish server (I’ve just downloaded and unzipped the Web Profile version).

Note: “sysadmin” is just the name I chose to use for the user, it is not a special user or anything like that

In the documentation it states that to start the server as a service in Linux you should execute the create-service subcommand, like so

sysadmin@server$ asadmin create-service

it should complain that you are not allowed to write on /etc/rc.d and you should run this command as a super user (root)

so, I did execute the following command

sysadmin@server$ sudo su -
root@server# asadmin create-service

and it did create the service correctly. It creates the script /etc/init.d/GlassFish_domain1. The problem is that this script runs as the root user.

First, let’s make a backup

root@server# cp /etc/init.d/GlassFish_domain1 /etc/init.d/GlassFish_domain1.bkp

then I modified the following lines to start GlassFish as the ‘sysadmin’ user

SU="su --login $GF_USER --command "

case "$1" in
    $SU "$ASADMIN start-domain    --domaindir /opt/glassfish4/glassfish/domains  domain1 &"
    $SU "$ASADMIN stop-domain   --domaindir /opt/glassfish4/glassfish/domains  domain1 &"
    $SU "$ASADMIN restart-domain   --domaindir /opt/glassfish4/glassfish/domains  domain1 &"
    echo "usage: $0 (start|stop|restart|help)"

Now it should run as a regular user.

If you ever need to remove the service, there’s still a feature request for that. In the meantime you can use the update-rc.d command to remove the soft links to your script that it created in the corresponding folders /etc/rc0.d, /etc/rc1.d, /etc/rc…

sysadmin@server$ sudo update-rc.d -f GlassFish_domain1 remove

the -f option is to force removal even though the script /etc/init.d/GlassFish_domain1 hasn’t been deleted




Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

A %d blogueros les gusta esto: