Skip to content

Commit

Permalink
Merge pull request #1 from ZhengLinLei/fix_docker_port
Browse files Browse the repository at this point in the history
Fix docker port
  • Loading branch information
ZhengLinLei authored Dec 1, 2023
2 parents fd8d73c + 5e917ef commit dc12224
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 609 deletions.
7 changes: 6 additions & 1 deletion RUN.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# Run container cis08583_ots_a end expose all ports with --netword=host
container_name=ciso8583_ots_a

if [ "$(docker ps -aq -f status=exited -f name=$container_name)" ] | [ "$(docker ps -aq -f status=created -f name=$container_name)" ]; then
if [ "$(docker ps -aq -f status=exited -f name=$container_name)" ] || [ "$(docker ps -aq -f status=created -f name=$container_name)" ]; then
echo "Container $container_name exists but is not running"
echo "Removing container $container_name to relaunch it"
# cleanup
./STOP.sh
echo "-------------------\n\n"
fi
if [ ! "$(docker ps -a -q -f name=$container_name)" ]; then
echo "Running $container_name"
docker run -d -it --name $container_name --network=host -v ciso8583_ots_a_logs:/opt/Ciso8583/log $container_name
# docker run -d -it --name $container_name -p 9101:9101 -v ciso8583_ots_a_logs:/opt/Ciso8583/log $container_name

# For testing purposes (Mac)
# docker run --rm -it --name $container_name -p 9101:9101 -v ciso8583_ots_a_logs:/opt/Ciso8583/log $container_name
fi
docker container exec -it $container_name bash
2 changes: 1 addition & 1 deletion STOP.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if [ "$(docker ps -a -q -f name=$container_name)" ]; then
if [ "$(docker ps -a -q -f name=ciso8583_ots_a)" ]; then
echo "Stopping container"
docker container stop ciso8583_ots_a
docker container remove ciso8583_ots_a
Expand Down
3 changes: 3 additions & 0 deletions docker/buildContainer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ cd src/
make

cp -a ../dist/. ../tmp/
# Add full access to be remove by anyone
chmod 777 ../tmp
chmod 777 ../tmp/ciso8583

make clean

Expand Down
4 changes: 2 additions & 2 deletions docker/compile.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LABEL version="0.1"
LABEL description="ISO8583 Server in C (Compilation layer, runnable with ./BUILD.sh in /)"

RUN apt update
RUN apt install -y vim gcc cmake
RUN apt install -y vim gcc make
RUN mkdir /opt/Ciso8583

# Set root path
Expand All @@ -16,7 +16,7 @@ COPY src src
COPY docker/buildContainer.sh .

# Create environment
RUN mkdir bin build dist
RUN mkdir bin build dist tmp
RUN chmod +x ./buildContainer.sh

# CMD ["ls", "-l"]
Expand Down
6 changes: 4 additions & 2 deletions docker/runProduction.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
echo "eoeoeoe"
echo "Running binary"

./bin/ciso8583
./bin/ciso8583 &

tail -f ./log/Ciso8583.log
18 changes: 15 additions & 3 deletions src/c/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
FILE* LOG_PTR;
char* LOG_NAME;

void log_start(char* filename) {
LOG_PTR = fopen(filename, "w");
strcpy(LOG_NAME, filename);
int log_start(char* filename) {
LOG_PTR = fopen(filename, "a");
if (LOG_PTR == NULL)
return -1;

LOG_NAME = filename;
log_info("Starting log for %s", filename);

return 0;
}
void log_close() {
log_info("Closing log for %s", LOG_NAME);
Expand All @@ -26,6 +31,7 @@ void log_format(const char* tag, const char* message, va_list args) {
fprintf(LOG_PTR, "%s [%s] ", date, tag);
vfprintf(LOG_PTR, message, args);
fprintf(LOG_PTR, "\n");
fflush(LOG_PTR);
}

void log_error(const char* message, ...) {
Expand All @@ -42,6 +48,12 @@ void log_info(const char* message, ...) {
va_end(args);
}

void log_warning(const char* message, ...) {
va_list args;
va_start(args, message);
log_format("warning", message, args);
va_end(args);
}

void log_debug(const char* message, ...) {
va_list args;
Expand Down
Loading

0 comments on commit dc12224

Please sign in to comment.