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

GF_USER="sysadmin"
GF_HOME="/opt/glassfish4/glassfish"
ASADMIN="$GF_HOME/lib/nadmin"
SU="su --login $GF_USER --command "
ASADMIN="/opt/glassfish4/glassfish/lib/nadmin"

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

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

sources:
https://glassfish.java.net/docs/4.0/administration-guide.pdf
http://aldemon.com/install-and-autostart-glassfish-as-non-root-user-linux/
https://blog.hazrulnizam.com/start-glassfish-4-automatically-centos-6/
https://help.ubuntu.com/lts/serverguide/
http://manpages.ubuntu.com/manpages/trusty/man8/update-rc.d.8.html

Anuncios

Responder

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

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. 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: