From 97fe81505c43709859d7a6409d99c85275e93243 Mon Sep 17 00:00:00 2001 From: ntheanh201 Date: Thu, 23 Jan 2025 16:32:54 +0700 Subject: [PATCH] migrate traffic_ops init.d service to systemd service --- traffic_ops/build/traffic_ops.spec | 7 +- traffic_ops/etc/init.d/traffic_ops | 94 ------------------- .../etc/systemd/system/traffic_ops.service | 33 +++++++ 3 files changed, 36 insertions(+), 98 deletions(-) delete mode 100755 traffic_ops/etc/init.d/traffic_ops create mode 100644 traffic_ops/etc/systemd/system/traffic_ops.service diff --git a/traffic_ops/build/traffic_ops.spec b/traffic_ops/build/traffic_ops.spec index 53fb0d94f6..9f52d759ce 100644 --- a/traffic_ops/build/traffic_ops.spec +++ b/traffic_ops/build/traffic_ops.spec @@ -172,7 +172,7 @@ if [ "$1" == "2" ]; then fi %post -%__cp %{PACKAGEDIR}/etc/init.d/traffic_ops /etc/init.d/traffic_ops +%__cp %{PACKAGEDIR}/etc/systemd/system/traffic_ops.service /etc/systemd/system/traffic_ops.service %__mkdir -p /var/www/files %__mkdir -p /etc/cron.d/ %__cp %{PACKAGEDIR}/etc/cron.d/trafops_dnssec_refresh /etc/cron.d/trafops_dnssec_refresh @@ -182,14 +182,13 @@ fi %__cp %{PACKAGEDIR}/etc/logrotate.d/traffic_ops_golang /etc/logrotate.d/traffic_ops_golang %__cp %{PACKAGEDIR}/etc/logrotate.d/traffic_ops_access /etc/logrotate.d/traffic_ops_access %__cp %{PACKAGEDIR}/etc/profile.d/traffic_ops.sh /etc/profile.d/traffic_ops.sh -%__chown root:root /etc/init.d/traffic_ops +%__chown root:root /etc/systemd/system/traffic_ops.service %__chown root:root /etc/cron.d/trafops_dnssec_refresh %__chown root:root /etc/cron.d/autorenew_certs %__chown root:root /etc/cron.d/trafops_clean_isos %__chown root:root /etc/logrotate.d/traffic_ops %__chown root:root /etc/logrotate.d/traffic_ops_golang %__chown root:root /etc/logrotate.d/traffic_ops_access -%__chmod +x /etc/init.d/traffic_ops %__chmod +x %{PACKAGEDIR}/install/bin/* /sbin/chkconfig --add traffic_ops @@ -231,7 +230,7 @@ fi if [ "$1" = "0" ]; then # this is an uninstall %__rm -rf %{PACKAGEDIR} - %__rm /etc/init.d/traffic_ops + %__rm /etc/systemd/system/traffic_ops.service /usr/bin/getent passwd %{TRAFFIC_OPS_USER} || /usr/sbin/userdel %{TRAFFIC_OPS_USER} /usr/bin/getent group %{TRAFFIC_OPS_GROUP} || /usr/sbin/groupdel %{TRAFFIC_OPS_GROUP} fi diff --git a/traffic_ops/etc/init.d/traffic_ops b/traffic_ops/etc/init.d/traffic_ops deleted file mode 100755 index a12f370616..0000000000 --- a/traffic_ops/etc/init.d/traffic_ops +++ /dev/null @@ -1,94 +0,0 @@ -#!/bin/bash -# -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# -# traffic ops Start up of the traffic ops application. -# -# chkconfig: 2345 55 25 -# description: Traffic Ops is the administrative web UI for IPCDN. -# -# pidfile: -# - -### BEGIN INIT INFO -# Required-Start: $local_fs $network $syslog -# Required-Stop: $local_fs $syslog -# Should-Start: $syslog -# Should-Stop: $network $syslog -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Start up the Traffic Ops Application. -# Description: Traffic Ops is the administrative UI for the CDN. -# -### END INIT INFO - -TO_DIR="/opt/traffic_ops/app"; export TO_DIR - -# uncomment this for riak client debug logging to the defined info log location. -# logs to stdout if the info log location is not defined in the cdn.conf -#RIAK_GO_CLIENT_DEBUG="true"; export RIAK_GO_CLIENT_DEBUG - -# source function library -. /etc/rc.d/init.d/functions - -start () -{ - stop - echo -e "Starting Traffic Ops\n" - ulimit -n 200000 || echo "Setting ulimit max files failed for traffic_ops_golang" - cd $TO_DIR && $TO_DIR/bin/traffic_ops_golang -cfg $TO_DIR/conf/cdn.conf -dbcfg $TO_DIR/conf/production/database.conf -riakcfg $TO_DIR/conf/production/riak.conf -backendcfg $TO_DIR/conf/production/backends.conf & -} - -stop () -{ - killproc $TO_DIR/bin/traffic_ops_golang -} - -restart () -{ - stop - start -} - -status () -{ - PID=`pidof -s /opt/traffic_ops/app/bin/traffic_ops_golang` - if [ -z "$PID" ] ; then - echo "Traffic Ops is offline" >&2 - return 1 - fi - echo "Traffic Ops is running, pid = $PID" - return 0 -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart) - restart - ;; - status) - status - ;; - *) - echo "Usage: $0 {start | stop | restart | status}" - ;; -esac - -exit 0 diff --git a/traffic_ops/etc/systemd/system/traffic_ops.service b/traffic_ops/etc/systemd/system/traffic_ops.service new file mode 100644 index 0000000000..5563d0f665 --- /dev/null +++ b/traffic_ops/etc/systemd/system/traffic_ops.service @@ -0,0 +1,33 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +[Unit] +Description=Traffic Ops - administrative for the CDN +After=network.target + +[Service] +Type=simple +Environment=TO_DIR=/opt/traffic_ops/app +WorkingDirectory=/opt/traffic_ops/app +LimitNOFILE=200000 +ExecStart=/opt/traffic_ops/app/bin/traffic_ops_golang \ + -cfg /opt/traffic_ops/app/conf/cdn.conf \ + -dbcfg /opt/traffic_ops/app/conf/production/database.conf \ + -riakcfg /opt/traffic_ops/app/conf/production/riak.conf \ + -backendcfg /opt/traffic_ops/app/conf/production/backends.conf +Restart=always +RestartSec=3 + +[Install] +WantedBy=multi-user.target \ No newline at end of file