Saturday, July 23, 2016

Spring Boot Uygulamalarının RHEL 7'de systemd Servisi Olarak Eklenmesi

Spring Boot, Spring tabanlı web uygulaması geliştirmeyi kolaylaştıran özellikleri ile son dönemde tercih edilen kurumsal uygulama geliştirme yaklaşımıdır.
Java Tools and Technologies Landscape 2016
Spring boot uygulamalarının dağıtımını jar ya da war olarak yapabilirsiniz. jar olarak yayına çıktığınızda herhangi bir uygulama sunucusuna ihtiyaç duymadan, sadece Java Sanal Makinasını kullanarak çalıştırabilirsiniz. jar olarak çıkmak için maven projesinin pom.xml dosyasında packaging tanımını jar olarak vermeniz gerekir:
<packaging>jar</packaging>
Bu jar dosyasının çalıştırılabilir bir jar dosyası olması için pom.xml'de spring-boot maven eklentisinde basit bir tanımlama yapmanız gerekir:
<build>
   <plugins>
      . . . .
      <plugin>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-maven-plugin</artifactId>
         <configuration>
            <executable>true</executable>
         </configuration>
      </plugin>
      . . .
   </plugins>
</build>
 Ardından aşağıdaki maven komutunu projenin kök dizininde çalıştırmalısınız:
