SaltyNote Server Setup

Last post Ubuntu Server Setup, I talked about the basic setup for an Ubuntu server. In this post, I will share some details about the setup for saltynote server.

Database

1. Create a new database, and a database user

Login database from terminal with mysql -u root -p, and execute follow command lines:

1
2
3
4
5
CREATE DATABASE saltynote;

# Please update USER_NAME and A-STRONG-PASSWORD.
CREATE USER 'USER_NAME'@'localhost' IDENTIFIED BY 'A_STRONG_PASSWORD';
GRANT ALL PRIVILEGES ON saltynote.* TO 'USER_NAME'@'localhost' WITH GRANT OPTION;

Note: You can find more details about how to enable remote access from this post. While here, I only enable it with local access, as I for security reason, it is not required for current stage.

Spring Boot Service

The service is implemented with Spring Boot. So it can be run with a standalone jar file as a Systemd service. You can find more official information from this link.

Create a new user

For security, I will create a specific user to run the service. This post will be very helpful for this step.

1
2
3
4
# Create a new user, and create its home dir
sudo useradd -m saltynote
# Update its password, so the new user can log in later
sudo passwd saltynote

Create Service Folder & Service Setup

1
mkdir -p /home/saltynote/service

Upload the jar file to /home/saltynote/service folder, and create application.properties inside that folder, which can be used to set some sensitive information. e.g. database connection info.

1
2
3
4
# Make saltynote is the owner of service.jar
chown saltynote:saltynote service.jar
# Only give owner read and execute permission
chmod 500 service.jar

Systemd Setup

Create note.service in /etc/systemd/system dir, and populate note.service as below:

1
2
3
4
5
6
7
8
9
10
11
[Unit]
Description=SaltyNote Service
After=syslog.target

[Service]
User=saltynote
ExecStart=/home/saltynote/service/service.jar
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

We can enable this service to auto start when system restarts by:

1
2
3
4
5
6
7
systemctl enable note.service

# manually start it
systemctl start note.service

# check its status
systemctl status note.service

If everything goes well, the service should start now. Open http://YOUR-SERVER-IP:8888, you should see a welcome message in JSON format.

1
2
# You can check that the service is running with saltynote user.
ps aux | grep java | grep -v grep

NginX and HTTPS

// TODO

TO BE DONE