---
url: /v6.2/en-us/install-upgrade.md
---
# Standalone Environment Version Upgrade

In a standalone environment, the version upgrade process generally follows the flow of **stopping the old version service** -> **installing the new version** -> **updating dependencies** -> **starting the new version service**. Detailed upgrade steps are as follows:

1. Obtain the new version installation package and extract it to the installation device.

2. Stop the old version service.\
   Switch to the runtime user and execute the stop service command in the installation directory. Refer to the example below, where the runtime username is `hengshi` and the old version installation path is `/opt/hengshi`.

```sh
sudo su - hengshi                 # Switch to the runtime user
cd /opt/hengshi                   # Navigate to the installation target directory
bin/hengshi-sense-bin stop all    # Stop the old version service
```

3. Install the new version. Execute the new version installation command in the extracted package directory. Refer to the example below for operation.

```sh
sudo su - hengshi  # Switch to the runtime user
cd ~/pkgs/hengshi-sense-[version] # Navigate to the extracted target directory

# Install the new version. The script will automatically back up the data from the previous version. 
# In special cases where backup is not required, confirm with HENGSHI technical support and use the parameter -s t to skip the backup.
./hs_install -p /opt/hengshi
```

The following message indicates that the new version has been successfully installed:

```sh
SUCCESSED! installed to xxxxx
```

> \[!TIP] Note\
> If you are not using HENGSHI's `metadb`, ensure that the variable `export HS_PG_IF_EXTERNAL=false` is set to `true`. You can modify this in the configuration file `conf/hengshi-sense-env.sh`. During the upgrade process, stopping this service will not be required.

4. Update system dependencies. This operation requires the user to have `sudo` permissions during execution. Once successful, `sudo` permissions can be revoked. Refer to the example below for operation.

```sh
sudo su - hengshi             # Switch to the runtime user
cd /opt/hengshi               # Navigate to the installation target directory
bin/hengshi-sense-bin init-os all  # Initialize OS
```

> \[!TIP] Note\
> For offline environments, use `bin/hengshi-sense-bin init-os all-offline` to skip online dependency updates.

5. Start the new version service. Execute the new version start command in the installation directory.

```sh
sudo su - hengshi             # Switch to the runtime user
cd /opt/hengshi               # Navigate to the installation target directory
bin/hengshi-sense-bin start all   # Start the new version service
```

When the service starts successfully, the following message will be displayed, and the module status will be **IS ACTIVE**:

```shell
 IS ACTIVE! : [metadb] @127.0.0.1:5301/hengshi
 IS ACTIVE! : [engine] @localhost:5302/hengshi
 IS ACTIVE! : [minio] minio server /opt/hengshi/minio-data
 IS ACTIVE! : [redis] 127.0.0.1@5307
 IS ACTIVE! : [syslog] syslog-ng --no-caps --module-path=/opt/hengshi/lib/syslog-ng/lib/syslog-ng -f /opt/hengshi/conf/syslog-ng.conf -p /opt/hengshi/logs/syslog-ng.pid -R /opt/hengshi/logs/syslog-ng.persist -c /opt/hengshi/logs/syslog-ng.ctl
 IS ACTIVE! : [apmserver] /opt/hengshi/lib/apm-server/apm-server -c /opt/hengshi/conf/apm-server.yaml
 IS ACTIVE! : [hengshi] jar /opt/hengshi/lib/bootstrap-6.0.0.jar
 IS ACTIVE! : [monit] /opt/hengshi/lib/monit/bin/monit -c /opt/hengshi/conf/monitrc
```

6. Upgrade complete. Access the service address via a browser to use the HENGSHI SENSE service.

# Rollback

The main operation of decompression rollback is to restore the contents of the most recent backup archive in the `backup` directory to the deployment location (including: program, configuration, data).

1. Prepare rollback files\
   First, navigate to the `backup` directory and select the most recent archive for decompression. Be sure to confirm the timestamp of the archive. In the example, the archive in the `hengshi-20210819163228` directory is selected for decompression, with a timestamp of `2021-08-19_16:32:28`.

2. Rollback program and data

```shell
cd /opt/hengshi
bin/hengshi-sense-bin stop all
tar -xf backup/hengshi-20210819163228/bin_conf_lib.tar.gz
mv pg_data pg_data.bak
bin/hengshi-sense-bin init metadb  
bin/hengshi-sense-bin start metadb  
bin/dbrestore.sh -m metadb -l ${PWD}/backup/hengshi-20210819163228 -t metadb_backup.2021-08-19_16-33-14[.tar.gz]  
bin/hengshi-sense-bin stop metadb
bin/hengshi-sense-bin start all
```

3. Clean up old data\
   After rollback, and upon confirming no issues through business checks, execute the following cleanup operations:

```shell
cd /opt/hengshi
rm pg_data.bak -rf
cd backup/hengshi-20210819163228 && rm metadb_backup.2021-08-19_16-33-14 -rf
```