[guru@server1 hr-boot]$ mvn clean install spring-boot:repackage
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building hr-boot-rest-jpa 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hr ---
[INFO] Deleting /home/guru/hr-boot/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hr ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ hr ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 12 source files to /home/guru/hr-boot/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ hr ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/guru/hr-boot/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ hr ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ hr ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.5:jar (default-jar) @ hr ---
[INFO] Building jar: /home/guru/hr-boot/target/hr-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:1.3.6.RELEASE:repackage (default) @ hr ---
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ hr ---
[INFO] Installing /home/guru/hr-boot/target/hr-0.0.1-SNAPSHOT.jar to /home/guru/.m2/repository/com/example/hr/0.0.1-SNAPSHOT/hr-0.0.1-SNAPSHOT.jar
[INFO] Installing /home/guru/hr-boot/pom.xml to /home/guru/.m2/repository/com/example/hr/0.0.1-SNAPSHOT/hr-0.0.1-SNAPSHOT.pom
[INFO] 
[INFO] --- spring-boot-maven-plugin:1.3.6.RELEASE:repackage (default-cli) @ hr ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.497 s
[INFO] Finished at: 2016-07-23T09:09:38+03:00
[INFO] Final Memory: 30M/174M
[INFO] ------------------------------------------------------------------------ 
target dizininin yeniden oluşturulduğunu ve içeriğine göz attığınızda ise jar dosyasını göreceksiniz:
[guru@server1 hr-boot]$ cd target
[guru@server1 target]$ ls -lh
total 27M
drwxrwxr-x 3 guru guru  72 Jul 23 09:26 classes
drwxrwxr-x 3 guru guru  24 Jul 23 09:26 generated-sources
-rw-rw-r-- 1 guru guru 27M Jul 23 09:26 hr-0.0.1-SNAPSHOT.jar
-rw-rw-r-- 1 guru guru 14K Jul 23 09:26 hr-0.0.1-SNAPSHOT.jar.original
drwxrwxr-x 2 guru guru  27 Jul 23 09:26 maven-archiver
drwxrwxr-x 3 guru guru  34 Jul 23 09:26 maven-status
war olarak çıkmak için ise maven projesinin pom.xml dosyasında packaging tanımını war olarak vermeniz gerekir:
<packaging>war</packaging>
Çalıştırdığımız komutta bir değişiklik yapmıyoruz:
[guru@server1 hr-boot]$ mvn clean install spring-boot:repackage
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building hr-boot-rest-jpa 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hr ---
[INFO] Deleting /home/guru/hr-boot/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hr ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ hr ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 12 source files to /home/guru/hr-boot/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ hr ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/guru/hr-boot/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ hr ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ hr ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-war-plugin:2.5:war (default-war) @ hr ---
[INFO] Packaging webapp
[INFO] Assembling webapp [hr] in [/home/guru/hr-boot/target/hr-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Webapp assembled in [151 msecs]
[INFO] Building war: /home/guru/hr-boot/target/hr-0.0.1-SNAPSHOT.war
[INFO] 
[INFO] --- spring-boot-maven-plugin:1.3.6.RELEASE:repackage (default) @ hr ---
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ hr ---
[INFO] Installing /home/guru/hr-boot/target/hr-0.0.1-SNAPSHOT.war to /home/guru/.m2/repository/com/example/hr/0.0.1-SNAPSHOT/hr-0.0.1-SNAPSHOT.war
[INFO] Installing /home/guru/hr-boot/pom.xml to /home/guru/.m2/repository/com/example/hr/0.0.1-SNAPSHOT/hr-0.0.1-SNAPSHOT.pom
[INFO] 
[INFO] --- spring-boot-maven-plugin:1.3.6.RELEASE:repackage (default-cli) @ hr ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.809 s
[INFO] Finished at: 2016-07-23T09:14:35+03:00
[INFO] Final Memory: 30M/175M
[INFO] ------------------------------------------------------------------------
target dizininin yeniden oluşturulduğunu ve içeriğine göz attığınızda ise war dosyasını göreceksiniz:
[guru@server1 target]$ ls -lh
total 50M
drwxrwxr-x 3 guru guru  72 Jul 23 09:14 classes
drwxrwxr-x 3 guru guru  24 Jul 23 09:14 generated-sources
drwxrwxr-x 4 guru guru  35 Jul 23 09:14 hr-0.0.1-SNAPSHOT
-rw-rw-r-- 1 guru guru 27M Jul 23 09:14 hr-0.0.1-SNAPSHOT.war
-rw-rw-r-- 1 guru guru 24M Jul 23 09:14 hr-0.0.1-SNAPSHOT.war.original
drwxrwxr-x 2 guru guru  27 Jul 23 09:14 maven-archiver
drwxrwxr-x 3 guru guru  34 Jul 23 09:14 maven-status
target dizinindeki  hr-0.0.1-SNAPSHOT.jar dosyasını /home/guru dizinine hr-app adıyla kopyalalım:
[guru@erver1 hr-boot]$ cd target/
[guru@server1 target]$ ls
classes  generated-sources  hr-0.0.1-SNAPSHOT.jar  hr-0.0.1-SNAPSHOT.jar.original  maven-archiver  maven-status
[guru@server1 target]$ cp hr-0.0.1-SNAPSHOT.jar /home/guru/hr-app
[guru@server1 target]$ ls -lh /home/guru/hr-app
-rwxrwxr-x 1 guru guru 27M Jul 23 16:34 /home/guru/hr-app
Bu dosyaya yakından baktığınızda aslında başlığında bir betiğin yer aldığını göreceksiniz:
[guru@server1 ~]$ head -240 hr-app
#!/bin/bash
#
#    .   ____          _            __ _ _
#   /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
#  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
#   \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
#    '  |____| .__|_| |_|_| |_\__, | / / / /
#   =========|_|==============|___/=/_/_/_/
#   :: Spring Boot Startup Script ::
#

### BEGIN INIT INFO
# Provides:          hr
# Required-Start:    $remote_fs $syslog $network
# Required-Stop:     $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: hr-boot-rest-jpa
# Description:       HR Spring Boot Project
# chkconfig:         2345 99 01
### END INIT INFO

[[ -n "$DEBUG" ]] && set -x

# Initialize variables that cannot be provided by a .conf file
WORKING_DIR="$(pwd)"
# shellcheck disable=SC2153
[[ -n "$JARFILE" ]] && jarfile="$JARFILE"
[[ -n "$APP_NAME" ]] && identity="$APP_NAME"

# Follow symlinks to find the real jar and detect init.d script
cd "$(dirname "$0")" || exit 1
[[ -z "$jarfile" ]] && jarfile=$(pwd)/$(basename "$0")
while [[ -L "$jarfile" ]]; do
  [[ "$jarfile" =~ init\.d ]] && init_script=$(basename "$jarfile")
  jarfile=$(readlink "$jarfile")
  cd "$(dirname "$jarfile")" || exit 1
  jarfile=$(pwd)/$(basename "$jarfile")
done
jarfolder="$(dirname "$jarfile")"
cd "$WORKING_DIR" || exit 1
. . .
RHEL 7'de servislerin yönetimi için systemd hizmetini kullanıyoruz. Servisin tanımı ve diğer servislerle bağımlılığını /usr/lib/systemd/system dizininde service uzantılı bir dosyada tanımlıyoruz. Örneğimizde bu dosyaya hr-boot.service adını vereceğiz:
[Unit]
Description=hr-boot service
Wants=mysqld.service
After=network.target mysqld.service

[Service]
Type=simple
ExecStart=/home/guru/hr-app
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target
Spring boot uygulamamız MySQL sunucusunu kullanıyor. Servisimizin çalışabilmesi için öncelikle MySQL sunucusunun başlatılması gerektiğini Wants ile tanımlıyoruz.
Şimdi önce servisi etkinleştireceğiz ve sonra servisi başlatabiliriz:
[guru@server1 hr-boot]$ sudo systemctl enable hr-boot
Created symlink from /etc/systemd/system/multi-user.target.wants/hr-boot.service to /usr/lib/systemd/system/hr-boot.service.
[guru@server1 hr-boot]$ sudo systemctl start hr-boot
[guru@server1 hr-boot]$ sudo systemctl status hr-boot
 hr-boot.service - hr-boot
   Loaded: loaded (/usr/lib/systemd/system/hr-boot.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2016-07-23 15:05:55 EEST; 1h 39min ago
 Main PID: 24437 (hr-app)
   CGroup: /system.slice/hr-boot.service
           ├─24437 /bin/bash /home/guru/hr-app
           └─24456 /usr/bin/java -jar /home/guru/hr-app

Jul 23 15:06:10 server1.example.com hr-app[24437]: 2016-07-23 15:06:10.939  INFO 24456 --- [           main] o.s.j.e.a.AnnotationMB...tartup
Jul 23 15:06:10 server1.example.com hr-app[24437]: 2016-07-23 15:06:10.959  INFO 24456 --- [           main] o.s.c.support.DefaultL...483647
Jul 23 15:06:10 server1.example.com hr-app[24437]: 2016-07-23 15:06:10.961  INFO 24456 --- [           main] o.s.m.s.b.SimpleBroker...ing...
Jul 23 15:06:10 server1.example.com hr-app[24437]: 2016-07-23 15:06:10.963  INFO 24456 --- [           main] o.s.m.s.b.SimpleBroker...ns]]]]
Jul 23 15:06:10 server1.example.com hr-app[24437]: 2016-07-23 15:06:10.965  INFO 24456 --- [           main] o.s.m.s.b.SimpleBroker...arted.
Jul 23 15:06:11 server1.example.com hr-app[24437]: 2016-07-23 15:06:11.115  INFO 24456 --- [           main] s.b.c.e.t.TomcatEmbedd...(http)
Jul 23 15:06:11 server1.example.com hr-app[24437]: 2016-07-23 15:06:11.124  INFO 24456 --- [           main] com.example.hr.HrBootA...5.437)
Jul 23 15:07:09 server1.example.com hr-app[24437]: 2016-07-23 15:07:09.445  INFO 24456 --- [MessageBroker-1] o.s.w.s.c.WebSocketMes...ECTED(
Jul 23 16:23:51 server1.example.com hr-app[24437]: 2016-07-23 16:23:51.487  INFO 24456 --- [MessageBroker-1] o.s.w.s.c.WebSocketMes...ECTED(
Jul 23 16:45:19 server1.example.com systemd[1]: Started hr-boot.
Hint: Some lines were ellipsized, use -l to show in full.
[guru@server1 hr-boot]$ sudo systemctl stop hr-boot
[guru@server1 hr-boot]$ sudo systemctl status hr-boot
 hr-boot.service - hr-boot
   Loaded: loaded (/usr/lib/systemd/system/hr-boot.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Sat 2016-07-23 16:45:52 EEST; 7s ago
 Main PID: 24437 (code=killed, signal=TERM)

Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.589  INFO 24456 --- [       Thread-3] o.s.m.s.b.SimpleBroker...ing...
Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.589  INFO 24456 --- [       Thread-3] o.s.m.s.b.SimpleBroker...ns]]]]
Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.590  INFO 24456 --- [       Thread-3] o.s.m.s.b.SimpleBroker...opped.
Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.616  INFO 24456 --- [       Thread-3] o.s.j.e.a.AnnotationMB...utdown
Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.621  INFO 24456 --- [       Thread-3] o.s.s.concurrent.Threa...cutor'
Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.625  INFO 24456 --- [       Thread-3] o.s.s.c.ThreadPoolTask...duler'
Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.626  INFO 24456 --- [       Thread-3] o.s.s.concurrent.Threa...cutor'
Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.626  INFO 24456 --- [       Thread-3] o.s.s.concurrent.Threa...cutor'
Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.627  INFO 24456 --- [       Thread-3] j.LocalContainerEntity...fault'
Jul 23 16:45:52 server1.example.com systemd[1]: Stopped hr-boot.
Hint: Some lines were ellipsized, use -l to show in full.
Eğer hr-boot servisini başlattığımızda mysqld servisi kapalı ise systemd önce mysqld servisini başlatacaktır:
[guru@server1 ~]$ sudo systemctl status mysqld
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: inactive (dead) since Sat 2016-07-23 16:53:30 EEST; 1min 25s ago
 Main PID: 12912 (code=exited, status=0/SUCCESS)
   Status: "MariaDB server is down"

