00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <SUM.h>
00010 #include <sys/socket.h>
00011 #include <sys/errno.h>
00012 #include <rpc/rpc.h>
00013 #include <rpc/pmap_clnt.h>
00014 #include <signal.h>
00015 #include <sum_rpc.h>
00016 #include <soi_error.h>
00017 #include <tape.h>
00018 #include <printk.h>
00019
00020 struct timeval TIMEOUT = { 30, 0 };
00021
00022 CLIENT *current_client, *clntsum, *clntget, *clntget1, *clntget2;
00023 char hostn[MAX_STR];
00024 char datestr[32];
00025 char *username;
00026
00027
00029 char *sname[] = {"SUMPROG", "SUMGET", "SUMGET1", "SUMGET2", "EOD"};
00030 char *vname[] = {"SUMVERS", "SUMGETV", "SUMGETV", "SUMGETV", "EOD"};
00031
00032
00033 static char *datestring()
00034 {
00035 struct timeval tvalr;
00036 struct tm *t_ptr;
00037
00038 gettimeofday(&tvalr, NULL);
00039 t_ptr = localtime((const time_t *)&tvalr);
00040 sprintf(datestr, "%s", asctime(t_ptr));
00041 datestr[19] = (char)NULL;
00042 return(&datestr[4]);
00043 }
00044
00045
00046
00047 void get_cmd(int argc, char *argv[])
00048 {
00049 char *cptr;
00050
00051 if(!(username = (char *)getenv("USER"))) username = "nouser";
00052 if(strcmp(username, "production")) {
00053 printf("!!NOTE: You must be user production to run tape_svc_restart!\n");
00054 exit(1);
00055 }
00056 gethostname(hostn, MAX_STR);
00057 cptr = index(hostn, '.');
00058 if(cptr) *cptr = (char)NULL;
00059 if(strcmp(hostn, "k1")) {
00060 printf("!!NOTE: tape_svc_restart must be run on k1!\n");
00061 exit(1);
00062 }
00063 }
00064
00065 int send_mail(char *fmt, ...)
00066 {
00067 va_list args;
00068 char string[1024], cmd[1024];
00069
00070 va_start(args, fmt);
00071 vsprintf(string, fmt, args);
00072 sprintf(cmd, "echo \"%s\" | Mail -s \"test mail\" jeneen@sun.stanford.edu,hao@sun.stanford.edu,jim@sun.stanford.edu", string);
00073 system(cmd);
00074 va_end(args);
00075 return(0);
00076 }
00077
00078
00079
00080 int main(int argc, char *argv[])
00081 {
00082 char *call_err;
00083 char line[32];
00084 uint32_t restartback;
00085 enum clnt_stat status;
00086 KEY *list = newkeylist();
00087 int i;
00088 char **p = sname;
00089
00090
00091
00092
00093
00094
00095 get_cmd(argc, argv);
00096 printf("\nYou must first take these steps to stop and start a tape_svc on k1\n\n");
00097 printf("Do you want sum_svc to disconnect from tape_svc (yes/no) [no] = ");
00098 if(gets(line) == NULL) { return; }
00099 if(!strcmp(line, "yes")) {
00100
00101 clntsum = clnt_create(SUMSVCHOST, SUMPROG, SUMVERS, "tcp");
00102 if(!clntsum) {
00103 clnt_pcreateerror("Can't get client handle to sum_svc in tape_svc_restart");
00104 printf("***tape_svc_restart can't get sum_svc on %s\n", hostn);
00105 printf("Please consider what this means. You might want to restart all of SUMS\n");
00106 printf("Going to skip the call to sums.\n");
00107 goto SKIPSUMSCALL;
00108
00109 }
00110 setkey_str(&list, "HOST", hostn);
00111 setkey_str(&list, "USER", username);
00112 setkey_str(&list, "ACTION", "close");
00113 status =clnt_call(clntsum, TAPERECONNECTDO,(xdrproc_t)xdr_Rkey,(char *)list,
00114 (xdrproc_t)xdr_uint32_t, (char *)&restartback, TIMEOUT);
00115 if(status != RPC_SUCCESS) {
00116 call_err = clnt_sperror(clntsum, "Err clnt_call for TAPERECONNECTDO");
00117 printf("%s %s\n", datestring(), call_err);
00118 printf("Going to skip the call to sums.\n");
00119 printf("Please consider what this means. You might want to restart all of SUMS\n");
00120 goto SKIPSUMSCALL;
00121 }
00122 switch(restartback) {
00123 case 0:
00124 printf("Success sum_svc has closed to tape_svc\n");
00125 break;
00126 case 1:
00127 printf("Failure sum_svc has not closed to tape_svc\n");
00128 break;
00129 case -1:
00130 printf("**Error in TAPERECONNECTDO call to sum_svc\n");
00131 exit(1);
00132 break;
00133 default:
00134 printf("**Error in TAPERECONNECTDO call to sum_svc\n");
00135 exit(1);
00136 break;
00137 }
00138 clntget = clnt_create(SUMSVCHOST, SUMGET, SUMGETV, "tcp");
00139 if(!clntget) {
00140 clnt_pcreateerror("Can't get client handle to Sget in tape_svc_restart");
00141 printf("***tape_svc_restart can't get Sget on %s\n", hostn);
00142 printf("Please consider what this means. You might want to restart all of SUMS\n");
00143 printf("Going to skip the call to sums.\n");
00144 goto SKIPSUMSCALL;
00145 }
00146 status =clnt_call(clntget, TAPERECONNECTDO,(xdrproc_t)xdr_Rkey,(char *)list,
00147 (xdrproc_t)xdr_uint32_t, (char *)&restartback, TIMEOUT);
00148 if(status != RPC_SUCCESS) {
00149 call_err = clnt_sperror(clntget, "Err clnt_call for TAPERECONNECTDO");
00150 printf("%s %s\n", datestring(), call_err);
00151 printf("Going to skip the call to sums.\n");
00152 printf("Please consider what this means. You might want to restart all of SUMS\n");
00153 goto SKIPSUMSCALL;
00154 }
00155 switch(restartback) {
00156 case 0:
00157 printf("Success Sget has closed to tape_svc\n");
00158 break;
00159 case 1:
00160 printf("Failure Sget has not closed to tape_svc\n");
00161 break;
00162 case -1:
00163 printf("**Error in TAPERECONNECTDO call to Sget\n");
00164 exit(1);
00165 break;
00166 default:
00167 printf("**Error in TAPERECONNECTDO call to Sget\n");
00168 exit(1);
00169 break;
00170 }
00171 clntget1 = clnt_create(SUMSVCHOST, SUMGET1, SUMGETV, "tcp");
00172 if(!clntget1) {
00173 clnt_pcreateerror("Can't get client handle to Sget1 in tape_svc_restart");
00174 printf("***tape_svc_restart can't get Sget1 on %s\n", hostn);
00175 printf("Please consider what this means. You might want to restart all of SUMS\n");
00176 printf("Going to skip the call to sums.\n");
00177 goto SKIPSUMSCALL;
00178 }
00179 status =clnt_call(clntget1,TAPERECONNECTDO,(xdrproc_t)xdr_Rkey,(char *)list,
00180 (xdrproc_t)xdr_uint32_t, (char *)&restartback, TIMEOUT);
00181 if(status != RPC_SUCCESS) {
00182 call_err = clnt_sperror(clntget1, "Err clnt_call for TAPERECONNECTDO");
00183 printf("%s %s\n", datestring(), call_err);
00184 printf("Going to skip the call to sums.\n");
00185 printf("Please consider what this means. You might want to restart all of SUMS\n");
00186 goto SKIPSUMSCALL;
00187 }
00188 switch(restartback) {
00189 case 0:
00190 printf("Success Sget1 has closed to tape_svc\n");
00191 break;
00192 case 1:
00193 printf("Failure Sget1 has not closed to tape_svc\n");
00194 break;
00195 case -1:
00196 printf("**Error in TAPERECONNECTDO call to Sget1\n");
00197 exit(1);
00198 break;
00199 default:
00200 printf("**Error in TAPERECONNECTDO call to Sget\n");
00201 exit(1);
00202 break;
00203 }
00204 clntget2 = clnt_create(SUMSVCHOST, SUMGET2, SUMGETV, "tcp");
00205 if(!clntget2) {
00206 clnt_pcreateerror("Can't get client handle to Sget2 in tape_svc_restart");
00207 printf("***tape_svc_restart can't get Sget2 on %s\n", hostn);
00208 printf("Please consider what this means. You might want to restart all of SUMS\n");
00209 printf("Going to skip the call to sums.\n");
00210 goto SKIPSUMSCALL;
00211 }
00212 status =clnt_call(clntget2,TAPERECONNECTDO,(xdrproc_t)xdr_Rkey,(char *)list,
00213 (xdrproc_t)xdr_uint32_t, (char *)&restartback, TIMEOUT);
00214 if(status != RPC_SUCCESS) {
00215 call_err = clnt_sperror(clntget2, "Err clnt_call for TAPERECONNECTDO");
00216 printf("%s %s\n", datestring(), call_err);
00217 printf("Going to skip the call to sums.\n");
00218 printf("Please consider what this means. You might want to restart all of SUMS\n");
00219 goto SKIPSUMSCALL;
00220 }
00221 switch(restartback) {
00222 case 0:
00223 printf("Success Sget2 has closed to tape_svc\n");
00224 break;
00225 case 1:
00226 printf("Failure Sget2 has not closed to tape_svc\n");
00227 break;
00228 case -1:
00229 printf("**Error in TAPERECONNECTDO call to Sget2\n");
00230 exit(1);
00231 break;
00232 default:
00233 printf("**Error in TAPERECONNECTDO call to Sget\n");
00234 exit(1);
00235 break;
00236 }
00237 }
00238 else return;
00239
00240 SKIPSUMSCALL:
00241
00242 printf("Do as production on k1:\n\n");
00243 printf("> /home/production/cvs/JSOC/base/sums/scripts/sum_stop_k1_tape\n");
00244 printf("> sum_forker jsoc_sums 2010.12.14.115800\n\n");
00245
00246 printf("Have you successfully started a new tape_svc and now want sum_svc\n");
00247 printf("to connect to it (yes/no) [no] = ");
00248 if(gets(line) == NULL) { return; }
00249 if(!strcmp(line, "yes")) {
00250 send_mail("tape_svc has been manually restarted\n");
00251 setkey_str(&list, "HOST", hostn);
00252 setkey_str(&list, "USER", username);
00253 setkey_str(&list, "ACTION", "reconnect");
00254 status =clnt_call(clntsum, TAPERECONNECTDO,(xdrproc_t)xdr_Rkey,(char *)list,
00255 (xdrproc_t)xdr_uint32_t, (char *)&restartback, TIMEOUT);
00256 if(status != RPC_SUCCESS) {
00257 call_err = clnt_sperror(clntsum, "Err clnt_call for TAPERECONNECTDO");
00258 printf("%s %s\n", datestring(), call_err);
00259 exit(1);
00260 }
00261 switch(restartback) {
00262 case 0:
00263 printf("Success sum_svc has reconnected to tape_svc\n");
00264 break;
00265 case 1:
00266 printf("Failure sum_svc has not reconnected to tape_svc\n");
00267 break;
00268 case -1:
00269 printf("**Error in TAPERECONNECTDO call to sum_svc\n");
00270 exit(1);
00271 break;
00272 default:
00273 printf("**Error in TAPERECONNECTDO call to sum_svc\n");
00274 exit(1);
00275 break;
00276 }
00277 status =clnt_call(clntget, TAPERECONNECTDO,(xdrproc_t)xdr_Rkey,(char *)list,
00278 (xdrproc_t)xdr_uint32_t, (char *)&restartback, TIMEOUT);
00279 if(status != RPC_SUCCESS) {
00280 call_err = clnt_sperror(clntget, "Err clnt_call for TAPERECONNECTDO");
00281 printf("%s %s\n", datestring(), call_err);
00282 exit(1);
00283 }
00284 switch(restartback) {
00285 case 0:
00286 printf("Success Sget has reconnected to tape_svc\n");
00287 break;
00288 case 1:
00289 printf("Failure Sget has not reconnected to tape_svc\n");
00290 break;
00291 case -1:
00292 printf("**Error in TAPERECONNECTDO call to Sget\n");
00293 exit(1);
00294 break;
00295 default:
00296 printf("**Error in TAPERECONNECTDO call to Sget\n");
00297 exit(1);
00298 break;
00299 }
00300 status =clnt_call(clntget1,TAPERECONNECTDO,(xdrproc_t)xdr_Rkey,(char *)list,
00301 (xdrproc_t)xdr_uint32_t, (char *)&restartback, TIMEOUT);
00302 if(status != RPC_SUCCESS) {
00303 call_err = clnt_sperror(clntget1, "Err clnt_call for TAPERECONNECTDO");
00304 printf("%s %s\n", datestring(), call_err);
00305 exit(1);
00306 }
00307 switch(restartback) {
00308 case 0:
00309 printf("Success Sget1 has reconnected to tape_svc\n");
00310 break;
00311 case 1:
00312 printf("Failure Sget1 has not reconnected to tape_svc\n");
00313 break;
00314 case -1:
00315 printf("**Error in TAPERECONNECTDO call to Sget1\n");
00316 exit(1);
00317 break;
00318 default:
00319 printf("**Error in TAPERECONNECTDO call to Sget1\n");
00320 exit(1);
00321 break;
00322 }
00323 status =clnt_call(clntget2,TAPERECONNECTDO,(xdrproc_t)xdr_Rkey,(char *)list,
00324 (xdrproc_t)xdr_uint32_t, (char *)&restartback, TIMEOUT);
00325 if(status != RPC_SUCCESS) {
00326 call_err = clnt_sperror(clntget2, "Err clnt_call for TAPERECONNECTDO");
00327 printf("%s %s\n", datestring(), call_err);
00328 exit(1);
00329 }
00330 switch(restartback) {
00331 case 0:
00332 printf("Success Sget2 has reconnected to tape_svc\n");
00333 break;
00334 case 1:
00335 printf("Failure Sget2 has not reconnected to tape_svc\n");
00336 break;
00337 case -1:
00338 printf("**Error in TAPERECONNECTDO call to Sget2\n");
00339 exit(1);
00340 break;
00341 default:
00342 printf("**Error in TAPERECONNECTDO call to Sget2\n");
00343 exit(1);
00344 break;
00345 }
00346 }
00347 }
00348