Skip to main content

Use trap in shell scripts

· One min read
docker run -d --name gs2  -p 9000-9009:9000-9009/tcp -v /root/real-gameserver/config:/opt/q1game/config 172.16.127.171:10001/gserver-allinone:0.0.1 /bin/bash -c 'cd control;./startAll.sh;trap "echo [`date --iso-8601=seconds`] WARNING Game Server will be stopped after 5 seconds;trap - SIGTERM;sleep 5;echo [`date --iso-8601=seconds`] WARNING Stopping the Game Server...;./stop.sh;exit 0" SIGTERM;while true;do echo "[`date --iso-8601=seconds`] Game Server(Game Id: ${GAMD_ID}, Region Id: ${REGION_ID}, Area Id: ${AREA_ID}, World Id: ${WORLD_ID}) running...";sleep 5;done'

docker stop gs2 -t 120

Gitlab Omnisharp package - Change LDAP DN for external user

· 2 min read

Scenario:

Change DN from "cn=李小李,ou=IT 中心,ou=XX 公司,dc=xx,dc=com" to "cn=李小李,ou=HR Dept,ou=XX 公司,dc=xx,dc=com" for user #11.

Step 1 - Connect to boundled PostgreSQL database

# sudo gitlab-psql -d gitlabhq_production
psql (10.9)
Type "help" for help.

gitlabhq_production=#

Refer to: https://docs.gitlab.com/omnibus/settings/database.html#connecting-to-the-bundled-postgresql-database

Step 2 - Search user DN by user id in the psql shell

gitlabhq_production=# select * from identities where provider = 'ldapmain' and user_id = 11;
id | extern_uid | provider | user_id | created_at | updated_at | saml_provider_id | secondary_extern_uid
----+----------------------------------------------------------------+----------+---------+----------------------------+----------------------------+------------------+----------------------
9 | cn=李小李,ou=IT中心,ou=XX公司,dc=xx,dc=com | ldapmain | 11 | 2018-06-27 15:01:13.457313 | 2019-12-19 03:26:00.777429 | |
(1 row)

gitlabhq_production=#

Step 3 - Update user DN

update identities set extern_uid = CONCAT('cn=',E'\u674e',E'\u5c0f',E'\u674e',',ou='HR Dept',',ou=XX',E'\u516c',E'\u53f8',',dc=q1oa,dc=com') where provider = 'ldapmain' and user_id = 11;
UPDATE 1
gitlabhq_production=#

Notes: You can't input chinese characters in the psql shell, so you need encode the chinese chars in unicode format and use CONCAT function to concat ascii and unicode characters in the update SQL statement. Refer to: https://kb.objectrocket.com/postgresql/use-psql-to-insert-a-record-with-unicode-characters-845

PS: In GitLab ver 12.2.5 (09f8edbc29a), it is able to modify user's DN by : Admin Area -> Overview -> Users -> find user and switch to "Identities" tab -> Edit

ClustrMaps