Jul 23 11:10:16 server1.example.com mysqld[12912]: Version: '10.1.11-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Mar...Server
Jul 23 11:10:16 server1.example.com systemd[1]: Started MariaDB database server.
Jul 23 16:53:28 server1.example.com systemd[1]: Stopping MariaDB database server...
Jul 23 16:53:28 server1.example.com mysqld[12912]: 2016-07-23 16:53:28 140506222205696 [Note] /usr/sbin/mysqld: Normal shutdown
Jul 23 16:53:28 server1.example.com mysqld[12912]: 2016-07-23 16:53:28 140506222205696 [Note] Event Scheduler: Purging the queue. 0 events
Jul 23 16:53:28 server1.example.com mysqld[12912]: 2016-07-23 16:53:28 140505547527936 [Note] InnoDB: FTS optimize thread exiting.
Jul 23 16:53:28 server1.example.com mysqld[12912]: 2016-07-23 16:53:28 140506222205696 [Note] InnoDB: Starting shutdown...
Jul 23 16:53:30 server1.example.com mysqld[12912]: 2016-07-23 16:53:30 140506222205696 [Note] InnoDB: Shutdown completed; log seque...602918
Jul 23 16:53:30 server1.example.com mysqld[12912]: 2016-07-23 16:53:30 140506222205696 [Note] /usr/sbin/mysqld: Shutdown complete
Jul 23 16:53:30 server1.example.com systemd[1]: Stopped MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.
[guru@server1 ~]$ sudo systemctl status hr-boot
● hr-boot.service - hr-boot
   Loaded: loaded (/usr/lib/systemd/system/hr-boot.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Sat 2016-07-23 16:45:52 EEST; 9min ago
 Main PID: 24437 (code=killed, signal=TERM)

Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.589  INFO 24456 --- [       Thread-3] o.s.m.s.b.SimpleBroker...ing...
Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.589  INFO 24456 --- [       Thread-3] o.s.m.s.b.SimpleBroker...ns]]]]
Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.590  INFO 24456 --- [       Thread-3] o.s.m.s.b.SimpleBroker...opped.
Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.616  INFO 24456 --- [       Thread-3] o.s.j.e.a.AnnotationMB...utdown
Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.621  INFO 24456 --- [       Thread-3] o.s.s.concurrent.Threa...cutor'
Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.625  INFO 24456 --- [       Thread-3] o.s.s.c.ThreadPoolTask...duler'
Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.626  INFO 24456 --- [       Thread-3] o.s.s.concurrent.Threa...cutor'
Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.626  INFO 24456 --- [       Thread-3] o.s.s.concurrent.Threa...cutor'
Jul 23 16:45:51 server1.example.com hr-app[24437]: 2016-07-23 16:45:51.627  INFO 24456 --- [       Thread-3] j.LocalContainerEntity...fault'
Jul 23 16:45:52 server1.example.com systemd[1]: Stopped hr-boot.
Hint: Some lines were ellipsized, use -l to show in full.
[guru@server1 ~]$ sudo systemctl start hr-boot
[guru@server1 ~]$ sudo systemctl status mysqld
 mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: active (running) since Sat 2016-07-23 16:55:14 EEST; 3s ago
 Main PID: 27975 (mysqld)
   Status: "Taking your SQL requests now..."
   CGroup: /system.slice/mariadb.service
           └─27975 /usr/sbin/mysqld

