воскресенье, 16 апреля 2017 г.

Напишем свой systemd сервис для db2

# nano /usr/local/bin/db2.sh

# chmod +x /usr/local/bin/db2.sh

#!/bin/sh
    #
    # Startup script for DB2
    # by A.F.
    #


   DB2_USER=db2inst1

    ### BEGIN INIT INFO
    # Provides:       $DB2_USER
    # Required-Start: $network $remote_fs
    # Required-Stop: $network $remote_fs
    # Default-Start: 3
    # Default-Stop: 0 1 2 5 6
    # Short-Description: DB2 $DB2_USER job service
    # Description:  DB2 Instance $DB2_USER job service
    ### END INIT INFO

    # Find the name of the script
    NAME=`basename $0`

    start() {
        DB2_START=$"Starting ${NAME} service: "

        su - $DB2_USER -c '. ./sqllib/db2profile; \
            ./sqllib/adm/db2start > /dev/null'

        ret=$?
        if [ $ret -eq 0 ]
        then
                echo "$DB2_START Success."
        else
                echo "$DB2_START Failed!"
                exit 1
        fi
        echo
    }

    stop() {
        echo -n $"Stopping ${NAME} service: "

        su - $DB2_USER -c '. ./sqllib/db2profile; \
            ./sqllib/adm/db2stop > /dev/null'

        ret=$?
        if [ $ret -eq 0 ]
        then
                echo "Success."
        else
                echo "Failed!"
                exit 1
        fi
      echo
    }
    restart() {
        stop
        start
    }
    case "$1" in
        start)
            start
            ;;
        stop)
            stop
            ;;
        restart)
            restart
            ;;
        *)
            echo $"Usage: $0 {start|stop|restart}"
            exit 1
    esac
    exit 0


Сохранить.  
----------------------------------
 
# nano /etc/systemd/system/db2.service

[Unit] 
Description = db2 daemon 

[Service] 
Type = forking 
ExecStart = /usr/local/bin/db2.sh start 
ExecStop = /usr/local/bin/db2.sh stop 
ExecReload = /usr/local/bin/db2.sh restart 
[Install] 
WantedBy = multi-user.target 
  
Сохранить. 
---------------------------------- 
# systemctl start db2 
# systemctl status db2 
# systemctl enable db2 
!!!# systemctl disable db2
 
 

How to Create a new service with systemd 
Automatic Startup and Restart
Creating Red Hat Wildfly systemd service for Ubuntu 16.04 
Systemd: пишем собственные .service и .target 
systemd. Часть 1. Установка и использование  
9.6. Creating and Modifying systemd Unit Files 
 



 В юните можжно написать ExecStart=/bin/sh -c '/home/dts/bin/dts-service.sh'



Комментариев нет:

Отправить комментарий