Reputation: 946
How to put the following commands to run in the background as a service on Ubuntu?
Start the hub
java -jar selenium-server-standalone-2.48.2.jar -role hub &
Start the nodes
java -jar selenium-server-standalone-2.48.2.jar -role node -hub http://localhost:4444/grid/register &
Whenever I close my ssh session can not access the selenium grid service even putting '&'
character at the end of each command. Would someone give me a help?
Upvotes: 2
Views: 2676
Reputation: 2189
I've tried to make selenium-server-standalone running as a service, but it failed to launch browser (I've tried chrome and firefox). So it is better to do as Mahsum Akbas says.
Here is an example of how you could make it as a service: bash - Start Java jar by service (linux)...
But it will not launch real browsers. I was using jenkins service to launch real browser, but it failed too. I had success in launching tests using headless browser. But there was the problem with some tests were failing.
EDITED: I've achieved it in such way using systemd:
sudo vim /etc/systemd/system/selenium-server-hub.service
[Unit]
Description=Selenium Server Standalone hub
StartLimitIntervalSec=5
After=syslog.target
[Service]
Type=simple
Restart=always
RestartSec=8
User=spacer
ExecStart=/bin/bash -c "export DISPLAY=:10 && /usr/bin/java -jar /home/spacer/seleniumserver/selenium-server.jar -role hub"
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
sudo vim /etc/systemd/system/selenium-server-hub.service
[Unit]
Description=Selenium Server node
StartLimitIntervalSec=0
After=selenium-server-hub.target
[Service]
Type=simple
Restart=always
RestartSec=8
User=spacer
ExecStart=/bin/bash -c "export DISPLAY=:10 && /usr/bin/java -Dwebdriver.chrome.driver=/bin/chromedriver -jar /home/spacer/seleniumserver/selenium-server.jar -role node -hub 'http://192.168.0.101:4444/grid/register/'"
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
I connect to my linux server through RDP and it opens display :10. Your display could be different. You could check your displays by command:
ps e | grep -Po " DISPLAY=[\.0-9A-Za-z:]* " | sort -u
PS: Chrome and Firefox are starting, even though chromedriver could not be started when I was launching selenium-server hub and node from terminal as usual.
Upvotes: 3
Reputation: 1583
you can use nohup
command. so, you can redirect output to nohup file and there will not be kill session after disconnect ssh.
nohup java -jar selenium-server-standalone-2.48.2.jar -role hub &
nohup java -jar selenium-server-standalone-2.48.2.jar -role node -hub http://localhost:4444/grid/register &
Upvotes: 1