Jul 23 16:55:14 server1.example.com mysqld[27975]: 2016-07-23 16:55:14 140191628089472 [Note] InnoDB: Highest supported file format...acuda.
Jul 23 16:55:14 server1.example.com mysqld[27975]: 2016-07-23 16:55:14 140191628089472 [Note] InnoDB: 128 rollback segment(s) are active.
Jul 23 16:55:14 server1.example.com mysqld[27975]: 2016-07-23 16:55:14 140191628089472 [Note] InnoDB: Waiting for purge to start
Jul 23 16:55:14 server1.example.com mysqld[27975]: 2016-07-23 16:55:14 140191628089472 [Note] InnoDB:  Percona XtraDB (http://www.p...602918
Jul 23 16:55:14 server1.example.com mysqld[27975]: 2016-07-23 16:55:14 140191628089472 [Note] Plugin 'FEEDBACK' is disabled.
Jul 23 16:55:14 server1.example.com mysqld[27975]: 2016-07-23 16:55:14 140190882457344 [Note] InnoDB: Dumping buffer pool(s) not yet started
Jul 23 16:55:14 server1.example.com mysqld[27975]: 2016-07-23 16:55:14 140191628089472 [Note] Server socket created on IP: '::'.
Jul 23 16:55:14 server1.example.com mysqld[27975]: 2016-07-23 16:55:14 140191628089472 [Note] /usr/sbin/mysqld: ready for connections.
Jul 23 16:55:14 server1.example.com mysqld[27975]: Version: '10.1.11-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Mar...Server
Jul 23 16:55:14 server1.example.com systemd[1]: Started MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.
[guru@server1 ~]$ sudo systemctl status hr-boot
 hr-boot.service - hr-boot
   Loaded: loaded (/usr/lib/systemd/system/hr-boot.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2016-07-23 16:55:13 EEST; 12s ago
 Main PID: 27976 (hr-app)
   CGroup: /system.slice/hr-boot.service
           ├─27976 /bin/bash /home/guru/hr-app
           └─27999 /usr/bin/java -jar /home/guru/hr-app

Jul 23 16:55:25 server1.example.com hr-app[27976]: 2016-07-23 16:55:25.899  INFO 27999 --- [           main] o.s.w.s.handler.Simple...ndler]
Jul 23 16:55:25 server1.example.com hr-app[27976]: 2016-07-23 16:55:25.970  INFO 27999 --- [           main] .m.m.a.ExceptionHandle...andler
Jul 23 16:55:26 server1.example.com hr-app[27976]: 2016-07-23 16:55:26.039  INFO 27999 --- [           main] o.s.w.s.handler.Simple...ndler]
Jul 23 16:55:26 server1.example.com hr-app[27976]: 2016-07-23 16:55:26.456  INFO 27999 --- [           main] o.s.j.e.a.AnnotationMB...tartup
Jul 23 16:55:26 server1.example.com hr-app[27976]: 2016-07-23 16:55:26.472  INFO 27999 --- [           main] o.s.c.support.DefaultL...483647
Jul 23 16:55:26 server1.example.com hr-app[27976]: 2016-07-23 16:55:26.473  INFO 27999 --- [           main] o.s.m.s.b.SimpleBroker...ing...
Jul 23 16:55:26 server1.example.com hr-app[27976]: 2016-07-23 16:55:26.473  INFO 27999 --- [           main] o.s.m.s.b.SimpleBroker...ns]]]]
Jul 23 16:55:26 server1.example.com hr-app[27976]: 2016-07-23 16:55:26.474  INFO 27999 --- [           main] o.s.m.s.b.SimpleBroker...arted.
Jul 23 16:55:26 server1.example.com hr-app[27976]: 2016-07-23 16:55:26.579  INFO 27999 --- [           main] s.b.c.e.t.TomcatEmbedd...(http)
Jul 23 16:55:26 server1.example.com hr-app[27976]: 2016-07-23 16:55:26.589  INFO 27999 --- [           main] com.example.hr.HrBootA...2.792)
Hint: Some lines were ellipsized, use -l to show in full.
[guru@server1 ~]$ 
Servisimizin konfigürasyonu için çalıştırılabilir dosya ile aynı isimli ancak uzantısı .conf olan bir dosya oluşturuyoruz. Tipik olarak Java Sanal Makinasının ayarlarını yapmak için kullanırız:
[guru@server1 ~]$ ls -lh hr-app.conf 
-r-------- 1 guru guru 80 Jul 23 17:04 hr-app.conf
[guru@server1 ~]$ cat hr-app.conf 
JAVA_OPTS="-Xms2048m -Xmx2048m -Xcomp -XX:+UseG1GC -XX:+UseStringDeduplication"
jcmd komutunu kullanarak, servis olarak çalıştırdığımız Java prosesinin, Java Sanal Makinası parametrelerinin hr-app.conf dosyasında JAVA_OPTS ile tanımladığımız değerlere sahip olduğunu doğrulayabiliriz:
[guru@server1 ~]$ sudo jcmd 
33366 sun.tools.jcmd.JCmd
29067 /home/guru/hr-app
[guru@server1 ~]$ sudo jcmd  29067 VM.command_line
29067:
VM Arguments:
jvm_args: -Dsun.misc.URLClassPath.disableJarChecking=true -Xms2048m -Xmx2048m -Xcomp -XX:+UseG1GC -XX:+UseStringDeduplication 
java_command: /home/guru/hr-app
java_class_path (initial): /home/guru/hr-app
Launcher Type: SUN_STANDARD
[guru@server1 ~]$ 

No comments:

Post a Comment