Spaces:
Sleeping
Sleeping
VenkateshRoshan
commited on
Commit
·
5eec0c8
1
Parent(s):
ff28980
systemProcess Updated
Browse files- setup_systemProcess.sh +20 -13
setup_systemProcess.sh
CHANGED
@@ -8,7 +8,7 @@ USER=student-admin
|
|
8 |
ssh_key_path=./
|
9 |
old_ssh_key_name=./student-admin_key
|
10 |
|
11 |
-
# remove keys if already present
|
12 |
rm -f $ssh_key_path/my_key*
|
13 |
|
14 |
# TODO : Add password to the ssh key and store it in a file and read the file and get the password
|
@@ -33,23 +33,21 @@ echo "$new_ssh_pub_key"
|
|
33 |
# Use the old SSH key to connect to the server and append the new public key to authorized_keys
|
34 |
ssh -i "$old_ssh_key_name" -p "$PORT" "$USER@$HOST" "echo '$new_ssh_pub_key' >> /home/student-admin/.ssh/authorized_keys && chmod 600 /home/student-admin/.ssh/authorized_keys"
|
35 |
|
36 |
-
# TODO : Comment the old ssh key in the authorized_keys file
|
37 |
-
#
|
38 |
-
|
39 |
# Verify if the key has been added successfully
|
40 |
echo "New public key added to authorized_keys on the server."
|
41 |
|
|
|
|
|
42 |
# Make a variable to store the SSH connection command with
|
43 |
-
SSH_CONNECTION="ssh -i
|
44 |
|
45 |
# run a command to create apt install python3-venv
|
46 |
-
|
47 |
-
$SSH_CONNECTION "sudo apt-get update && suod apt-get upgrade && sudo apt-get install python3-venv && pip install --upgrade pip"
|
48 |
|
49 |
VENV=/home/$USER/mlops
|
50 |
|
51 |
-
# creating a virtual environment
|
52 |
-
# ssh -i "$old_ssh_key_name" -p "$PORT" "$USER@$HOST" "python3 -m venv $VENV"
|
53 |
$SSH_CONNECTION "python3 -m venv $VENV"
|
54 |
|
55 |
echo "Virtual environment created. in $VENV"
|
@@ -61,25 +59,31 @@ GIT_REPO_PATH=https://github.com/VenkateshRoshan/MLOPs-CaseStudy1.git
|
|
61 |
# ssh -i "$old_ssh_key_name" -p "$PORT" "$USER@$HOST" "git clone $GIT_REPO_PATH"
|
62 |
$SSH_CONNECTION "git clone $GIT_REPO_PATH"
|
63 |
|
|
|
|
|
64 |
# Activate the virtual environment
|
65 |
# ssh -i "$old_ssh_key_name" -p "$PORT" "$USER@$HOST" "source $VENV/bin/activate && sudo apt install ffmpeg && cd MLOPs-CaseStudy1 && pip install -r requirements.txt"
|
66 |
-
$SSH_CONNECTION "source $VENV/bin/activate && sudo apt install ffmpeg && cd MLOPs-CaseStudy1 && pip3 install -r requirements.txt" # python3 app.py" to run the application
|
67 |
|
68 |
echo "The environment is ready to run the application."
|
69 |
|
70 |
# check the pip list in the environment
|
71 |
$SSH_CONNECTION "source $VENV/bin/activate && pip list"
|
|
|
|
|
|
|
72 |
|
73 |
# Create a systemd service file for the application
|
74 |
SERVICE_FILE="[Unit]
|
75 |
-
Description=
|
76 |
After=network.target
|
77 |
|
78 |
[Service]
|
79 |
Type=simple
|
80 |
-
ExecStart=/bin/bash -c 'source $VENV/bin/activate && cd /home
|
81 |
Restart=always
|
82 |
User=$USER
|
|
|
83 |
WorkingDirectory=/home/$USER/MLOPs-CaseStudy1
|
84 |
|
85 |
[Install]
|
@@ -88,6 +92,9 @@ WantedBy=multi-user.target"
|
|
88 |
# Write the service file to the server
|
89 |
echo "$SERVICE_FILE" | $SSH_CONNECTION "sudo tee /etc/systemd/system/mlopscs2.service > /dev/null"
|
90 |
|
|
|
|
|
|
|
91 |
# Reload systemd to recognize the new service
|
92 |
$SSH_CONNECTION "sudo systemctl daemon-reload"
|
93 |
|
@@ -104,7 +111,7 @@ $SSH_CONNECTION "sudo systemctl start mlopscs2"
|
|
104 |
# $SSH_CONNECTION "sudo systemctl restart mlopscs2"
|
105 |
|
106 |
# Run the application
|
107 |
-
$SSH_CONNECTION "source $VENV/bin/activate && cd MLOPs-CaseStudy1 && python3 app.py"
|
108 |
|
109 |
echo "Systemd service for MLOps application created and started."
|
110 |
|
|
|
8 |
ssh_key_path=./
|
9 |
old_ssh_key_name=./student-admin_key
|
10 |
|
11 |
+
# # remove keys if already present
|
12 |
rm -f $ssh_key_path/my_key*
|
13 |
|
14 |
# TODO : Add password to the ssh key and store it in a file and read the file and get the password
|
|
|
33 |
# Use the old SSH key to connect to the server and append the new public key to authorized_keys
|
34 |
ssh -i "$old_ssh_key_name" -p "$PORT" "$USER@$HOST" "echo '$new_ssh_pub_key' >> /home/student-admin/.ssh/authorized_keys && chmod 600 /home/student-admin/.ssh/authorized_keys"
|
35 |
|
|
|
|
|
|
|
36 |
# Verify if the key has been added successfully
|
37 |
echo "New public key added to authorized_keys on the server."
|
38 |
|
39 |
+
new_ssh_key_name=./my_key
|
40 |
+
|
41 |
# Make a variable to store the SSH connection command with
|
42 |
+
SSH_CONNECTION="ssh -i $new_ssh_key_name -p $PORT $USER@$HOST"
|
43 |
|
44 |
# run a command to create apt install python3-venv
|
45 |
+
$SSH_CONNECTION "sudo apt-get update && sudo apt-get upgrade && sudo apt-get install python3-venv && pip install --upgrade pip"
|
|
|
46 |
|
47 |
VENV=/home/$USER/mlops
|
48 |
|
49 |
+
# # creating a virtual environment
|
50 |
+
# # ssh -i "$old_ssh_key_name" -p "$PORT" "$USER@$HOST" "python3 -m venv $VENV"
|
51 |
$SSH_CONNECTION "python3 -m venv $VENV"
|
52 |
|
53 |
echo "Virtual environment created. in $VENV"
|
|
|
59 |
# ssh -i "$old_ssh_key_name" -p "$PORT" "$USER@$HOST" "git clone $GIT_REPO_PATH"
|
60 |
$SSH_CONNECTION "git clone $GIT_REPO_PATH"
|
61 |
|
62 |
+
$SSH_CONNECTION "export HF_TOKEN=$HF_TOKEN; echo \$HF_TOKEN >> ~/.bashrc; source ~/.bashrc"
|
63 |
+
|
64 |
# Activate the virtual environment
|
65 |
# ssh -i "$old_ssh_key_name" -p "$PORT" "$USER@$HOST" "source $VENV/bin/activate && sudo apt install ffmpeg && cd MLOPs-CaseStudy1 && pip install -r requirements.txt"
|
66 |
+
$SSH_CONNECTION "source $VENV/bin/activate && sudo apt install ffmpeg && cd MLOPs-CaseStudy1 && pip3 install --no-cache-dir -r requirements.txt" # python3 app.py" to run the application
|
67 |
|
68 |
echo "The environment is ready to run the application."
|
69 |
|
70 |
# check the pip list in the environment
|
71 |
$SSH_CONNECTION "source $VENV/bin/activate && pip list"
|
72 |
+
$SSH_CONNECTION "export HF_TOKEN=$HF_TOKEN; echo \$HF_TOKEN >> ~/.bashrc; source ~/.bashrc"
|
73 |
+
# add $HF_TOKEN to /home/$USER/.env
|
74 |
+
$SSH_CONNECTION "echo 'HF_TOKEN=$HF_TOKEN' >> /home/$USER/.env"
|
75 |
|
76 |
# Create a systemd service file for the application
|
77 |
SERVICE_FILE="[Unit]
|
78 |
+
Description=MLOps Case Study 1 Deployment
|
79 |
After=network.target
|
80 |
|
81 |
[Service]
|
82 |
Type=simple
|
83 |
+
ExecStart=/bin/bash -c 'source ~/.bashrc && source $VENV/bin/activate && cd /home/student-admin/MLOPs-CaseStudy1 && python app.py'
|
84 |
Restart=always
|
85 |
User=$USER
|
86 |
+
EnvironmentFile=/home/$USER/.env
|
87 |
WorkingDirectory=/home/$USER/MLOPs-CaseStudy1
|
88 |
|
89 |
[Install]
|
|
|
92 |
# Write the service file to the server
|
93 |
echo "$SERVICE_FILE" | $SSH_CONNECTION "sudo tee /etc/systemd/system/mlopscs2.service > /dev/null"
|
94 |
|
95 |
+
# give permission to the service file
|
96 |
+
$SSH_CONNECTION "sudo chmod 644 /etc/systemd/system/mlopscs2.service"
|
97 |
+
|
98 |
# Reload systemd to recognize the new service
|
99 |
$SSH_CONNECTION "sudo systemctl daemon-reload"
|
100 |
|
|
|
111 |
# $SSH_CONNECTION "sudo systemctl restart mlopscs2"
|
112 |
|
113 |
# Run the application
|
114 |
+
# $SSH_CONNECTION "source $VENV/bin/activate && cd MLOPs-CaseStudy1 && python3 app.py"
|
115 |
|
116 |
echo "Systemd service for MLOps application created and started."
|
117 |
|