# 2.3 – Install as Linux/Unix daemon

#### Before installation
---

1. Download SparkView for Linux/Unix: [https://cloud.beyondssl.com/url/sparkviewother](https://cloud.beyondssl.com/url/sparkviewother)
2. Unzip it to your destination directory. Here we use `/usr/local/bin/SparkGateway`.
3. Modify gateway.conf to change gateway listening port or other configurations.

#### Using install script
---

The installation script "installLinux.sh" is located in the unpacked SparkView folder.\
Execute it with sudo and the following command:\
`sudo sh ./installLinux.sh`


#### Manual installation
---

Open gateway listening port (80):
   - `firewall-cmd --permanent --add-port=80/tcp`,<br>`firewall-cmd --reload`
   - or
   - `iptables -A INPUT -p tcp --dport 80 -j ACCEPT`
> If SparkView can not listen on port 80, 443 or any ports below 1024, you can try this command:<br>`sudo setcap cap_net_bind_service=+epi "readlink -f \"which java\""`

**Test the gateway in console mode:**

`java –jar SparkGateway.jar`

You can install it as a service if it’s working correctly in console mode:

**For Systemd system:**

Create file: `/etc/systemd/system/SparkGateway.service` with the following contents:
```
[Unit]
Description=SparkView Service
After=network.target
[Service]
User=yourUserName
WorkingDirectory=/usr/local/bin/SparkGateway
ExecStart=/usr/bin/java -jar /usr/local/bin/SparkGateway/SparkGateway.jar
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
```
Then notify the systemd fo the new service: `systemctl daemon-reload`

Service commands:
- Enable the service: `systemctl enable SparkGateway`
- Start the service: `systemctl start SparkGateway`
- Stop the service: `systemctl stop SparkGateway`
- Check the status if the service is not started: `systemctl status SparkGateway`
- Uninstall the service: `systemctl disable SparkGateway`

Please check the following documentation for SUSE: [http://remotespark.com/view/SUSE_Install.txt](http://remotespark.com/view/SUSE_Install.txt)

**For SysVinit init system:**

To build the daemon wrapper you will need:
- GNU AutoConf (at least version 2.53)
- An ANSI-C compliant compiler (GCC is good)
- GNU Make
- A Java Platform 2 compliant SDK

`yum groupinstall "Development Tools"` (CentOS)

`apt-get install build-essentials` (Debian/Ubuntu)

Run the following commands:
```
cd /usr/local/bin/SparkGateway
tar xvfz commons-daemon-native.tar.gz
cd commons-daemon-1.0.10-native-src/unix
./configure
make
cp jsvc ../..
cd ../..
chmod a+x SparkGateway.sh
```
Change the name of your license file to “license” and copy it to installation directory if you are using the full version.

Modify gateway.conf file, change listening port and file path according to your installation directory.

Starting the daemon: `./SparkGateway.sh start`<br/>
Stopping the daemon: `./SparkGateway.sh stop`

We are using Apache Jsvc as a Linux/Unix daemon wrapper, for more information, please check
[http://commons.apache.org/daemon/jsvc.html](http://commons.apache.org/daemon/jsvc.html)

The script (SparkGateway.sh) is only tested on CentOS, you may need to change it on other Linux.

Run as a service and start automatically:
```
cp SparkGateway.sh /etc/init.d/SparkGateway
chmod +x /etc/init.d/SparkGateway
chkconfig --add SparkGateway
chkconfig SparkGateway on
```
Start the service: `service SparkGateway start`<br/>
Stop the service: `service SparkGateway stop`